Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix case where we pass ServiceDefinition to the builder already #402

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions sdk-core/src/main/java/dev/restate/sdk/core/RestateEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,24 @@ private ServiceDefinitionFactoryDiscovery() {
@SuppressWarnings("unchecked")
public static ServiceDefinitionFactory<Object, Object> discoverServiceDefinitionFactory(
Object service) {
if (service instanceof ServiceDefinitionFactory<?, ?>) {
// We got this already
return (ServiceDefinitionFactory<Object, Object>) service;
}
if (service instanceof ServiceDefinition<?>) {
// We got this already
return new ServiceDefinitionFactory<>() {
@Override
public ServiceDefinition<Object> create(Object serviceObject) {
return (ServiceDefinition<Object>) serviceObject;
}

@Override
public boolean supports(Object serviceObject) {
return serviceObject == service;
}
};
}
return Objects.requireNonNull(
ServiceDefinitionFactorySingleton.INSTANCE.discoverFactory(service),
() ->
Expand Down
Loading