Class InjectedADEPT2Service

  • All Implemented Interfaces:
    ADEPT2Service
    Direct Known Subclasses:
    InitialisedInjectedService

    public class InjectedADEPT2Service
    extends Object
    implements ADEPT2Service
    A class to simplify the implementation of an object that should be injected into the AristaFlow platform when bootstrapping. Only classes implementing ADEPT2Service are allowed to be injected. This class provides the basic interface.

    Injected services are initialised, started and shutdown(boolean) just like the normal ADEPT2Service. Therefore startup and runtime required services also apply for injected services. This allows injected services to use the platform themselves. The main difference is, that they are instantiated outside the platform and therefore do neither get a configuration nor a registry.

    • Field Detail

      • EMPTY_STRING_ARRAY

        protected static final String[] EMPTY_STRING_ARRAY
        An empty string array for usage as startup and runtime required services if no services are provided.
      • logger

        protected final Logger logger
        The logger of this service for usage by subclasses.
      • startupRequiredServices

        protected final String[] startupRequiredServices
        The services which are required for starting the injected service.
      • runtimeRequiredServices

        protected final String[] runtimeRequiredServices
        The services which are required and requested lazily at runtime.
    • Constructor Detail

      • InjectedADEPT2Service

        protected InjectedADEPT2Service()
        Creates a new service with the standard logger and no startup and runtime required services.
      • InjectedADEPT2Service

        protected InjectedADEPT2Service​(Logger logger)
        Creates a new service with the designated logger and no startup and runtime required services.
        Parameters:
        logger - The logger to be used by this service. If this is null, the default logger (using the class name) will be used.
      • InjectedADEPT2Service

        protected InjectedADEPT2Service​(Logger logger,
                                        String[] startupRequiredServices,
                                        String[] runtimeRequiredServices)
        Creates a new service with the designated logger and no startup and runtime required services.
        Parameters:
        logger - The logger to be used by this service. If this is null, the default logger (using the class name) will be used.
        startupRequiredServices - The service type names of services required at startup time (in init(URI[], URI[]) and start()). This may be null.
        runtimeRequiredServices - The service type names of services required at runtime (after startup time). This may be null.
    • Method Detail

      • getLogger

        public Logger getLogger()
        Gets the logger to be used by subclasses. Note that the logger might be changed in the lifecycle of the service.
        Returns:
        The logger to be used by subclasses.
      • ping

        public long ping()
        Description copied from interface: ADEPT2Service
        Gets whether the 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 service can be detected by comparing the returned start time with the previous one.
        Specified by:
        ping in interface ADEPT2Service
        Returns:
        The start time of the 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().
      • getServiceInstanceName

        public SerialisableTriple<String,​String,​String> getServiceInstanceName()
        Description copied from interface: ADEPT2Service
        Gets the (optional) cluster name, the unique node name and the hierarchical instance name of this service.
        Specified by:
        getServiceInstanceName in interface ADEPT2Service
        Returns:
        The (optional) cluster name, the unique node name and the hierarchical instance name of this service.
      • getStartupRequiredServices

        public String[] getStartupRequiredServices()
        Description copied from interface: ADEPT2Service
        Returns a list of service types, which are required for executing the service. The service is allowed for querying the Registry for implementations of this type during ADEPT2Service.init(URI[], URI[]) or to ADEPT2Service.start() the service.
        It is assured that ADEPT2Service.init(URI[], URI[]) is not called before the required services are started. The order in the array is not relevant since the dependencies of the required services are also inspected and respected.
        These services may also be accessed when shutting down the service.
        Specified by:
        getStartupRequiredServices in interface ADEPT2Service
        Returns:
        A list of service types which are required by this service.
      • getRuntimeRequiredServices

        public String[] getRuntimeRequiredServices()
        Description copied from interface: ADEPT2Service
        Returns a list of service types, which are requested when needed at runtime. This has to be after the component is initialised and started and before the shutdown. This means before requesting a runtime required service ADEPT2Service.init(URI[], URI[]) as well as ADEPT2Service.start() have to be returned. When starting another thread, this has to be synchronised correctly.
        Since these services are not necessarily started before this service, they may be shutdown before shutting down this service. This has to be considered when calling a runtime required service. If a service is absolutely necessary when shutting down, it will have to be declared as startup-required.

        All services required at startup should not be returned again here.

        Specified by:
        getRuntimeRequiredServices in interface ADEPT2Service
        Returns:
        A list of services which are required during runtime and requested lazily.
      • getLocalUris

        public URI[] getLocalUris()
        Description copied from interface: ADEPT2Service
        Returns the URIs under which the service is locally exported. If this service is only locally available, there will be only one URI and this is a local one. The request for the corresponding component will fail if it is not a local service.
        Internal services may return an empty array.
        Specified by:
        getLocalUris in interface ADEPT2Service
        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.
      • init

        public void init​(URI[] localExportedUris,
                         URI[] globalExportedUris)
                  throws AbortServiceException
        Description copied from interface: ADEPT2Service
        Initialise the service. Startup-required services may already be used here.
        After returning form ADEPT2Service.init(URI[], URI[]), the service must be ready for ADEPT2Service.start().
        Specified by:
        init in interface ADEPT2Service
        Parameters:
        localExportedUris - The URIs with which this service is exported locally or a local URI or an empty array for internal services.
        globalExportedUris - The URIs with which this service is published globally or null in case the service is not published.
        Throws:
        AbortServiceException - If this service cannot be initialised due to a severe problem, an AbortServiceException will be thrown. ADEPT2Service.shutdown(boolean) will not be called when aborting; the service has to shut down itself/clean up before throwing the exception.
      • start

        public void start()
                   throws AbortServiceException
        Description copied from interface: ADEPT2Service
        Starts the 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.
        This method is executed exactly once by the registry.

        After returning from ADEPT2Service.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.

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

        public void preShutdown​(boolean emergency)
        Empty convenience method.
        Specified by:
        preShutdown in interface ADEPT2Service
        Parameters:
        emergency - Whether the shutdown will be an emergency shutdown. Normally a service should not do anything in pre-shutdown in case of an emergency.
      • shutdown

        public void shutdown​(boolean emergency)
        Description copied from interface: ADEPT2Service
        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.
        Specified by:
        shutdown in interface ADEPT2Service
        Parameters:
        emergency - Whether the shutdown will be an emergency shutdown.