org.restlet.engine.http.connector

## Class BaseHelper<T extends Connector>

- java.lang.Object
- - org.restlet.engine.Helper
  - - org.restlet.engine.RestletHelper<T>
    - - org.restlet.engine.ConnectorHelper<T>
      - - 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

Constructors
Constructor and Description
`BaseHelper(T connector, boolean clientSide)` Constructor.

### Method Summary

Methods
`protected abstract Connection<T>` `createConnection(BaseHelper<T> helper, java.net.Socket socket, java.nio.channels.SocketChannel socketChannel)` Creates a connection associated to the given socket.
`protected Controller` `createController()` Creates a new controller.
`protected java.util.concurrent.ExecutorService` `createControllerService()` Creates the connector controller service.
`protected Response` `createResponse(Request request)` Creates the response object.
`protected java.util.concurrent.ThreadPoolExecutor` `createWorkerService()` Creates the handler service.
`protected java.util.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 java.util.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 java.util.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.
`java.util.concurrent.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,
                                 java.net.Socket socket,
                                 java.nio.channels.SocketChannel socketChannel)
                                                                 throws java.io.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:
  `java.io.IOException`

#### createController

    protected Controller createController()

Creates a new controller.

Returns:
  A new controller.

#### createControllerService

    protected java.util.concurrent.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 java.util.concurrent.ThreadPoolExecutor createWorkerService()

Creates the handler service.

Returns:
  The handler service.

#### getConnections

    protected java.util.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 java.util.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 java.util.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 java.util.concurrent.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 java.lang.Exception

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

Description copied from class: `RestletHelper`
Stop callback.

Overrides:
  `stop` in class `ConnectorHelper<T extends Connector>`
Throws:
  `java.lang.Exception`