public class InjectedADEPT2Service extends java.lang.Object implements ADEPT2Service
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.
| Modifier and Type | Field and Description |
|---|---|
protected static java.lang.String[] |
EMPTY_STRING_ARRAY
An empty string array for usage as startup and runtime required services if
no services are provided.
|
protected java.util.logging.Logger |
logger
The logger of this service for usage by subclasses.
|
protected java.lang.String[] |
runtimeRequiredServices
The services which are required and requested lazily at runtime.
|
protected java.lang.String[] |
startupRequiredServices
The services which are required for starting the injected service.
|
| Modifier | Constructor and Description |
|---|---|
protected |
InjectedADEPT2Service()
Creates a new service with the standard logger and no startup and runtime
required services.
|
protected |
InjectedADEPT2Service(java.util.logging.Logger logger)
Creates a new service with the designated logger and no startup and runtime
required services.
|
protected |
InjectedADEPT2Service(java.util.logging.Logger logger,
java.lang.String[] startupRequiredServices,
java.lang.String[] runtimeRequiredServices)
Creates a new service with the designated logger and no startup and runtime
required services.
|
| Modifier and Type | Method and Description |
|---|---|
java.net.URI[] |
getLocalUris()
Returns the URIs under which the service is locally exported.
|
java.util.logging.Logger |
getLogger()
Gets the logger to be used by subclasses.
|
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
ADEPT2Service.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)
Empty convenience method.
|
void |
shutdown(boolean emergency)
Signals this service that it is being shut down.
|
void |
start()
Starts the service.
|
protected static final java.lang.String[] EMPTY_STRING_ARRAY
protected final java.util.logging.Logger logger
protected final java.lang.String[] startupRequiredServices
protected final java.lang.String[] runtimeRequiredServices
protected InjectedADEPT2Service()
protected InjectedADEPT2Service(java.util.logging.Logger logger)
logger - The logger to be used by this service. If this is
null, the default logger (using the class name) will
be used.protected InjectedADEPT2Service(java.util.logging.Logger logger,
java.lang.String[] startupRequiredServices,
java.lang.String[] runtimeRequiredServices)
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.public java.util.logging.Logger getLogger()
public long ping()
ADEPT2Serviceping in interface ADEPT2Service0 for a service that has not been started,
-1 for a service that has been shut down. boolean logic use 0 < ping().public SerialisablePair<java.lang.String,java.lang.String> getRelease()
ADEPT2ServicegetRelease in interface ADEPT2Servicepublic SerialisableTriple<java.lang.String,java.lang.String,java.lang.String> getServiceInstanceName()
ADEPT2ServicegetServiceInstanceName in interface ADEPT2Servicepublic java.lang.String[] getStartupRequiredServices()
ADEPT2ServiceRegistry for
implementations of this type during ADEPT2Service.init(URI[], URI[]) or to
ADEPT2Service.start() the service. 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.
getStartupRequiredServices in interface ADEPT2Servicepublic java.lang.String[] getRuntimeRequiredServices()
ADEPT2ServiceADEPT2Service.init(URI[], URI[]) as well as ADEPT2Service.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.
getRuntimeRequiredServices in interface ADEPT2Servicepublic java.net.URI[] getLocalUris()
ADEPT2ServicegetLocalUris in interface ADEPT2Servicepublic java.net.URI[] getURIs()
ADEPT2ServiceADEPT2Service.init(URI[], URI[]).
For a published service these are the global URIs, otherwise the method
will return the local URIs.getURIs in interface ADEPT2Servicepublic void init(java.net.URI[] localExportedUris,
java.net.URI[] globalExportedUris)
throws AbortServiceException
ADEPT2ServiceADEPT2Service.init(URI[], URI[]), the service must be ready
for ADEPT2Service.start().init in interface ADEPT2ServicelocalExportedUris - 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. ADEPT2Service.shutdown(boolean) will not be called when aborting; the
service has to shut down itself/clean up before throwing the
exception.public void start()
throws AbortServiceException
ADEPT2Service
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.
start in interface ADEPT2ServiceAbortServiceException - 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.public void preShutdown(boolean emergency)
preShutdown in interface ADEPT2Serviceemergency - Whether the shutdown will be an emergency shutdown. Normally a service should
not do anything in pre-shutdown in case of an emergency.public void shutdown(boolean emergency)
ADEPT2ServiceServiceThreadHandling. shutdown in interface ADEPT2Serviceemergency - Whether the shutdown will be an emergency shutdown.