Package de.aristaflow.adept2.core.client
Class ClientServiceSharedServices
- java.lang.Object
-
- de.aristaflow.adept2.base.service.AbstractSubService<AbstractADEPT2Service>
-
- de.aristaflow.adept2.core.client.ClientServiceSharedServices
-
public class ClientServiceSharedServices extends AbstractSubService<AbstractADEPT2Service>
Sub-service implementation which implements some default behaviour for all implementations ofClientService
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ClientServiceSharedServices.ServiceAvailabilityTracker
A tracker for the availability of a specificADEPT2Service
s.
-
Field Summary
Fields Modifier and Type Field Description protected Map<ADEPT2Service,ClientServiceSharedServices.ServiceAvailabilityTracker>
availTracker
The listeners registered for the availability of anADEPT2Service
and the corresponding service availability tracker.static String
CONF_EXECUTOR_POOL_SIZE
Configuration key for the amount of threads used for theexecutorService
.static String
CONF_SCHEDULED_EXECUTOR_POOL_SIZE
Configuration key for the amount of threads used for thescheduledExecutorService
.static String
CONF_SERVICE_AVAILABILITY_POLL_RATE
Configuration key for the rate at which to poll the availability of services.static String
CONF_SERVICE_AVAILABILITY_POOL_SIZE
Configuration key for the amount of threads used for the service availability check.protected int
executorPoolSize
The amount of threads used for theexecutorService
.protected ExecutorService
executorService
The executor service that is used for new threads started by client components.protected int
scheduledExecutorPoolSize
The amount of threads used for thescheduledExecutorService
.protected LoggingScheduledThreadPoolExecutor
scheduledExecutorService
The scheduled executor service that is used for new threads scheduled by client components.protected long
servAvailPollRate
The rate in milliseconds at which to poll the availability of servicesserviceAvailibilityChecker
.protected int
servAvailPoolSize
The amount of threads used for theserviceAvailibilityChecker
.protected ScheduledExecutorService
serviceAvailibilityChecker
The thread pool for checking the availability of services and notifying changes to the registered listeners.-
Fields inherited from class de.aristaflow.adept2.base.service.AbstractSubService
logger, runtimeRequiredServices, service, startupRequiredServices
-
-
Constructor Summary
Constructors Constructor Description ClientServiceSharedServices(AbstractADEPT2Service service, org.apache.commons.configuration2.Configuration configuration)
Default constructors, expects some configuration values to be set in the provided configuration:CONF_EXECUTOR_POOL_SIZE
CONF_SCHEDULED_EXECUTOR_POOL_SIZE
CONF_SERVICE_AVAILABILITY_POOL_SIZE
CONF_SERVICE_AVAILABILITY_POLL_RATE
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addServiceStateListener(ADEPT2Service service, ClientService.ServiceStateListener listener)
Cf.void
awaitTermination()
Await the termination of the executors, must be called after callingshutdown(boolean)
.ExecutorService
getExecutorService()
Cf.LoggingScheduledThreadPoolExecutor
getScheduledExecutorService()
Cf.void
init()
Initialise the sub service.void
removeServiceStateListener(ADEPT2Service service, ClientService.ServiceStateListener listener)
Cf.void
shutdown(boolean emergency)
Signals this service that it is being shut down.-
Methods inherited from class de.aristaflow.adept2.base.service.AbstractSubService
getLocalUris, getRuntimeRequiredServices, getStartupRequiredServices, getURIs, ping, privilegeSession, sessionActive, sessionFinished, start
-
-
-
-
Field Detail
-
CONF_EXECUTOR_POOL_SIZE
public static final String CONF_EXECUTOR_POOL_SIZE
Configuration key for the amount of threads used for theexecutorService
.- See Also:
- Constant Field Values
-
CONF_SCHEDULED_EXECUTOR_POOL_SIZE
public static final String CONF_SCHEDULED_EXECUTOR_POOL_SIZE
Configuration key for the amount of threads used for thescheduledExecutorService
.- See Also:
- Constant Field Values
-
CONF_SERVICE_AVAILABILITY_POOL_SIZE
public static final String CONF_SERVICE_AVAILABILITY_POOL_SIZE
Configuration key for the amount of threads used for the service availability check.- See Also:
- Constant Field Values
-
CONF_SERVICE_AVAILABILITY_POLL_RATE
public static final String CONF_SERVICE_AVAILABILITY_POLL_RATE
Configuration key for the rate at which to poll the availability of services.- See Also:
- Constant Field Values
-
executorPoolSize
protected final int executorPoolSize
The amount of threads used for theexecutorService
.
-
executorService
protected ExecutorService executorService
The executor service that is used for new threads started by client components.
-
scheduledExecutorPoolSize
protected final int scheduledExecutorPoolSize
The amount of threads used for thescheduledExecutorService
.
-
scheduledExecutorService
protected LoggingScheduledThreadPoolExecutor scheduledExecutorService
The scheduled executor service that is used for new threads scheduled by client components.
-
availTracker
protected final Map<ADEPT2Service,ClientServiceSharedServices.ServiceAvailabilityTracker> availTracker
The listeners registered for the availability of anADEPT2Service
and the corresponding service availability tracker.
-
serviceAvailibilityChecker
protected ScheduledExecutorService serviceAvailibilityChecker
The thread pool for checking the availability of services and notifying changes to the registered listeners.
-
servAvailPoolSize
protected final int servAvailPoolSize
The amount of threads used for theserviceAvailibilityChecker
.
-
servAvailPollRate
protected final long servAvailPollRate
The rate in milliseconds at which to poll the availability of servicesserviceAvailibilityChecker
.
-
-
Constructor Detail
-
ClientServiceSharedServices
public ClientServiceSharedServices(AbstractADEPT2Service service, org.apache.commons.configuration2.Configuration configuration)
Default constructors, expects some configuration values to be set in the provided configuration:- Parameters:
service
- The ClientService implementationconfiguration
- The configuration of the client service.
-
-
Method Detail
-
init
public void init() throws AbortServiceException
Description copied from class:AbstractSubService
Initialise the sub service. Startup-required services may already be used here.
After returning formAbstractSubService.init()
, the sub service must be ready forAbstractSubService.start()
.This implementation is empty which allows subclasses to omit the initialisation if they do not need one.
- Overrides:
init
in classAbstractSubService<AbstractADEPT2Service>
- Throws:
AbortServiceException
- If this sub service cannot be initialised due to a severe problem, anAbortServiceException
will be thrown.AbstractSubService.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)
Description copied from class:AbstractSubService
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.
- Overrides:
shutdown
in classAbstractSubService<AbstractADEPT2Service>
- Parameters:
emergency
- Whether the shutdown will be an emergency shutdown.
-
awaitTermination
public void awaitTermination()
Await the termination of the executors, must be called after callingshutdown(boolean)
.
-
getExecutorService
public ExecutorService getExecutorService()
-
getScheduledExecutorService
public LoggingScheduledThreadPoolExecutor getScheduledExecutorService()
-
addServiceStateListener
public boolean addServiceStateListener(ADEPT2Service service, ClientService.ServiceStateListener listener)
-
removeServiceStateListener
public void removeServiceStateListener(ADEPT2Service service, ClientService.ServiceStateListener listener)
-
-