Package org.restlet.ext.nio
Class BaseHelper<T extends Connector>
- java.lang.Object
-
- org.restlet.engine.Helper
-
- org.restlet.engine.RestletHelper<T>
-
- org.restlet.engine.connector.ConnectorHelper<T>
-
- org.restlet.ext.nio.BaseHelper<T>
-
- 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 withgetMinThreads()and the behavior of theThreadPoolExecutorconfigured 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 Summary
Fields Modifier and Type Field Description protected booleanclientSideDeprecated.Indicates if it is helping a client connector.protected ConnectionControllercontrollerDeprecated.The controller task.private java.util.concurrent.ExecutorServicecontrollerServiceDeprecated.The controller service.protected java.util.Queue<Response>inboundMessagesDeprecated.The queue of inbound messages.protected java.util.Queue<Response>outboundMessagesDeprecated.The queue of outbound messages.private java.util.concurrent.ThreadPoolExecutorworkerServiceDeprecated.The worker service.
-
Constructor Summary
Constructors Constructor Description BaseHelper(T connector, boolean clientSide)Deprecated.Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancontrol()Deprecated.Controls the helper for inbound or outbound messages to handle.protected abstract ConnectionControllercreateController()Deprecated.Creates a new controller.protected java.util.concurrent.ExecutorServicecreateControllerService()Deprecated.Creates the connector controller service.protected RequestcreateRequest()Deprecated.Creates the request object.protected java.util.concurrent.ThreadPoolExecutorcreateWorkerService()Deprecated.Creates the handler service.protected voiddoFinishStop()Deprecated.Finish stopping the helper.protected voiddoGracefulStop()Deprecated.Do a graceful stop first.abstract voiddoHandleInbound(Response response)Deprecated.Effectively handles an inbound message.abstract voiddoHandleOutbound(Response response)Deprecated.Effectively handles an outbound message.protected voidexecute(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.ConnectionControllergetController()Deprecated.Returns the controller task.intgetControllerSleepTimeMs()Deprecated.Returns the time for the controller thread to sleep between each control.intgetInboundBufferSize()Deprecated.Returns the size of the content buffer for receiving messages.java.util.Queue<Response>getInboundMessages()Deprecated.Returns the queue of inbound messages pending for handling.intgetLowThreads()Deprecated.Returns the number of threads for the overload state.intgetMaxIoIdleTimeMs()Deprecated.Returns the time for an idle IO connection or request to wait for an operation before being closed.intgetMaxQueued()Deprecated.Returns the maximum number of calls that can be queued if there aren't any worker thread available to service them.intgetMaxThreadIdleTimeMs()Deprecated.Returns the time for an idle thread to wait for an operation before being collected.intgetMaxThreads()Deprecated.Returns the maximum threads that will service requests.intgetMinThreads()Deprecated.Returns the minimum threads waiting to service requests.intgetOutboundBufferSize()Deprecated.Returns the size of the content buffer for sending responses.protected java.util.Queue<Response>getOutboundMessages()Deprecated.Returns the queue of outbound messages pending for handling.RequestgetRequest(Response response)Deprecated.Returns the parent request of this response.intgetThrottleTimeMs()Deprecated.Returns the time to wait between socket write operations in milliseconds.java.io.OutputStreamgetTraceStream()Deprecated.Returns the trace output stream to use if tracing is enabled.java.lang.StringgetTransport()Deprecated.Returns the transport protocol.java.util.concurrent.ThreadPoolExecutorgetWorkerService()Deprecated.Returns the connection handler service.protected abstract voidhandleInbound(Response response)Deprecated.Handle the given inbound message.protected voidhandleInbound(Response response, boolean synchronous)Deprecated.Handle the given inbound message.protected abstract voidhandleOutbound(Response response)Deprecated.Handle the given outbound message.protected voidhandleOutbound(Response response, boolean synchronous)Deprecated.Handle the given outbound message.booleanhasWorkerThreads()Deprecated.Indicates if the worker service (pool of worker threads) is enabled.booleanisClientSide()Deprecated.Indicates if it is helping a client connector.abstract booleanisControllerDaemon()Deprecated.Indicates if the controller thread should be a daemon (not blocking JVM exit).booleanisDirectBuffers()Deprecated.Indicates if direct NIO buffers should be used.booleanisServerSide()Deprecated.Indicates if it is helping a server connector.booleanisTracing()Deprecated.Indicates if console tracing is enabled.booleanisWorkerServiceOverloaded()Deprecated.Indicates if the worker service is busy.voidonInboundError(Status status, Response message)Deprecated.Called on error.voidonOutboundError(Status status, Response message)Deprecated.Called on error.voidstart()Deprecated.Start callback.voidstop()Deprecated.Stop callback.voidtraceWorkerService()Deprecated.Adds traces on the worker service.-
Methods inherited from class org.restlet.engine.connector.ConnectorHelper
getConnectorService, getContext, getProtocols, update
-
Methods inherited from class org.restlet.engine.RestletHelper
getAttributes, getHelped, getHelpedParameters, getLogger, getMetadataService, handle, setHelped
-
-
-
-
Field Detail
-
clientSide
protected final boolean clientSide
Deprecated.Indicates if it is helping a client connector.
-
controller
protected final ConnectionController controller
Deprecated.The controller task.
-
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 withgetMinThreads()and the behavior of theThreadPoolExecutorconfigured 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.ExceptionDeprecated.Description copied from class:RestletHelperStart callback.- Overrides:
startin classConnectorHelper<T extends Connector>- Throws:
java.lang.Exception
-
stop
public void stop() throws java.lang.ExceptionDeprecated.Description copied from class:RestletHelperStop callback.- Overrides:
stopin classConnectorHelper<T extends Connector>- Throws:
java.lang.Exception
-
traceWorkerService
public void traceWorkerService()
Deprecated.Adds traces on the worker service.
-
-