org.restlet.engine.connector
Class ConnectionHelper<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.connector.BaseHelper<T>
                  extended by org.restlet.engine.connector.ConnectionHelper<T>
Direct Known Subclasses:
ClientConnectionHelper, ServerConnectionHelper

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

Connector helper using network connections. 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
maxConnectionsPerHost int -1 Maximum number of concurrent connections per host (IP address).
initialConnections int 100 Initial number of connections pre-created in the connections pool. This saves time during establishment of new connections as heavy byte buffers are simply reused.
maxTotalConnections int -1 Maximum number of concurrent connections in total.
persistingConnections boolean true Indicates if connections should be kept alive after a call.
pipeliningConnections boolean false Indicates if pipelining connections are supported.
pooledConnections boolean true Indicates if connections should be pooled to save instantiation time.
socketKeepAlive boolean true Indicates if a TCP connection should be automatically kept alive after 2 hours of inactivity.
socketOobInline boolean false Indicates if urgent TCP data received on the socket will be received through the socket input stream.
socketLingerTimeMs int -1 Time to block when a socket close is requested or -1 to not block at all.
socketNoDelay boolean false Enables Nagle's algorithm if set to false, preventing sending of small TCP packets.
socketReceiveBufferSize int 8192 The hinted size of the underlying TCP buffers used by the platform for inbound network I/O.
socketReuseAddress boolean true Indicates if sockets can be reused right away even if they are busy (in TIME_WAIT or 2MSL wait state).
socketSendBufferSize int 8192 The hinted size of the underlying TCP buffers used by the platform for outbound network I/O.
socketTrafficClass int 0 Type of service to set in IP packets.

Author:
Jerome Louvel

Field Summary
 
Fields inherited from class org.restlet.engine.connector.BaseHelper
clientSide, controller, inboundMessages, outboundMessages
 
Constructor Summary
ConnectionHelper(T connector, boolean clientSide)
          Constructor.
 
Method Summary
 void addOutboundMessage(Response response)
          Add the outbound message to the queue and wake up the IO controller.
protected  void checkin(Connection<?> connection)
          Checks in the connection back into the pool.
protected  Connection<T> checkout(SocketChannel socketChannel, ConnectionController controller, InetSocketAddress socketAddress)
          Checks out a connection associated to the given socket from the pool.
 void configure(Socket socket)
          Configures a given socket based on the helper parameters.
protected abstract  Connection<T> createConnection(SocketChannel socketChannel, ConnectionController controller, InetSocketAddress socketAddress)
          Creates a connection associated to the given socket.
 void createConnectionPool()
          Creates the connection pool.
abstract  InboundWay createInboundWay(Connection<T> connection, int bufferSize)
          Creates an inbound way for the given connection.
abstract  OutboundWay createOutboundWay(Connection<T> connection, int bufferSize)
          Creates an outbound way for the given connection.
protected  void doFinishStop()
          Finish stopping the helper.
protected  void doGracefulStop()
          Do a graceful stop first.
 ConnectionPool<T> getConnectionPool()
          Returns the connection pool.
 List<Connection<T>> getConnections()
          Returns the set of active connections.
 int getInitialConnections()
          Returns the initial number of connections pre-created in the connections pool.
 int getMaxConnectionsPerHost()
          Returns the maximum concurrent connections per host (IP address).
 int getMaxTotalConnections()
          Returns the maximum number of concurrent connections allowed.
 int getSocketLingerTimeMs()
          Returns the time to block when a socket close is requested or -1 to not block at all.
 int getSocketReceiveBufferSize()
          Returns the hinted size of the underlying TCP buffers used by the platform for inbound network I/O.
 int getSocketSendBufferSize()
          Returns the hinted size of the underlying TCP buffers used by the platform for outbound network I/O.
 int getSocketTrafficClass()
          Returns the type of service to set in IP packets.
 boolean isPersistingConnections()
          Indicates if persistent connections should be used if possible.
 boolean isPipeliningConnections()
          Indicates if pipelining connections are supported.
 boolean isPooledConnection()
          Indicates if the connection objects should be pooled to save instantiation time.
abstract  boolean isProxying()
          Indicates if the helper is going through a client proxy or is a server proxy.
 boolean isSocketKeepAlive()
          Indicates if a TCP connection should be automatically kept alive after 2 hours of inactivity.
 boolean isSocketNoDelay()
          Enables Nagle's algorithm if set to false, preventing sending of small TCP packets.
 boolean isSocketOobInline()
          Indicates if urgent TCP data received on the socket will be received through the socket input stream.
 boolean isSocketReuseAddress()
          Indicates if sockets can be reused right away even if they are busy (in TIME_WAIT or 2MSL wait state).
 
Methods inherited from class org.restlet.engine.connector.BaseHelper
control, createController, createControllerService, createRequest, createWorkerService, doHandleInbound, doHandleOutbound, execute, getController, getControllerSleepTimeMs, getInboundBufferSize, getInboundMessages, getLowThreads, getMaxIoIdleTimeMs, getMaxQueued, getMaxThreadIdleTimeMs, getMaxThreads, getMinThreads, getOutboundBufferSize, getOutboundMessages, getRequest, getThrottleTimeMs, getTraceStream, getTransport, getWorkerService, handleInbound, handleInbound, handleOutbound, handleOutbound, hasWorkerThreads, isClientSide, isControllerDaemon, isDirectBuffers, isServerSide, isTracing, isWorkerServiceOverloaded, onInboundError, onOutboundError, start, stop, traceWorkerService
 
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

ConnectionHelper

public ConnectionHelper(T connector,
                        boolean clientSide)
Constructor.

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

addOutboundMessage

public void addOutboundMessage(Response response)
Add the outbound message to the queue and wake up the IO controller.

Parameters:
response - The outbound message.

checkin

protected void checkin(Connection<?> connection)
Checks in the connection back into the pool.

Parameters:
connection - The connection to check in.

checkout

protected Connection<T> checkout(SocketChannel socketChannel,
                                 ConnectionController controller,
                                 InetSocketAddress socketAddress)
                                            throws IOException
Checks out a connection associated to the given socket from the pool.

Parameters:
socketChannel - The underlying NIO socket channel.
controller - The underlying IO controller.
socketAddress - The associated IP address.
Returns:
The new connection.
Throws:
IOException

configure

public void configure(Socket socket)
               throws SocketException
Configures a given socket based on the helper parameters.

Parameters:
socket - The socket to configure.
Throws:
SocketException

createConnection

protected abstract Connection<T> createConnection(SocketChannel socketChannel,
                                                  ConnectionController controller,
                                                  InetSocketAddress socketAddress)
                                                             throws IOException
Creates a connection associated to the given socket.

Parameters:
socketChannel - The underlying NIO socket channel.
controller - The underlying IO controller.
socketAddress - The associated IP address.
Returns:
The new connection.
Throws:
IOException

createConnectionPool

public void createConnectionPool()
Creates the connection pool.


createInboundWay

public abstract InboundWay createInboundWay(Connection<T> connection,
                                            int bufferSize)
Creates an inbound way for the given connection.

Parameters:
connection - The parent connection.
bufferSize - The byte buffer size.
Returns:
The inbound way created.

createOutboundWay

public abstract OutboundWay createOutboundWay(Connection<T> connection,
                                              int bufferSize)
Creates an outbound way for the given connection.

Parameters:
connection - The parent connection.
bufferSize - The byte buffer size.
Returns:
The outbound way created.

doFinishStop

protected void doFinishStop()
Description copied from class: BaseHelper
Finish stopping the helper.

Overrides:
doFinishStop in class BaseHelper<T extends Connector>

doGracefulStop

protected void doGracefulStop()
Description copied from class: BaseHelper
Do a graceful stop first.

Overrides:
doGracefulStop in class BaseHelper<T extends Connector>

getConnectionPool

public ConnectionPool<T> getConnectionPool()
Returns the connection pool.

Returns:
The connection pool.

getConnections

public List<Connection<T>> getConnections()
Returns the set of active connections.

Returns:
The set of active connections.

getInitialConnections

public int getInitialConnections()
Returns the initial number of connections pre-created in the connections pool.

Returns:
The initial number of connections pre-created in the connections pool.

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).

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.

getSocketLingerTimeMs

public int getSocketLingerTimeMs()
Returns the time to block when a socket close is requested or -1 to not block at all.

Returns:
The time to block when a socket close is requested or -1 to not block at all.

getSocketReceiveBufferSize

public int getSocketReceiveBufferSize()
Returns the hinted size of the underlying TCP buffers used by the platform for inbound network I/O.

Returns:
The hinted size of the underlying TCP buffers used by the platform for inbound network I/O.

getSocketSendBufferSize

public int getSocketSendBufferSize()
Returns the hinted size of the underlying TCP buffers used by the platform for outbound network I/O.

Returns:
The hinted size of the underlying TCP buffers used by the platform for outbound network I/O.

getSocketTrafficClass

public int getSocketTrafficClass()
Returns the type of service to set in IP packets.

Returns:
The type of service to set in IP packets.

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.

isPooledConnection

public boolean isPooledConnection()
Indicates if the connection objects should be pooled to save instantiation time.

Returns:
True if the connection objects should be pooled.

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.

isSocketKeepAlive

public boolean isSocketKeepAlive()
Indicates if a TCP connection should be automatically kept alive after 2 hours of inactivity.

Returns:
True if a TCP connection should be automatically kept alive after 2 hours of inactivity.

isSocketNoDelay

public boolean isSocketNoDelay()
Enables Nagle's algorithm if set to false, preventing sending of small TCP packets.

Returns:
True if Nagle's algorithm should be disabled.

isSocketOobInline

public boolean isSocketOobInline()
Indicates if urgent TCP data received on the socket will be received through the socket input stream.

Returns:
True if urgent TCP data received on the socket will be received through the socket input stream.

isSocketReuseAddress

public boolean isSocketReuseAddress()
Indicates if sockets can be reused right away even if they are busy (in TIME_WAIT or 2MSL wait state).

Returns:
True if sockets can be reused right away even if they are busy (in TIME_WAIT or 2MSL wait state).


Copyright © 2005-2014 Restlet.