Class MicroserviceSubscriptionsServiceImpl
java.lang.Object
com.cumulocity.microservice.subscription.service.impl.MicroserviceSubscriptionsServiceImpl
- All Implemented Interfaces:
MicroserviceSubscriptionsService
@Service
public class MicroserviceSubscriptionsServiceImpl
extends Object
implements MicroserviceSubscriptionsService
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface -
Constructor Summary
ConstructorsConstructorDescriptionMicroserviceSubscriptionsServiceImpl(PlatformProperties properties, org.springframework.context.ApplicationEventPublisher eventPublisher, MicroserviceSubscriptionsRepository repository, MicroserviceMetadataRepresentation microserviceMetadataRepresentation, ContextService<MicroserviceCredentials> contextService) -
Method Summary
Modifier and TypeMethodDescription<T> TcallForTenant(String tenant, Callable<T> runnable) Invokes runnable in context of subscribed tenant.getAll()Gets current microservice subscriptions' credentialsgetCredentials(String tenant) Gets microservice credentials of the given tenant.
NOTE: this method may return stale data if the refreshing subscription process is in progress.getCredentialsAsync(String tenant) Asynchronously gets microservice credentials of the given tenant.Returns current tenant.booleanvoid<T> voidlisten(Class<T> clazz, MicroserviceSubscriptionsServiceImpl.MicroserviceChangedListener<T> listener) voidrunForEachTenant(Runnable runnable) Invokes runnable in context of all subscribed tenants.voidrunForTenant(String tenant, Runnable runnable) Invokes runnable in context of subscribed tenant.voidFetches microservice subscriptions and emits MicroserviceSubscriptionRemovedEvent, MicroserviceSubscriptionAddedEvent to the MicroserviceChangedListener listeners
-
Constructor Details
-
MicroserviceSubscriptionsServiceImpl
@Autowired public MicroserviceSubscriptionsServiceImpl(PlatformProperties properties, org.springframework.context.ApplicationEventPublisher eventPublisher, MicroserviceSubscriptionsRepository repository, MicroserviceMetadataRepresentation microserviceMetadataRepresentation, ContextService<MicroserviceCredentials> contextService)
-
-
Method Details
-
listen
-
listen
public <T> void listen(Class<T> clazz, MicroserviceSubscriptionsServiceImpl.MicroserviceChangedListener<T> listener) -
subscribe
public void subscribe()Description copied from interface:MicroserviceSubscriptionsServiceFetches microservice subscriptions and emits MicroserviceSubscriptionRemovedEvent, MicroserviceSubscriptionAddedEvent to the MicroserviceChangedListener listenersIf a listener throws exception during event execution, the event is created again in the next call to the method.
- Specified by:
subscribein interfaceMicroserviceSubscriptionsService
-
getAll
Description copied from interface:MicroserviceSubscriptionsServiceGets current microservice subscriptions' credentials- Specified by:
getAllin interfaceMicroserviceSubscriptionsService- Returns:
- collection of microservice credentials
-
getCredentials
Description copied from interface:MicroserviceSubscriptionsServiceGets microservice credentials of the given tenant.
NOTE: this method may return stale data if the refreshing subscription process is in progress. Please useMicroserviceSubscriptionsService.getCredentialsAsync(String)to get the most up-to-date credentials.- Specified by:
getCredentialsin interfaceMicroserviceSubscriptionsService- Parameters:
tenant- tenant id- Returns:
Optional.ofmicroservice credentials if tenant is found in current subscriptions;Optional.<MicroserviceCredentials>empty()otherwise
-
getCredentialsAsync
Description copied from interface:MicroserviceSubscriptionsServiceAsynchronously gets microservice credentials of the given tenant. Returns a CompletableFuture that will be completed when the subscription process finishes. This method guarantees the most up-to-date credentials, waiting for any ongoing subscription refresh process to complete.- Specified by:
getCredentialsAsyncin interfaceMicroserviceSubscriptionsService- Parameters:
tenant- tenant id- Returns:
CompletableFuturethat completes with Optional microservice credentials for the requested tenant
-
getTenant
Description copied from interface:MicroserviceSubscriptionsServiceReturns current tenant.- Specified by:
getTenantin interfaceMicroserviceSubscriptionsService- Returns:
- current tenant id
-
runForEachTenant
Description copied from interface:MicroserviceSubscriptionsServiceInvokes runnable in context of all subscribed tenants.- Specified by:
runForEachTenantin interfaceMicroserviceSubscriptionsService- Parameters:
runnable- runnable to execute
-
runForTenant
Description copied from interface:MicroserviceSubscriptionsServiceInvokes runnable in context of subscribed tenant.- Specified by:
runForTenantin interfaceMicroserviceSubscriptionsService- Parameters:
tenant- tenant idrunnable- runnable to execute
-
callForTenant
Description copied from interface:MicroserviceSubscriptionsServiceInvokes runnable in context of subscribed tenant.- Specified by:
callForTenantin interfaceMicroserviceSubscriptionsService- Type Parameters:
T- generic type of expected result object- Parameters:
tenant- tenant idrunnable- callable to execute- Returns:
- result object
-
isRegisteredSuccessfully
public boolean isRegisteredSuccessfully()- Specified by:
isRegisteredSuccessfullyin interfaceMicroserviceSubscriptionsService
-