Class ServiceStateTracker
ClientService. It also tracks the
availability of the platform by polling the cluster node state. Both issues are separately
implemented.
The lifecycle of ClientService is coupled to the platform running on a cluster node.
This platform may be restarted and may change between client and server role. However, service
state listeners registered at the ClientService may have a different lifecycle and
keep on running while the platform restarts. When restarting the platform and thus the
ClientService the listeners will get lost and they will no longer receive
notifications about a service. Additionally, they will not get notified about the restart of the
ClientService where they would need to re-register.
This class solves this issue by being coupled to the lifecycle of ClusterNode.
Additionally, listeners do not register with a service object (which is also coupled to the
lifecycle of the platform and not of the one of a cluster node) but with the URI[]
of a service. This is usually the global service URI which is resolved transparently considering
all cluster nodes. Therefore the service may change its providing cluster node without the
service state listener needing to change.
The availability of the platform will be tracked by a separate thread polling the cluster node
state for changes. As soon as a changes occurs, it submits a runnable for notifying the
registered listeners and immediately polls for a cluster node change again. Since this has to be
outside of the platform lifecycle, the thread keeps on running while the cluster node exists. It
stops as soon as the cluster node has terminated. The code bootstrapping the cluster node should
also join() this thread. While the service state tracker may ignore the platform being
unavailable, platform state listeners will be notified about every relevant change of the cluster
node state. This may lead to consecutive notifications of the platform being unavailable (but the
cluster node changing states while preparing the platform restart).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classA callable retrieving all listeners registered for platform state and submitting the corresponding notifications about the (un-)availability of the platform.protected classA thread tracking the availability of the platform.static interfaceListener for events that the availability of the platform within the cluster node has changed.final classA tracker for the availability of a specificADEPT2Serviceidentified by itsURI[]. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<ArrayKey<URI>,ServiceStateTracker.ServiceAvailabilityTracker> The listeners registered for the availability of anADEPT2Serviceand the corresponding service availability tracker.protected final ClusterNodeStateThe cluster node state for the platform availability tracker.protected final LoggerThe logger for problems occurring with the asynchronous notifications.protected final LimitedPipelineExecutor<Object>The executor for notifying the registered platform state listeners.protected final ThreadThe thread tracking the availability of the platform by polling the cluster node state.protected AbstractAuthenticatedServiceThe service used in the injected part of the cluster node/ClusterService.protected final longThe rate in milliseconds at which to poll the availability of servicesserviceAvailibilityChecker.protected final intThe amount of threads used for theserviceAvailibilityChecker.protected final Collection<ServiceStateTracker.PlatformStateListener>The listeners registered for changes in the platform availability.The statuses which are relevant for the (un-)availability of the platform.protected ServiceAccessThe access for services within the platform used to retrieve the polled services.protected ScheduledExecutorServiceThe thread pool for checking the availability of services and notifying changes to the registered listeners. -
Constructor Summary
ConstructorsConstructorDescriptionServiceStateTracker(int servAvailPoolSize, long servAvailPollRate, ClusterNodeState cns) Creates a new service state tracker for a cluster node. -
Method Summary
Modifier and TypeMethodDescriptionbooleanRegisters the designated listener for changes in the availability of the platform.booleanaddServiceStateListener(URI[] service, Class<? extends ADEPT2Service> servClass, ClientService.ServiceStateListener listener) This is similar toClientService.addServiceStateListener(ADEPT2Service, ServiceStateListener)except that it uses theURI[]of the service and the service class instead of the service instance.voidjoin()Joins the thread tracking the platform availability.voidRemoves the designated listener from changes in the availability of the platform.voidremoveServiceStateListener(URI[] service, ClientService.ServiceStateListener listener) This is similar toClientService.removeServiceStateListener(ADEPT2Service, ServiceStateListener)except that it uses theURI[]of the service instead of the service instance.voidshutdown()Signals the shutting down of the platform of the cluster node.voidstart(AbstractAuthenticatedService pService, ServiceAccess sAccess) Starts this service state tracker each time the platform becomes available (again).
-
Field Details
-
logger
The logger for problems occurring with the asynchronous notifications. -
poolSize
protected final int poolSizeThe amount of threads used for theserviceAvailibilityChecker. -
pollRate
protected final long pollRateThe rate in milliseconds at which to poll the availability of servicesserviceAvailibilityChecker. -
availTracker
The listeners registered for the availability of anADEPT2Serviceand the corresponding service availability tracker. -
platformService
The service used in the injected part of the cluster node/ClusterService. This is used to track the state of the platform within the cluster node. -
servAccess
The access for services within the platform used to retrieve the polled services. -
serviceAvailibilityChecker
The thread pool for checking the availability of services and notifying changes to the registered listeners. -
cns
The cluster node state for the platform availability tracker. -
relevantStatuses
The statuses which are relevant for the (un-)availability of the platform. Some intermediate statuses are not relevant. -
psListeners
The listeners registered for changes in the platform availability. -
platformAvailabilityNotifier
The executor for notifying the registered platform state listeners. This is a pipeline executor to avoid later state notifications to overtake older state notifications. -
platformAvailabilityTracker
The thread tracking the availability of the platform by polling the cluster node state.
-
-
Constructor Details
-
ServiceStateTracker
Creates a new service state tracker for a cluster node.- Parameters:
servAvailPoolSize- The amount of threads used for theserviceAvailibilityCheckerand the #platformAvailabilityNotifier.servAvailPollRate- The rate in milliseconds at which to poll the availability of servicesserviceAvailibilityChecker.cns- The cluster node state for the platform availability tracker.
-
-
Method Details
-
start
Starts this service state tracker each time the platform becomes available (again).- Parameters:
pService- The service used in the injected part of the cluster node/ClusterService. This is used to track the state of the platform within the cluster node.sAccess- The access for services within the platform used to retrieve the polled services.
-
shutdown
public void shutdown()Signals the shutting down of the platform of the cluster node. This removes access to the platform and terminates the executor service. -
addServiceStateListener
public boolean addServiceStateListener(URI[] service, Class<? extends ADEPT2Service> servClass, ClientService.ServiceStateListener listener) This is similar toClientService.addServiceStateListener(ADEPT2Service, ServiceStateListener)except that it uses theURI[]of the service and the service class instead of the service instance. This is due to the service instance to be subject of change in case the platform within the cluster node changes.- Parameters:
service- TheURI[]of the service to poll.servClass- The class of the service to poll.listener- The listener which to notify in case of service availability changes.- Returns:
- Whether the designated service is currently available.
-
removeServiceStateListener
This is similar toClientService.removeServiceStateListener(ADEPT2Service, ServiceStateListener)except that it uses theURI[]of the service instead of the service instance.- Parameters:
service- TheURI[]of the service which to no longer poll.listener- The listener which to no longer notify in case of service availability changes.
-
addPlatformStateListener
Registers the designated listener for changes in the availability of the platform.- Parameters:
psl- The listener notified of changes in the availability of the platform.- Returns:
- Whether the platform is currently available.
-
removePlatformStateListener
Removes the designated listener from changes in the availability of the platform.- Parameters:
psl- The listener which no longer to notify of changes in the availability of the platform.
-
join
Joins the thread tracking the platform availability. The shutdown procedure should call this to prevent the platform availability tracker from surviving the final termination.- Throws:
InterruptedException- If the current thread is interrupted while waiting for the platform availability tracker, anInterruptedExceptionwill be thrown and the thread will not be joined.
-