Class InjectedADEPT2Service
java.lang.Object
de.aristaflow.adept2.core.registry.InjectedADEPT2Service
- All Implemented Interfaces:
ADEPT2Service
- Direct Known Subclasses:
InitialisedInjectedService
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 Summary
FieldsModifier and TypeFieldDescriptionprotected static final String[]An empty string array for usage as startup and runtime required services if no services are provided.protected final LoggerThe logger of this service for usage by subclasses.protected final String[]The services which are required and requested lazily at runtime.protected final String[]The services which are required for starting the injected service. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new service with the standard logger and no startup and runtime required services.protectedInjectedADEPT2Service(Logger logger) Creates a new service with the designated logger and no startup and runtime required services.protectedInjectedADEPT2Service(Logger logger, String[] startupRequiredServices, String[] runtimeRequiredServices) Creates a new service with the designated logger and no startup and runtime required services. -
Method Summary
Modifier and TypeMethodDescriptionURI[]Returns the URIs under which the service is locally exported.Gets the logger to be used by subclasses.Gets the release of this service, that is, the build version and the build date.String[]Returns a list of service types, which are requested when needed at runtime.Gets the (optional) cluster name, the unique node name and the hierarchical instance name of this service.String[]Returns a list of service types, which are required for executing the service.URI[]getURIs()Returns the URIs which are set for this service inADEPT2Service.init(URI[], URI[]).voidInitialise the service.longping()Gets whether the service is running and accepts requests or not and since when.voidpreShutdown(boolean emergency) Empty convenience method.voidshutdown(boolean emergency) Signals this service that it is being shut down.voidstart()Starts the service.
-
Field Details
-
EMPTY_STRING_ARRAY
An empty string array for usage as startup and runtime required services if no services are provided. -
logger
The logger of this service for usage by subclasses. -
startupRequiredServices
The services which are required for starting the injected service. -
runtimeRequiredServices
The services which are required and requested lazily at runtime.
-
-
Constructor Details
-
InjectedADEPT2Service
protected InjectedADEPT2Service()Creates a new service with the standard logger and no startup and runtime required services. -
InjectedADEPT2Service
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 isnull, 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 isnull, the default logger (using the class name) will be used.startupRequiredServices- The service type names of services required at startup time (ininit(URI[], URI[])andstart()). This may benull.runtimeRequiredServices- The service type names of services required at runtime (after startup time). This may benull.
-
-
Method Details
-
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:ADEPT2ServiceGets 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:
pingin interfaceADEPT2Service- Returns:
- The start time of the service,
0for a service that has not been started,-1for a service that has been shut down.
If you need the oldbooleanlogic use0 < ping().
-
getRelease
Description copied from interface:ADEPT2ServiceGets the release of this service, that is, the build version and the build date.- Specified by:
getReleasein interfaceADEPT2Service- Returns:
- The build version and the build date of this service.
-
getServiceInstanceName
Description copied from interface:ADEPT2ServiceGets the (optional) cluster name, the unique node name and the hierarchical instance name of this service.- Specified by:
getServiceInstanceNamein interfaceADEPT2Service- Returns:
- The (optional) cluster name, the unique node name and the hierarchical instance name of this service.
-
getStartupRequiredServices
Description copied from interface:ADEPT2ServiceReturns a list of service types, which are required for executing the service. The service is allowed for querying theRegistryfor implementations of this type duringADEPT2Service.init(URI[], URI[])or toADEPT2Service.start()the service.
It is assured thatADEPT2Service.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:
getStartupRequiredServicesin interfaceADEPT2Service- Returns:
- A list of service types which are required by this service.
-
getRuntimeRequiredServices
Description copied from interface:ADEPT2ServiceReturns 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 serviceADEPT2Service.init(URI[], URI[])as well asADEPT2Service.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:
getRuntimeRequiredServicesin interfaceADEPT2Service- Returns:
- A list of services which are required during runtime and requested lazily.
-
getLocalUris
Description copied from interface:ADEPT2ServiceReturns 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:
getLocalUrisin interfaceADEPT2Service- 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
Description copied from interface:ADEPT2ServiceReturns the URIs which are set for this service inADEPT2Service.init(URI[], URI[]). For a published service these are the global URIs, otherwise the method will return the local URIs.- Specified by:
getURIsin interfaceADEPT2Service- Returns:
- The URIs with which this service is globally published or the local URIs.
-
init
Description copied from interface:ADEPT2ServiceInitialise the service. Startup-required services may already be used here.
After returning formADEPT2Service.init(URI[], URI[]), the service must be ready forADEPT2Service.start().- Specified by:
initin interfaceADEPT2Service- 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 ornullin case the service is not published.- Throws:
AbortServiceException- If this service cannot be initialised due to a severe problem, anAbortServiceExceptionwill 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
Description copied from interface:ADEPT2ServiceStarts 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:
startin interfaceADEPT2Service- Throws:
AbortServiceException- If this service cannot be started due to a severe problem, anAbortServiceExceptionwill 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:
preShutdownin interfaceADEPT2Service- 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:ADEPT2ServiceSignals 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 (seeServiceThreadHandling.
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:
shutdownin interfaceADEPT2Service- Parameters:
emergency- Whether the shutdown will be an emergency shutdown.
-