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 specific ADEPT2Services. 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 Details

    • 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 Details

    • 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 Details

    • serviceAvailable

      protected long serviceAvailable()
      Checks whether our ADEPT2Service reacts to ADEPT2Service.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 for ADEPT2Service.ping() or Long.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.
      Specified by:
      run in interface Runnable
    • 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.