public static class ClientServiceSharedServices.ServiceAvailabilityTracker
extends java.lang.Object
implements java.lang.Runnable
ADEPT2Services. The service is polled
regularly. If its availability changes (detected via ADEPT2Service.ping()) the
registered listeners will be notified. | Modifier and Type | Field and Description |
|---|---|
protected java.util.Collection<ClientService.ServiceStateListener> |
listeners
The listeners which are registered for changes in the availability of the
service.
|
protected java.util.logging.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 java.util.concurrent.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 java.lang.Class<? extends ADEPT2Service> |
serviceClass
The interfaces of the service.
|
protected java.net.URI[] |
serviceUris
The URIs of the service the last time the service was available.
|
| Modifier | Constructor and Description |
|---|---|
protected |
ServiceAvailabilityTracker(ADEPT2Service service,
java.util.concurrent.ScheduledExecutorService scheduler,
long rate,
java.util.logging.Logger logger)
Creates a new tracker for the designated service using the designated
executor service for checking the service availability.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addListener(ClientService.ServiceStateListener listener)
Adds the designated listener for changes in the availability of our
ADEPT2Service. |
boolean |
removeServiceStateListener(ClientService.ServiceStateListener listener)
Removes the designated listener so that it is no longer notified for
changes in the availability of our
ADEPT2Service. |
void |
run() |
protected long |
serviceAvailable()
Checks whether our
ADEPT2Service reacts to ADEPT2Service.ping() and gets
the corresponding return value. |
protected final java.util.logging.Logger logger
protected final ADEPT2Service service
protected final java.lang.Class<? extends ADEPT2Service> serviceClass
protected java.net.URI[] serviceUris
protected final java.util.Collection<ClientService.ServiceStateListener> listeners
protected final java.util.concurrent.ScheduledExecutorService scheduler
protected final long rate
protected ServiceAvailabilityTracker(ADEPT2Service service, java.util.concurrent.ScheduledExecutorService scheduler, long rate, java.util.logging.Logger logger)
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.protected long serviceAvailable()
ADEPT2Service reacts to ADEPT2Service.ping() and gets
the corresponding return value. Long.MIN_VALUE for a service that is currently not
responding. ADEPT2Service returns for ADEPT2Service.ping() or
Long.MIN_VALUE if communication failed.public void run()
run in interface java.lang.Runnablepublic boolean addListener(ClientService.ServiceStateListener listener)
ADEPT2Service.listener - The listener which to notify in case the availability of
our ADEPT2Service changes.ADEPT2Service is currently available.public boolean removeServiceStateListener(ClientService.ServiceStateListener listener)
ADEPT2Service. If this is
the last listener, the availability check will be disabled.listener - The listener which to remove.