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 specificADEPT2Service
s. The service is polled regularly. If its availability changes (detected viaADEPT2Service.ping()
) the registered listeners will be notified.
Note that polling will only take place if at least one listener is registered.
-
-
Field Summary
Fields Modifier and Type Field Description protected Collection<ClientService.ServiceStateListener>
listeners
The listeners which are registered for changes in the availability of the service.protected Logger
logger
The logger for logging problems occurring when notifying listeners.protected long
rate
The time in milliseconds between checking the service availability (at a fixed rate).protected ScheduledExecutorService
scheduler
The executor service which runs the tracker regularly to check for the service availability.protected ADEPT2Service
service
The service of which to check its availability.protected Class<? extends ADEPT2Service>
serviceClass
The interfaces of the service.protected URI[]
serviceUris
The URIs of the service the last time the service was available.
-
Constructor Summary
Constructors Modifier Constructor Description 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addListener(ClientService.ServiceStateListener listener)
Adds the designated listener for changes in the availability of ourADEPT2Service
.boolean
removeServiceStateListener(ClientService.ServiceStateListener listener)
Removes the designated listener so that it is no longer notified for changes in the availability of ourADEPT2Service
.void
run()
Note that this method is called from the constructor!protected long
serviceAvailable()
Checks whether ourADEPT2Service
reacts toADEPT2Service.ping()
and gets the corresponding return value.
-
-
-
Field Detail
-
logger
protected final Logger logger
The logger for logging problems occurring when notifying listeners.
-
service
protected final ADEPT2Service service
The service of which to check its availability.
-
serviceClass
protected final Class<? extends ADEPT2Service> serviceClass
The interfaces of the service.
-
serviceUris
protected URI[] serviceUris
The URIs of the service the last time the service was available.
-
listeners
protected final Collection<ClientService.ServiceStateListener> listeners
The listeners which are registered for changes in the availability of the service.
-
scheduler
protected final ScheduledExecutorService scheduler
The executor service which runs the tracker regularly to check for the service availability.
-
rate
protected final long rate
The time in milliseconds between checking the service availability (at a fixed rate).
-
-
Constructor Detail
-
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 Detail
-
serviceAvailable
protected long serviceAvailable()
Checks whether ourADEPT2Service
reacts toADEPT2Service.ping()
and gets the corresponding return value.Long.MIN_VALUE
for a service that is currently not responding.
Note that this method may take some time, the communication timeout applies here.- Returns:
- The value our
ADEPT2Service
returns forADEPT2Service.ping()
orLong.MIN_VALUE
if communication failed.
-
run
public void run()
Note that this method is called from the constructor! The instance may not be fully initialised.
-
addListener
public boolean addListener(ClientService.ServiceStateListener listener)
Adds the designated listener for changes in the availability of ourADEPT2Service
.- Parameters:
listener
- The listener which to notify in case the availability of ourADEPT2Service
changes.- Returns:
- Whether our
ADEPT2Service
is currently available.
-
removeServiceStateListener
public boolean removeServiceStateListener(ClientService.ServiceStateListener listener)
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.
-
-