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 specific
Note that polling will only take place if at least one listener is registered.
ADEPT2Service identified by its
URI[]. 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 booleanWhether the executing thread may be interrupted.protected final Collection<ClientService.ServiceStateListener>The listeners which are registered for changes in the service availability.protected final LockA lock to prevent one tracker to run concurrently (for the very same service).protected final URI[]The service of which to check its availability.protected final Class<? extends ADEPT2Service>The interface of the service. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedServiceAvailabilityTracker(URI[] service, Class<? extends ADEPT2Service> serviceClass) Creates a new service availability tracker for the designated service. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds the designated listener for changes in the availability of ourADEPT2Service.booleanStops the service availability tracking by cancelling the future and interrupting the executing thread if allowed.booleanRemoves the designated listener so that it is no longer notified for changes in the availability of ourADEPT2Service.voidrun()protected Triple<Long,Long, ADEPT2Service> Checks whether the platform and the service are available.
-
Field Details
-
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. -
service
The service of which to check its availability. -
serviceClass
The interface of the service. -
listeners
The listeners which are registered for changes in the service availability. -
interruptible
protected boolean interruptibleWhether the executing thread may be interrupted.
To prevent inconsistent states, the current thread is not interruptible while notifying the listeners.
-
-
Constructor Details
-
ServiceAvailabilityTracker
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 Details
-
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.
-
run
public void run() -
interrupt
public 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.
-
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.
-