Skip to content

Commit

Permalink
Fix case where we pass ServiceDefinition to the builder already (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkydeveloper authored Nov 18, 2024
1 parent c86ae92 commit fa728dd
Showing 1 changed file with 18 additions and 0 deletions.
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

0 comments on commit fa728dd

Please sign in to comment.