org.restlet.engine.http.connector
Class BaseHelper<T extends Connector>

java.lang.Object
  extended by org.restlet.engine.Helper
      extended by org.restlet.engine.RestletHelper<T>
          extended by org.restlet.engine.ConnectorHelper<T>
              extended by org.restlet.engine.http.connector.BaseHelper<T>
Direct Known Subclasses:
BaseClientHelper, BaseServerHelper

public abstract class BaseHelper<T extends Connector>
extends ConnectorHelper<T>

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 Indicates if the controller thread should be a daemon (not blocking JVM exit).
controllerSleepTimeMs int 100 Time for the controller thread to sleep between each control.
inboundBufferSize int IoUtils.BUFFER_SIZE The size of the buffer when reading messages.
minThreads int 1 Minimum threads waiting to service requests.
maxThreads int 10 Maximum threads that will service requests.
maxConnectionsPerHost int -1 Maximum number of concurrent connections per host (IP address).
maxTotalConnections int -1 Maximum number of concurrent connections in total.
outboundBufferSize int IoUtils.BUFFER_SIZE The size of the buffer when writing messages.
persistingConnections boolean true Indicates if connections should be kept alive after a call.
pipeliningConnections boolean false Indicates if pipelining connections are supported.
threadMaxIdleTimeMs int 60000 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.

Author:
Jerome Louvel

Constructor Summary
BaseHelper(T connector, boolean clientSide)
          Constructor.
 
Method Summary
protected abstract  Connection<T> createConnection(BaseHelper<T> helper, Socket socket, SocketChannel socketChannel)
          Creates a connection associated to the given socket.
protected  Controller createController()
          Creates a new controller.
protected  ExecutorService createControllerService()
          Creates the connector controller service.
protected  Response createResponse(Request request)
          Creates the response object.
protected  ThreadPoolExecutor createWorkerService()
          Creates the handler service.
protected  Set<Connection<T>> getConnections()
          Returns the set of active connections.
 Controller getController()
          Returns the controller task.
 int getControllerSleepTimeMs()
          Returns the time for the controller thread to sleep between each control.
 int getInboundBufferSize()
          Returns the size of the buffer when reading messages..
protected  Queue<Response> getInboundMessages()
          Returns the queue of inbound messages pending for handling.
 int getMaxConnectionsPerHost()
          Returns the maximum concurrent connections per host (IP address).
 int getMaxThreads()
          Returns the maximum threads that will service requests.
 int getMaxTotalConnections()
          Returns the maximum number of concurrent connections allowed.
 int getMinThreads()
          Returns the minimum threads waiting to service requests.
 int getOutboundBufferSize()
          Returns the size of the buffer when writing messages..
protected  Queue<Response> getOutboundMessages()
          Returns the queue of outbound messages pending for handling.
 int getThreadMaxIdleTimeMs()
          Returns the time for an idle thread to wait for an operation before being collected.
 ThreadPoolExecutor getWorkerService()
          Returns the connection handler service.
abstract  void handleInbound(Response response)
          Handles an inbound message.
 void handleNextInbound()
          Handles the next inbound message.
protected  void handleNextOutbound()
          Handles the next outbound message.
abstract  void handleOutbound(Response response)
          Handles an outbound message.
 boolean isClientSide()
          Indicates if it is helping a client connector.
 boolean isControllerDaemon()
          Indicates if the controller thread should be a daemon (not blocking JVM exit).
 boolean isPersistingConnections()
          Indicates if persistent connections should be used if possible.
 boolean isPipeliningConnections()
          Indicates if pipelining connections are supported.
abstract  boolean isProxying()
          Indicates if the helper is going through a client proxy or is a server proxy.
 boolean isServerSide()
          Indicates if it is helping a server connector.
 boolean isTracing()
          Indicates if console tracing is enabled.
protected  boolean isWorkerServiceFull()
          Indicates if the worker service is busy.
 void start()
          Start callback.
 void stop()
          Stop callback.
 
Methods inherited from class org.restlet.engine.ConnectorHelper
getConnectorService, getContext, getProtocols, update
 
Methods inherited from class org.restlet.engine.RestletHelper
getAttributes, getHelped, getHelpedParameters, getLogger, getMetadataService, handle, setHelped
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseHelper

public BaseHelper(T connector,
                  boolean clientSide)
Constructor.

Parameters:
connector - The helped connector.
clientSide - True if it is helping a client connector.
Method Detail

createConnection

protected abstract Connection<T> createConnection(BaseHelper<T> helper,
                                                  Socket socket,
                                                  SocketChannel socketChannel)
                                                             throws IOException
Creates a connection associated to the given socket.

Parameters:
helper - The parent helper.
socket - The underlying BIO socket.
socketChannel - The underlying NIO socket channel.
Returns:
The new connection.
Throws:
IOException

createController

protected Controller createController()
Creates a new controller.

Returns:
A new controller.

createControllerService

protected ExecutorService createControllerService()
Creates the connector controller service.

Returns:
The connector controller service.

createResponse

protected Response createResponse(Request request)
Creates the response object.

Parameters:
request - The associated request.
Returns:
The response object.

createWorkerService

protected ThreadPoolExecutor createWorkerService()
Creates the handler service.

Returns:
The handler service.

getConnections

protected Set<Connection<T>> getConnections()
Returns the set of active connections.

Returns:
The set of active connections.

getController

public Controller getController()
Returns the controller task.

Returns:
The controller task.

getControllerSleepTimeMs

public int getControllerSleepTimeMs()
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()
Returns the size of the buffer when reading messages..

Returns:
The size of the buffer when reading messages..

getInboundMessages

protected Queue<Response> getInboundMessages()
Returns the queue of inbound messages pending for handling.

Returns:
The queue of inbound messages.

getMaxConnectionsPerHost

public int getMaxConnectionsPerHost()
Returns the maximum concurrent connections per host (IP address). By default, it is unbounded.

Returns:
Maximum number of concurrent connections per host (IP address).

getMaxThreads

public int getMaxThreads()
Returns the maximum threads that will service requests.

Returns:
The maximum threads that will service requests.

getMaxTotalConnections

public int getMaxTotalConnections()
Returns the maximum number of concurrent connections allowed. By default, it is unbounded.

Returns:
The maximum number of concurrent connections allowed.

getMinThreads

public int getMinThreads()
Returns the minimum threads waiting to service requests.

Returns:
The minimum threads waiting to service requests.

getOutboundBufferSize

public int getOutboundBufferSize()
Returns the size of the buffer when writing messages..

Returns:
The size of the buffer when writing messages..

getOutboundMessages

protected Queue<Response> getOutboundMessages()
Returns the queue of outbound messages pending for handling.

Returns:
The queue of outbound messages.

getThreadMaxIdleTimeMs

public int getThreadMaxIdleTimeMs()
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.

getWorkerService

public ThreadPoolExecutor getWorkerService()
Returns the connection handler service.

Returns:
The connection handler service.

handleInbound

public abstract void handleInbound(Response response)
Handles an inbound message.

Parameters:
response - The response to handle.

handleNextInbound

public void handleNextInbound()
Handles the next inbound message.


handleNextOutbound

protected void handleNextOutbound()
Handles the next outbound message.


handleOutbound

public abstract void handleOutbound(Response response)
Handles an outbound message.

Parameters:
response - The response to handle.

isClientSide

public boolean isClientSide()
Indicates if it is helping a client connector.

Returns:
True if it is helping a client connector.

isControllerDaemon

public boolean isControllerDaemon()
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).

isPersistingConnections

public boolean isPersistingConnections()
Indicates if persistent connections should be used if possible.

Returns:
True if persistent connections should be used if possible.

isPipeliningConnections

public boolean isPipeliningConnections()
Indicates if pipelining connections are supported.

Returns:
True if pipelining connections are supported.

isProxying

public abstract boolean isProxying()
Indicates if the helper is going through a client proxy or is a server proxy.

Returns:
True if the helper is going through a client proxy or is a server proxy.

isServerSide

public boolean isServerSide()
Indicates if it is helping a server connector.

Returns:
True if it is helping a server connector.

isTracing

public boolean isTracing()
Indicates if console tracing is enabled.

Returns:
True if console tracing is enabled.

isWorkerServiceFull

protected boolean isWorkerServiceFull()
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.

start

public void start()
           throws Exception
Description copied from class: RestletHelper
Start callback.

Overrides:
start in class ConnectorHelper<T extends Connector>
Throws:
Exception

stop

public void stop()
          throws Exception
Description copied from class: RestletHelper
Stop callback.

Overrides:
stop in class ConnectorHelper<T extends Connector>
Throws:
Exception


Copyright © 2005-2011 Noelios Technologies.