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
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 Summary
FieldsModifier and TypeFieldDescriptionprotected LoggerThe logger of the corresponding main service this sub service belongs to.protected final String[]The service type names of services required at runtime (after startup time) by this sub service.protected final TThe corresponding main service this sub service belongs to.protected final String[]The service type names of services required at runtime (after startup time) by this sub service. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractSubService(String[] startupRequiredServices, String[] runtimeRequiredServices, T service) Creates a simple sub service with the designated required services for the designated main service.AbstractSubService(T service) Creates a simple sub service for the designated main service. -
Method Summary
Modifier and TypeMethodDescriptionprotected URI[]Forwards toAbstractADEPT2Service.getLocalUris()of the main service.final String[]Gets the service type names of services required at runtime (after startup time) by this sub service.final String[]protected URI[]getURIs()Forwards toAbstractADEPT2Service.getURIs()of the main service.voidinit()Initialise the sub service.longping()Gets whether the main service is running and accepts requests or not and since when.protected final voidprivilegeSession(SessionToken activeSession, SessionToken newSession) Forwards toAbstractADEPT2Service.privilegeSession(SessionToken, SessionToken)of the main service.protected final voidsessionActive(SessionToken session) Forwards toAbstractADEPT2Service.sessionActive(SessionToken)of the main service.protected final voidsessionFinished(SessionToken session) Forwards toAbstractADEPT2Service.sessionFinished(SessionToken)of the main service.voidshutdown(boolean emergency) Signals this service that it is being shut down.voidstart()Starts the sub service.
-
Field Details
-
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
The service type names of services required at runtime (after startup time) by this sub service. -
runtimeRequiredServices
The service type names of services required at runtime (after startup time) by this sub service. -
service
The corresponding main service this sub service belongs to.
-
-
Constructor Details
-
AbstractSubService
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 (ininit()andstart()) 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
Forwards toAbstractADEPT2Service.privilegeSession(SessionToken, SessionToken)of the main service.- 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
Forwards toAbstractADEPT2Service.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
Forwards toAbstractADEPT2Service.sessionFinished(SessionToken)of the main service.- 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
-
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
Forwards toAbstractADEPT2Service.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
Forwards toAbstractADEPT2Service.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,
0for a service that has not been started,-1for a service that has been shut down.
If you need the oldbooleanlogic use0 < ping().
-
init
Initialise the sub service. Startup-required services may already be used here.
After returning forminit(), the sub service must be ready forstart().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, anAbortServiceExceptionwill 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
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 fromstart(), 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, anAbortServiceExceptionwill 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 (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.This implementation is empty.
- Parameters:
emergency- Whether the shutdown will be an emergency shutdown.
-