Class Service<C extends ServiceConsumer>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.lang.String SERVICE_LOG_TAG  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Service​(java.lang.String serviceName, java.lang.Integer priority)
      Service constructor.
    • Method Summary

      Modifier and Type Method Description
      static <O> O call​(java.util.concurrent.Callable<O> callable, ServiceSession serviceSession)
      This method execute a callable instance and wait for the response.
      static <O> O call​(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.Future fork​(java.lang.Runnable runnable)
      This method execute any runnable over service thread with a service session.
      protected 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.
      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.Integer getPriority()
      Return the service priority.
      java.lang.String getServiceName()
      Return the service name.
      protected void init()
      This method will be called immediately after of the execution of the service's constructor method
      abstract void registerConsumer​(C consumer)
      This method register the consumer in the service.
      static void run​(java.lang.Runnable runnable, ServiceSession session)
      This method is the gateway to the service subsystem from context out of the hcjf domain.
      static 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.
      protected void shutdown​(Service.ShutdownStage stage)
      This method will be called for the global shutdown process in each stage.
      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.
      static void systemShutdown()
      This method start the global shutdown process.
      abstract void unregisterConsumer​(C consumer)
      Unregister a specific consumer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • SERVICE_LOG_TAG

        protected static final java.lang.String SERVICE_LOG_TAG
        See Also:
        Constant Field Values
    • Constructor Detail

      • Service

        protected Service​(java.lang.String serviceName,
                          java.lang.Integer priority)
        Service constructor.
        Parameters:
        serviceName - Name of the service, can't be null.
        priority - Service execution priority.
        Throws:
        java.lang.NullPointerException - If the name is null.
    • 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.