Package org.hcjf.service
Class Service<C extends ServiceConsumer>
- java.lang.Object
-
- org.hcjf.service.Service<C>
-
- Direct Known Subclasses:
BroadcastService,Cloud,CloudOrchestrator,Events,FileSystemWatcherService,KubernetesSpy,Log,Naming,NetService,ProcessDiscoveryService
public abstract class Service<C extends ServiceConsumer> extends java.lang.ObjectThis abstract class contains all the implementations and the interfaces that describe the behavior of the system service.- Author:
- javaito
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classService.RunnableWrapperComparatorThis comparator gets priority to service runnable.protected static classService.ShutdownStageEnum all the shutting down stagesstatic classService.StaticServiceThreadstatic classService.ThreadPoolAgentstatic interfaceService.ThreadPoolAgentMBean
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringSERVICE_LOG_TAG
-
Constructor Summary
Constructors Modifier Constructor Description protectedService(java.lang.String serviceName, java.lang.Integer priority)Service constructor.
-
Method Summary
Modifier and Type Method Description static <O> Ocall(java.util.concurrent.Callable<O> callable, ServiceSession serviceSession)This method execute a callable instance and wait for the response.static <O> Ocall(java.util.concurrent.Callable<O> callable, ServiceSession serviceSession, long timeout)This method execute a callable instance and wait for the response.protected java.util.concurrent.Futurefork(java.lang.Runnable runnable)This method execute any runnable over service thread with a service session.protected java.util.concurrent.Futurefork(java.lang.Runnable runnable, java.lang.String executorName, java.util.concurrent.ThreadPoolExecutor executor)This method execute any runnnable over service thread with a service session using an custom thread pool threadPoolExecutor.protected <R> java.util.concurrent.Future<R>fork(java.util.concurrent.Callable<R> callable)This method execute any callable over service thread with a service session.protected <R> java.util.concurrent.Future<R>fork(java.util.concurrent.Callable<R> callable, java.lang.String executorName, java.util.concurrent.ThreadPoolExecutor executor)This method execute any callable over service thread with a service session using an custom thread pool threadPoolExecutor.java.lang.IntegergetPriority()Return the service priority.java.lang.StringgetServiceName()Return the service name.protected voidinit()This method will be called immediately after of the execution of the service's constructor methodabstract voidregisterConsumer(C consumer)This method register the consumer in the service.static voidrun(java.lang.Runnable runnable, ServiceSession session)This method is the gateway to the service subsystem from context out of the hcjf domain.static voidrun(java.lang.Runnable runnable, ServiceSession session, boolean waitFor, long timeout)This method is the gateway to the service subsystem from context out of the hcjf domain.protected voidshutdown(Service.ShutdownStage stage)This method will be called for the global shutdown process in each stage.protected voidshutdownExecutor(java.util.concurrent.ThreadPoolExecutor executor)This method will be called for the global shutdown process when the process try to finalize the registered thread pool executors.static voidsystemShutdown()This method start the global shutdown process.abstract voidunregisterConsumer(C consumer)Unregister a specific consumer.
-
-
-
Field Detail
-
SERVICE_LOG_TAG
protected static final java.lang.String SERVICE_LOG_TAG
- See Also:
- Constant Field Values
-
-
Method Detail
-
fork
protected final <R> java.util.concurrent.Future<R> fork(java.util.concurrent.Callable<R> callable)
This method execute any callable over service thread with a service session.- Type Parameters:
R- Expected result.- Parameters:
callable- Callable to execute.- Returns:
- Callable's future.
-
fork
protected final <R> java.util.concurrent.Future<R> fork(java.util.concurrent.Callable<R> callable, java.lang.String executorName, java.util.concurrent.ThreadPoolExecutor executor)This method execute any callable over service thread with a service session using an custom thread pool threadPoolExecutor. This thread pool threadPoolExecutor must create only Service thread implementations.- Type Parameters:
R- Expected return type.- Parameters:
callable- Callable to execute.executorName- Name of the executor.executor- Custom thread pool threadPoolExecutor.- Returns:
- Callable's future.
-
fork
protected final java.util.concurrent.Future fork(java.lang.Runnable runnable)
This method execute any runnable over service thread with a service session.- Parameters:
runnable- Runnable to execute.- Returns:
- Runnable's future.
-
fork
protected final java.util.concurrent.Future fork(java.lang.Runnable runnable, java.lang.String executorName, java.util.concurrent.ThreadPoolExecutor executor)This method execute any runnnable over service thread with a service session using an custom thread pool threadPoolExecutor. This thread pool threadPoolExecutor must create only Service thread implementations.- Parameters:
runnable- Runnable to execute.executorName- Name of the executor.executor- Custom thread pool threadPoolExecutor.- Returns:
- Runnable's future.
-
getServiceName
public final java.lang.String getServiceName()
Return the service name.- Returns:
- Service name.
-
getPriority
public final java.lang.Integer getPriority()
Return the service priority.- Returns:
- Service priority.
-
init
protected void init()
This method will be called immediately after of the execution of the service's constructor method
-
shutdown
protected void shutdown(Service.ShutdownStage stage)
This method will be called for the global shutdown process in each stage.- Parameters:
stage- Shutdown stage.
-
shutdownExecutor
protected void shutdownExecutor(java.util.concurrent.ThreadPoolExecutor executor)
This method will be called for the global shutdown process when the process try to finalize the registered thread pool executors.- Parameters:
executor- Thread pool threadPoolExecutor to finalize.
-
registerConsumer
public abstract void registerConsumer(C consumer)
This method register the consumer in the service.- Parameters:
consumer- Object with the logic to consume the service.- Throws:
java.lang.RuntimeException- It contains exceptions generated by the particular logic of each implementation.
-
unregisterConsumer
public abstract void unregisterConsumer(C consumer)
Unregister a specific consumer.- Parameters:
consumer- Consumer to unregister.
-
systemShutdown
public static final void systemShutdown()
This method start the global shutdown process.
-
run
public static final void run(java.lang.Runnable runnable, ServiceSession session)This method is the gateway to the service subsystem from context out of the hcjf domain.- Parameters:
runnable- Custom runnable.session- Custom session.
-
run
public static final void run(java.lang.Runnable runnable, ServiceSession session, boolean waitFor, long timeout)This method is the gateway to the service subsystem from context out of the hcjf domain.- Parameters:
runnable- Custom runnable.session- Custom session.waitFor- Wait fot the execution ends.timeout- Wait time out, if this value is lower than 0 then the timeout is infinite.
-
call
public static final <O> O call(java.util.concurrent.Callable<O> callable, ServiceSession serviceSession)This method execute a callable instance and wait for the response.- Type Parameters:
O- Expected response.- Parameters:
callable- Callable instance.serviceSession- Service session.- Returns:
- Result instance.
-
call
public static final <O> O call(java.util.concurrent.Callable<O> callable, ServiceSession serviceSession, long timeout)This method execute a callable instance and wait for the response.- Type Parameters:
O- Expected response.- Parameters:
callable- Callable instance.serviceSession- Service session.timeout- Max time for the execution.- Returns:
- Result instance.
-
-