Class AbstractSubService<T extends AbstractADEPT2Service>

java.lang.Object
de.aristaflow.adept2.base.service.AbstractSubService<T>
Type Parameters:
T - The type of the service this is a sub service of.
Direct Known Subclasses:
ClientServiceSharedServices

public class AbstractSubService<T extends AbstractADEPT2Service> extends Object
An abstract implementation for sub services of an AbstractADEPT2Service. This provides just the basic requirements for a sub service and forwards the session handling to the corresponding main service. The basic requirements include empty implementations for the initialisation, start and shutdown as well as the startup and runtime required services. Note that a sub service must only provide its own required services not the ones of the main service!

This interface can be used by the main services to manage their sub services. Note that unlike the methods of AbstractADEPT2Service no method of this interface will be called by the registry.

  • Field Details

    • logger

      protected Logger logger
      The logger of the corresponding main service this sub service belongs to.
      Only change this logger if you really know what you are doing!!
    • startupRequiredServices

      protected final String[] startupRequiredServices
      The service type names of services required at runtime (after startup time) by this sub service.
    • runtimeRequiredServices

      protected final String[] runtimeRequiredServices
      The service type names of services required at runtime (after startup time) by this sub service.
    • service

      protected final T extends AbstractADEPT2Service service
      The corresponding main service this sub service belongs to.
  • Constructor Details

    • AbstractSubService

      public AbstractSubService(T service)
      Creates a simple sub service for the designated main service.
      Parameters:
      service - The main service this sub service belongs to.
    • AbstractSubService

      public AbstractSubService(String[] startupRequiredServices, String[] runtimeRequiredServices, T service)
      Creates a simple sub service with the designated required services for the designated main service.
      Parameters:
      startupRequiredServices - The service type names of services required at startup time (in init() and start()) by this sub service.
      runtimeRequiredServices - The service type names of services required at runtime (after startup time) by this sub service.
      service - The main service this sub service belongs to.
  • Method Details

    • privilegeSession

      protected final void privilegeSession(SessionToken activeSession, SessionToken newSession)
      Parameters:
      activeSession - The session token with which to privilege a new session that should be allowed to terminate despite this service shutting down. This session token has to be active and must not be null.
      newSession - The session token which should be allowed to terminate despite this service shutting down. This has to be a top-level session token and it must not be null.
    • sessionActive

      protected final void sessionActive(SessionToken session)
      Forwards to AbstractADEPT2Service.sessionActive(SessionToken) of the main service.
      Parameters:
      session - The session token with which a method is called and therefore active. This must not be null.
    • sessionFinished

      protected final void sessionFinished(SessionToken session)
      Parameters:
      session - The session token with which a method has been executed and which is not active any more in this service. This must not be null.
    • getStartupRequiredServices

      public final String[] getStartupRequiredServices()
      Gets the service type names of services required at startup time (in init() and start()) by this sub service.
      Returns:
      The service type names of services required at startup time (in init() and start()) by this sub service.
    • getRuntimeRequiredServices

      public final String[] getRuntimeRequiredServices()
      Gets the service type names of services required at runtime (after startup time) by this sub service.
      Returns:
      The service type names of services required at runtime (after startup time) by this sub service.
    • getLocalUris

      protected URI[] getLocalUris()
      Forwards to AbstractADEPT2Service.getLocalUris() of the main service.
      Returns:
      The URIs with which this service is exported locally - this may also be one local URI or an empty array for internal services, that should not be reached at all, for instance communication services.
    • getURIs

      protected URI[] getURIs()
      Forwards to AbstractADEPT2Service.getURIs() of the main service.
      Returns:
      The URIs with which this service is globally published or the local URIs.
    • ping

      public long ping()
      Gets whether the main service is running and accepts requests or not and since when. This allows, for instance, to check remotely whether this service is available. Additionally, restarts of the main service can be detected by comparing the returned start time with the previous one.
      Returns:
      The start time of the main service, 0 for a service that has not been started, -1 for a service that has been shut down.
      If you need the old boolean logic use 0 < ping().
    • init

      public void init() throws AbortServiceException
      Initialise the sub service. Startup-required services may already be used here.
      After returning form init(), the sub service must be ready for start().

      This implementation is empty which allows subclasses to omit the initialisation if they do not need one.

      Throws:
      AbortServiceException - If this sub service cannot be initialised due to a severe problem, an AbortServiceException will be thrown. shutdown(boolean) will not be called when aborting; the sub service has to shut down itself/clean up before throwing the exception.
    • start

      public void start() throws AbortServiceException
      Starts the sub service. This method is executed exactly once by the registry and it must return to start further services. For a stand-alone-service own threads or processes have to be started here.
      After returning from start(), the service must be ready to receive any API call. This implicates for instance, that the thread calling this method may not leave the method before a server thread is actually ready to receive requests.

      This implementation is empty which allows subclasses to omit the start procedure if they do not need one.

      Throws:
      AbortServiceException - If this sub service cannot be started due to a severe problem, an AbortServiceException will be thrown. shutdown(boolean) will not be called when aborting; the sub service has to shut down itself/clean up before throwing the exception.
    • shutdown

      public void shutdown(boolean emergency)
      Signals this service that it is being shut down. While this method is called, the service is no longer (remotely) available. It should terminate and close all activities and connections. Since the service is in an inconsistent state while shutting down, access should be restricted to the threads relevant for shutting down. All other requests should be blocked (see ServiceThreadHandling.
      All startup required services are available in shutdown, runtime services may already be shut down.
      In case of an emergency shutdown, even startup required services may not be available. Additionally, shutting down should be rather fast, so cleanup should concentrate on the really important things and use brief timeouts when waiting.

      This implementation is empty.

      Parameters:
      emergency - Whether the shutdown will be an emergency shutdown.