public interface ADEPT2Service
Beside methods for starting and shutting down, this interface also allows for
defining which other services will be required. This can be achieved by
implementing getStartupRequiredServices() and
getRuntimeRequiredServices() (see the comments of these methods for
further information).
The differentiation allows for a clean start of a service and all of its
dependencies. This also allows for cyclic dependencies between services, as
long as the cycle does not exist within "startup-required" services (
getStartupRequiredServices()).
A service has the following life cycle:
init(URI[], URI[]))start())preShutdown(boolean))shutdown(boolean))
A service may expect that it is only called, when it is in state 'started'.
Starting a service will be accomplished as follows:
init(URI[], URI[])start()
A service needs to provide a constructor accepting a
Configuration as well as a
Registry. The first parameter provides the configuration for the
service, the second one allows the service to retrieve other services from
the registry.
The provided configuration will already be checked against the
ConfigurationDescription of a
service - if present. Such a configuration description allows the service to
declare its needs for its configuration. Complex configurations may be
checked via a
ConfigurationValidator . If
the configuration does not match the configuration description, the service
will not be instantiated at all.
The constructor may throw a ConfigurationException in case the
designated configuration is invalid, for instance, it does not provide a
mandatory configuration value. This is treated like an
AbortServiceException when calling init(URI[], URI[]) or
start(). The service needs to implement the appropriate cleanup - if
necessary in the early stage of constructing - since shutdown(boolean) will
not be called.
To allow for a stable system, services should always check their
configuration in the constructor or not later then start(). At
runtime, an erroneous configuration may be a serious problem for a service.
However, the service can not be shut down easily at this time.
Example for dependencies: A process manager implementation requires a
DataManager (for execution), a LogManager and a JDBCDataSource. Since the
LogManager and the JDBCDataSource are already used during the initialisation,
the process manager implementation will return {"LogManager",
"JDBCDataSource"} in getStartupRequiredServices() and
{"DataManager"} in getRuntimeRequiredServices(). Instead of plain
strings, the constants from
ComponentTypes (for
instance
ComponentTypes.COMPONENT_TYPE_DATA_MANAGER
should be used.
| Modifier and Type | Method and Description |
|---|---|
java.net.URI[] |
getLocalUris()
Returns the URIs under which the service is locally exported.
|
SerialisablePair<java.lang.String,java.lang.String> |
getRelease()
Gets the release of this service, that is, the build version and the build date.
|
java.lang.String[] |
getRuntimeRequiredServices()
Returns a list of service types, which are requested when needed at
runtime.
|
SerialisableTriple<java.lang.String,java.lang.String,java.lang.String> |
getServiceInstanceName()
Gets the (optional) cluster name, the unique node name and the hierarchical instance name of
this service.
|
java.lang.String[] |
getStartupRequiredServices()
Returns a list of service types, which are required for executing the
service.
|
java.net.URI[] |
getURIs()
Returns the URIs which are set for this service in
init(URI[], URI[]). |
void |
init(java.net.URI[] localExportedUris,
java.net.URI[] globalExportedUris)
Initialise the service.
|
long |
ping()
Gets whether the service is running and accepts requests or not and since when.
|
void |
preShutdown(boolean emergency)
Signals this service that it is about to be shut down.
|
void |
shutdown(boolean emergency)
Signals this service that it is being shut down.
|
void |
start()
Starts the service.
|
long ping()
0 for a service that has not been started,
-1 for a service that has been shut down. boolean logic use 0 < ping().SerialisablePair<java.lang.String,java.lang.String> getRelease()
SerialisableTriple<java.lang.String,java.lang.String,java.lang.String> getServiceInstanceName()
java.lang.String[] getStartupRequiredServices()
Registry for
implementations of this type during init(URI[], URI[]) or to
start() the service. 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.
java.lang.String[] getRuntimeRequiredServices()
init(URI[], URI[]) as well as start() have to be returned. When
starting another thread, this has to be synchronised correctly. All services required at startup should not be returned again here.
java.net.URI[] getLocalUris()
java.net.URI[] getURIs()
init(URI[], URI[]).
For a published service these are the global URIs, otherwise the method
will return the local URIs.void init(java.net.URI[] localExportedUris,
java.net.URI[] globalExportedUris)
throws AbortServiceException
init(URI[], URI[]), the service must be ready
for start().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.AbortServiceException - If this service cannot be initialised due to
a severe problem, an AbortServiceException will be
thrown. shutdown(boolean) will not be called when aborting; the
service has to shut down itself/clean up before throwing the
exception.void start()
throws AbortServiceException
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.
AbortServiceException - If this service cannot be started due to
a severe problem, an AbortServiceException will be
thrown. shutdown(boolean) will not be called when aborting; the
service has to shut down itself/clean up before throwing the
exception.void preShutdown(boolean emergency)
shutdown(boolean). All startup required services are available in pre shutdown, runtime
services may already be shut down. emergency - Whether the shutdown will be an emergency shutdown. Normally a service should
not do anything in pre-shutdown in case of an emergency.void shutdown(boolean emergency)
ServiceThreadHandling. emergency - Whether the shutdown will be an emergency shutdown.