Package de.aristaflow.adept2.core.client
Class ClientServiceSharedServices.ServiceAvailabilityTracker
java.lang.Object
de.aristaflow.adept2.core.client.ClientServiceSharedServices.ServiceAvailabilityTracker
- All Implemented Interfaces:
Runnable
- Enclosing class:
- ClientServiceSharedServices
public static class ClientServiceSharedServices.ServiceAvailabilityTracker
extends Object
implements Runnable
A tracker for the availability of a specific
Note that polling will only take place if at least one listener is registered.
ADEPT2Services. The service is polled
regularly. If its availability changes (detected via ADEPT2Service.ping()) the
registered listeners will be notified. Note that polling will only take place if at least one listener is registered.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Collection<ClientService.ServiceStateListener>The listeners which are registered for changes in the availability of the service.protected final LoggerThe logger for logging problems occurring when notifying listeners.protected final longThe time in milliseconds between checking the service availability (at a fixed rate).protected final ScheduledExecutorServiceThe executor service which runs the tracker regularly to check for the service availability.protected final ADEPT2ServiceThe service of which to check its availability.protected final Class<? extends ADEPT2Service>The interfaces of the service.protected URI[]The URIs of the service the last time the service was available. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedServiceAvailabilityTracker(ADEPT2Service service, ScheduledExecutorService scheduler, long rate, Logger logger) Creates a new tracker for the designated service using the designated executor service for checking the service availability. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds the designated listener for changes in the availability of ourADEPT2Service.booleanRemoves the designated listener so that it is no longer notified for changes in the availability of ourADEPT2Service.voidrun()Note that this method is called from the constructor! The instance may not be fully initialised.protected longChecks whether ourADEPT2Servicereacts toADEPT2Service.ping()and gets the corresponding return value.
-
Field Details
-
logger
The logger for logging problems occurring when notifying listeners. -
service
The service of which to check its availability. -
serviceClass
The interfaces of the service. -
serviceUris
The URIs of the service the last time the service was available. -
listeners
The listeners which are registered for changes in the availability of the service. -
scheduler
The executor service which runs the tracker regularly to check for the service availability. -
rate
protected final long rateThe time in milliseconds between checking the service availability (at a fixed rate).
-
-
Constructor Details
-
ServiceAvailabilityTracker
protected ServiceAvailabilityTracker(ADEPT2Service service, ScheduledExecutorService scheduler, long rate, Logger logger) Creates a new tracker for the designated service using the designated executor service for checking the service availability.- Parameters:
service- The service of which to check its availability.scheduler- The executor service which runs the tracker regularly to check for the service availability.rate- The time in milliseconds between checking the service availability (at a fixed rate).logger- The logger for logging problems occurring when notifying listeners.
-
-
Method Details
-
serviceAvailable
protected long serviceAvailable()Checks whether ourADEPT2Servicereacts toADEPT2Service.ping()and gets the corresponding return value.Long.MIN_VALUEfor a service that is currently not responding.
Note that this method may take some time, the communication timeout applies here.- Returns:
- The value our
ADEPT2Servicereturns forADEPT2Service.ping()orLong.MIN_VALUEif communication failed.
-
run
public void run()Note that this method is called from the constructor! The instance may not be fully initialised. -
addListener
Adds the designated listener for changes in the availability of ourADEPT2Service.- Parameters:
listener- The listener which to notify in case the availability of ourADEPT2Servicechanges.- Returns:
- Whether our
ADEPT2Serviceis currently available.
-
removeServiceStateListener
Removes the designated listener so that it is no longer notified for changes in the availability of ourADEPT2Service. If this is the last listener, the availability check will be disabled.- Parameters:
listener- The listener which to remove.- Returns:
- Whether the designated listener was the last listener.
-