Class 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 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 Detail

      • runLock

        protected 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 of synchronized) to allow for interrupts.
      • service

        protected final URI[] service
        The service of which to check its availability.
      • serviceClass

        protected final Class<? extends ADEPT2Service> serviceClass
        The interface of the service.
      • interruptible

        protected 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

      • ServiceAvailabilityTracker

        protected 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

      • serviceAvailable

        protected 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 be Long.MIN_VALUE if the platform or the service are unavailable. If the platform is unavailable, both start times will be Long.MIN_VALUE and the service instance will be null.
        Returns:
        The start time of (a service representing) the platform, of the service and the service instance itself.
      • run

        public void run()
        Specified by:
        run in interface Runnable
      • 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

        public boolean addListener​(ClientService.ServiceStateListener listener)
        Adds the designated listener for changes in the availability of our ADEPT2Service.
        Parameters:
        listener - The listener which to notify in case the availability of our ADEPT2Service 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 our ADEPT2Service. 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.