Class BaseHelper<T extends Connector>

  • Direct Known Subclasses:
    ConnectionHelper

    @Deprecated
    public abstract class BaseHelper<T extends Connector>
    extends ConnectorHelper<T>
    Deprecated.
    Will be removed to favor lower-level network extensions allowing more control at the Restlet API level.
    Base connector helper. Here is the list of parameters that are supported. They should be set in the connector's context before it is started:
    Parameter name Value type Default value Description
    controllerDaemon boolean true (client), false (server) Indicates if the controller thread should be a daemon (not blocking JVM exit).
    controllerSleepTimeMs int 60 000 Time for the controller thread to sleep between each control. A value strictly superior to 0 is required.
    minThreads int 1 Minimum number of worker threads waiting to service calls, even if they are idle. Technically speaking, this is a core number of threads that are pre-started.
    lowThreads int 8 Number of worker threads determining when the connector is considered overloaded. This triggers some protection actions such as not accepting new connections.
    maxThreads int 10 Maximum number of worker threads that can service calls. If this number is reached then additional calls are queued if the "maxQueued" value hasn't been reached.
    maxQueued int 0 Maximum number of calls that can be queued if there aren't any worker thread available to service them. If the value is '0', then no queue is used and calls are rejected if no worker thread is immediately available. If the value is '-1', then an unbounded queue is used and calls are never rejected.

    Note: make sure that this value is consistent with getMinThreads() and the behavior of the ThreadPoolExecutor configured internally.
    maxIoIdleTimeMs int 60 000 Maximum time for an idle IO connection or request to wait for an operation before being closed. For an unlimited wait, use '0' as value.
    maxThreadIdleTimeMs int 300 000 Time for an idle thread to wait for an operation before being collected.
    tracing boolean false Indicates if all messages should be printed on the standard console.
    workerThreads boolean true Indicates if the processing of calls should be done via threads provided by a worker service (i.e. a pool of worker threads). Note that if set to false, calls will be processed a single IO selector thread, which should never block, otherwise the other connections would hang.
    inboundBufferSize int 16 * 1024 Size of the content buffer for receiving messages.
    outboundBufferSize int 32 * 1024 Size of the content buffer for sending messages.
    directBuffers boolean false Indicates if direct NIO buffers should be allocated instead of regular buffers. See NIO's ByteBuffer Javadocs. Note that tracing must be disabled to use direct buffers.
    throttleTimeMs int 0 Time to wait between socket write operations in milliseconds. Can prevent TCP buffer overflows.
    transport String TCP Indicates the transport protocol such as TCP or UDP.
    • Field Detail

      • clientSide

        protected final boolean clientSide
        Deprecated.
        Indicates if it is helping a client connector.
      • controllerService

        private volatile java.util.concurrent.ExecutorService controllerService
        Deprecated.
        The controller service.
      • inboundMessages

        protected final java.util.Queue<Response> inboundMessages
        Deprecated.
        The queue of inbound messages.
      • outboundMessages

        protected final java.util.Queue<Response> outboundMessages
        Deprecated.
        The queue of outbound messages.
      • workerService

        private volatile java.util.concurrent.ThreadPoolExecutor workerService
        Deprecated.
        The worker service.
    • Constructor Detail

      • BaseHelper

        public BaseHelper​(T connector,
                          boolean clientSide)
        Deprecated.
        Constructor.
        Parameters:
        connector - The helped connector.
        clientSide - True if it is helping a client connector.
    • Method Detail

      • control

        public boolean control()
        Deprecated.
        Controls the helper for inbound or outbound messages to handle.
        Returns:
        Indicates if some concrete activity occurred.
      • createController

        protected abstract ConnectionController createController()
        Deprecated.
        Creates a new controller.
        Returns:
        A new controller.
      • createControllerService

        protected java.util.concurrent.ExecutorService createControllerService()
        Deprecated.
        Creates the connector controller service.
        Returns:
        The connector controller service.
      • createRequest

        protected Request createRequest()
        Deprecated.
        Creates the request object.
        Returns:
        The request object.
      • createWorkerService

        protected java.util.concurrent.ThreadPoolExecutor createWorkerService()
        Deprecated.
        Creates the handler service.
        Returns:
        The handler service.
      • doFinishStop

        protected void doFinishStop()
        Deprecated.
        Finish stopping the helper.
      • doGracefulStop

        protected void doGracefulStop()
        Deprecated.
        Do a graceful stop first.
      • doHandleInbound

        public abstract void doHandleInbound​(Response response)
        Deprecated.
        Effectively handles an inbound message.
        Parameters:
        response - The response to handle.
      • doHandleOutbound

        public abstract void doHandleOutbound​(Response response)
        Deprecated.
        Effectively handles an outbound message.
        Parameters:
        response - The response to handle.
      • execute

        protected void execute​(java.lang.Runnable task)
        Deprecated.
        Executes the next task in a separate thread provided by the worker service, only if the worker service isn't busy.
        Parameters:
        task - The next task to execute.
      • getController

        public ConnectionController getController()
        Deprecated.
        Returns the controller task.
        Returns:
        The controller task.
      • getControllerSleepTimeMs

        public int getControllerSleepTimeMs()
        Deprecated.
        Returns the time for the controller thread to sleep between each control.
        Returns:
        The time for the controller thread to sleep between each control.
      • getInboundBufferSize

        public int getInboundBufferSize()
        Deprecated.
        Returns the size of the content buffer for receiving messages.
        Returns:
        The size of the content buffer for receiving messages.
      • getInboundMessages

        public java.util.Queue<Response> getInboundMessages()
        Deprecated.
        Returns the queue of inbound messages pending for handling.
        Returns:
        The queue of inbound messages.
      • getLowThreads

        public int getLowThreads()
        Deprecated.
        Returns the number of threads for the overload state.
        Returns:
        The number of threads for the overload state.
      • getMaxIoIdleTimeMs

        public int getMaxIoIdleTimeMs()
        Deprecated.
        Returns the time for an idle IO connection or request to wait for an operation before being closed. For an unlimited wait, use '0' as value.
        Returns:
        The time for an idle IO connection to wait for an operation before being closed.
      • getMaxQueued

        public int getMaxQueued()
        Deprecated.
        Returns the maximum number of calls that can be queued if there aren't any worker thread available to service them. If the value is '0', then no queue is used and calls are rejected if no worker thread is immediately available. If the value is '-1', then an unbounded queue is used and calls are never rejected.

        Note: make sure that this value is consistent with getMinThreads() and the behavior of the ThreadPoolExecutor configured internally.
        Returns:
        The maximum number of calls that can be queued.
      • getMaxThreadIdleTimeMs

        public int getMaxThreadIdleTimeMs()
        Deprecated.
        Returns the time for an idle thread to wait for an operation before being collected.
        Returns:
        The time for an idle thread to wait for an operation before being collected.
      • getMaxThreads

        public int getMaxThreads()
        Deprecated.
        Returns the maximum threads that will service requests.
        Returns:
        The maximum threads that will service requests.
      • getMinThreads

        public int getMinThreads()
        Deprecated.
        Returns the minimum threads waiting to service requests. Technically speaking, this is a core number of threads that are pre-started.
        Returns:
        The minimum threads waiting to service requests.
      • getOutboundBufferSize

        public int getOutboundBufferSize()
        Deprecated.
        Returns the size of the content buffer for sending responses.
        Returns:
        The size of the content buffer for sending responses.
      • getOutboundMessages

        protected java.util.Queue<Response> getOutboundMessages()
        Deprecated.
        Returns the queue of outbound messages pending for handling.
        Returns:
        The queue of outbound messages.
      • getRequest

        public Request getRequest​(Response response)
        Deprecated.
        Returns the parent request of this response.
        Parameters:
        response - The response to analyze.
        Returns:
        The parent request if available.
      • getThrottleTimeMs

        public int getThrottleTimeMs()
        Deprecated.
        Returns the time to wait between socket write operations in milliseconds. Can prevent TCP buffer overflows.
        Returns:
        The time to wait between socket write operations in milliseconds.
      • getTraceStream

        public java.io.OutputStream getTraceStream()
        Deprecated.
        Returns the trace output stream to use if tracing is enabled.
        Returns:
        The trace output stream to use if tracing is enabled.
      • getTransport

        public java.lang.String getTransport()
        Deprecated.
        Returns the transport protocol.
        Returns:
        The transport protocol.
      • getWorkerService

        public java.util.concurrent.ThreadPoolExecutor getWorkerService()
        Deprecated.
        Returns the connection handler service.
        Returns:
        The connection handler service.
      • handleInbound

        protected abstract void handleInbound​(Response response)
        Deprecated.
        Handle the given inbound message.
        Parameters:
        response - The message to handle.
      • handleInbound

        protected void handleInbound​(Response response,
                                     boolean synchronous)
        Deprecated.
        Handle the given inbound message.
        Parameters:
        response - The message to handle.
        synchronous - True if the current thread should be used.
      • handleOutbound

        protected abstract void handleOutbound​(Response response)
        Deprecated.
        Handle the given outbound message.
        Parameters:
        response - The message to handle.
      • handleOutbound

        protected void handleOutbound​(Response response,
                                      boolean synchronous)
        Deprecated.
        Handle the given outbound message.
        Parameters:
        response - The message to handle.
        synchronous - True if the current thread should be used.
      • hasWorkerThreads

        public boolean hasWorkerThreads()
        Deprecated.
        Indicates if the worker service (pool of worker threads) is enabled.
        Returns:
        True if the worker service (pool of worker threads) is enabled.
      • isClientSide

        public boolean isClientSide()
        Deprecated.
        Indicates if it is helping a client connector.
        Returns:
        True if it is helping a client connector.
      • isControllerDaemon

        public abstract boolean isControllerDaemon()
        Deprecated.
        Indicates if the controller thread should be a daemon (not blocking JVM exit).
        Returns:
        True if the controller thread should be a daemon (not blocking JVM exit).
      • isDirectBuffers

        public boolean isDirectBuffers()
        Deprecated.
        Indicates if direct NIO buffers should be used. Note that tracing must be disabled to use direct buffers.
        Returns:
        True if direct NIO buffers should be used.
      • isServerSide

        public boolean isServerSide()
        Deprecated.
        Indicates if it is helping a server connector.
        Returns:
        True if it is helping a server connector.
      • isTracing

        public boolean isTracing()
        Deprecated.
        Indicates if console tracing is enabled.
        Returns:
        True if console tracing is enabled.
      • isWorkerServiceOverloaded

        public boolean isWorkerServiceOverloaded()
        Deprecated.
        Indicates if the worker service is busy. This state is detected by checking if the number of active task running is superior or equal to the maximum pool size.
        Returns:
        True if the worker service is busy.
      • onInboundError

        public void onInboundError​(Status status,
                                   Response message)
        Deprecated.
        Called on error. Unblocks the message.
        Parameters:
        status - The error status to set on the responses.
        message - The message to unblock.
      • onOutboundError

        public void onOutboundError​(Status status,
                                    Response message)
        Deprecated.
        Called on error. Unblocks the message.
        Parameters:
        status - The error status to set on the responses.
        message - The message to unblock.
      • start

        public void start()
                   throws java.lang.Exception
        Deprecated.
        Description copied from class: RestletHelper
        Start callback.
        Overrides:
        start in class ConnectorHelper<T extends Connector>
        Throws:
        java.lang.Exception
      • stop

        public void stop()
                  throws java.lang.Exception
        Deprecated.
        Description copied from class: RestletHelper
        Stop callback.
        Overrides:
        stop in class ConnectorHelper<T extends Connector>
        Throws:
        java.lang.Exception
      • traceWorkerService

        public void traceWorkerService()
        Deprecated.
        Adds traces on the worker service.