Class ServiceStateTracker.ServiceAvailabilityTracker
- java.lang.Object
- 
- de.aristaflow.adept2.core.registry.cluster.ServiceStateTracker.ServiceAvailabilityTracker
 
- 
- All Implemented Interfaces:
- Runnable
 - Enclosing class:
- ServiceStateTracker
 
 public final class ServiceStateTracker.ServiceAvailabilityTracker extends Object implements Runnable A tracker for the availability of a specificADEPT2Serviceidentified by itsURI[]. 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 SummaryFields Modifier and Type Field Description protected booleaninterruptibleWhether the executing thread may be interrupted.protected Collection<ClientService.ServiceStateListener>listenersThe listeners which are registered for changes in the service availability.protected LockrunLockA lock to prevent one tracker to run concurrently (for the very same service).protected URI[]serviceThe service of which to check its availability.protected Class<? extends ADEPT2Service>serviceClassThe interface of the service.
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedServiceAvailabilityTracker(URI[] service, Class<? extends ADEPT2Service> serviceClass)Creates a new service availability tracker for the designated service.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddListener(ClientService.ServiceStateListener listener)Adds the designated listener for changes in the availability of ourADEPT2Service.booleaninterrupt()Stops the service availability tracking by cancelling the future and interrupting the executing thread if allowed.booleanremoveServiceStateListener(ClientService.ServiceStateListener listener)Removes the designated listener so that it is no longer notified for changes in the availability of ourADEPT2Service.voidrun()protected Triple<Long,Long,ADEPT2Service>serviceAvailable()Checks whether the platform and the service are available.
 
- 
- 
- 
Field Detail- 
runLockprotected final Lock runLock A lock to prevent one tracker to run concurrently (for the very same service). Tracking different services concurrently is fine.
 We need a lock (instead ofsynchronized) to allow for interrupts.
 - 
serviceprotected final URI[] service The service of which to check its availability.
 - 
serviceClassprotected final Class<? extends ADEPT2Service> serviceClass The interface of the service.
 - 
listenersprotected final Collection<ClientService.ServiceStateListener> listeners The listeners which are registered for changes in the service availability.
 - 
interruptibleprotected boolean interruptible Whether the executing thread may be interrupted.
 To prevent inconsistent states, the current thread is not interruptible while notifying the listeners.
 
- 
 - 
Constructor Detail- 
ServiceAvailabilityTrackerprotected ServiceAvailabilityTracker(URI[] service, Class<? extends ADEPT2Service> serviceClass) Creates a new service availability tracker for the designated service.- Parameters:
- service- The service of which to check its availability.
- serviceClass- The interface of the service.
 
 
- 
 - 
Method Detail- 
serviceAvailableprotected Triple<Long,Long,ADEPT2Service> serviceAvailable() Checks whether the platform and the service are available. If so, the start time of (a service representing) the platform, the start time of the service and the service instance itself will be returned. The start time will beLong.MIN_VALUEif the platform or the service are unavailable. If the platform is unavailable, both start times will beLong.MIN_VALUEand the service instance will benull.- Returns:
- The start time of (a service representing) the platform, of the service and the service instance itself.
 
 - 
interruptpublic boolean interrupt() Stops the service availability tracking by cancelling the future and interrupting the executing thread if allowed. While notifying the registered listeners, interrupts will be refused.- Returns:
- Whether cancelling the future was successful.
 
 - 
addListenerpublic 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 our- ADEPT2Servicechanges.
- Returns:
- Whether our ADEPT2Serviceis currently available.
 
 - 
removeServiceStateListenerpublic 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.
 
 
- 
 
-