org.restlet.engine.connector
Class ClientConnectionHelper

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<Client>
                      extended by org.restlet.engine.connector.ClientConnectionHelper
Direct Known Subclasses:
HttpClientHelper

public abstract class ClientConnectionHelper
extends ConnectionHelper<Client>

Base client helper based on NIO non blocking sockets. Here is the list of parameters that are supported. They should be set in the Client's context before it is started:

Parameter name Value type Default value Description
proxyHost String System property "http.proxyHost" The host name of the HTTP proxy.
proxyPort int System property "http.proxyPort" The port of the HTTP proxy.
socketConnectTimeoutMs int 0 The socket connection timeout or 0 for unlimited wait.

Author:
Jerome Louvel

Field Summary
protected static String CONNECTOR_LATCH
           
 
Fields inherited from class org.restlet.engine.connector.BaseHelper
clientSide, controller, inboundMessages, outboundMessages
 
Constructor Summary
ClientConnectionHelper(Client connector)
          Constructor.
 
Method Summary
protected  Connection<Client> createConnection(SocketChannel socketChannel, ConnectionController controller, InetSocketAddress socketAddress)
          Creates a connection associated to the given socket.
protected  ConnectionController createController()
          Creates a new controller.
protected  SocketChannel createSocketChannel(boolean secure, InetSocketAddress socketAddress)
          Creates the socket that will be used to send the request and get the response.
protected  SocketChannel createSocketChannel(boolean secure, String hostDomain, int hostPort)
          Creates the socket channel that will be used to send the request and get the response.
 void doHandleInbound(Response response)
          Effectively handles an inbound message.
 void doHandleOutbound(Response response)
          Effectively handles an outbound message.
protected  Connection<Client> getBestConnection(Request request)
          Tries to reuse an existing connection for the given request, or creates a new one.
 String getProxyHost()
          Returns the host name of the HTTP proxy, if specified.
 int getProxyPort()
          Returns the port of the HTTP proxy, if specified, 3128 otherwise.
protected  InetSocketAddress getSocketAddress(Request request)
          Returns an IP socket address representing the target host domain and port for a given request.
 int getSocketConnectTimeoutMs()
          Returns the socket connection timeout.
 void handle(Request request, Response response)
          Handles a call.
protected  void handleInbound(Response response)
          Handle the given inbound message.
protected  void handleOutbound(Response response)
          Handle the given outbound message.
 boolean isControllerDaemon()
          Indicates if the controller thread should be a daemon (not blocking JVM exit).
 boolean isProxying()
          Indicates if the helper is going through a client proxy or is a server proxy.
 void start()
          Start callback.
 void stop()
          Stop callback.
protected  void unblock(Response response)
          Unblocks the thread that handles the given request/response pair.
 
Methods inherited from class org.restlet.engine.connector.ConnectionHelper
addOutboundMessage, checkin, checkout, configure, createConnectionPool, createInboundWay, createOutboundWay, doFinishStop, doGracefulStop, getConnectionPool, getConnections, getInitialConnections, getMaxConnectionsPerHost, getMaxTotalConnections, getSocketLingerTimeMs, getSocketReceiveBufferSize, getSocketSendBufferSize, getSocketTrafficClass, isPersistingConnections, isPipeliningConnections, isPooledConnection, isSocketKeepAlive, isSocketNoDelay, isSocketOobInline, isSocketReuseAddress
 
Methods inherited from class org.restlet.engine.connector.BaseHelper
control, createControllerService, createRequest, createWorkerService, execute, getController, getControllerSleepTimeMs, getInboundBufferSize, getInboundMessages, getLowThreads, getMaxIoIdleTimeMs, getMaxQueued, getMaxThreadIdleTimeMs, getMaxThreads, getMinThreads, getOutboundBufferSize, getOutboundMessages, getRequest, getThrottleTimeMs, getTraceStream, getTransport, getWorkerService, handleInbound, handleOutbound, hasWorkerThreads, isClientSide, isDirectBuffers, isServerSide, isTracing, isWorkerServiceOverloaded, onInboundError, onOutboundError, 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, setHelped
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONNECTOR_LATCH

protected static final String CONNECTOR_LATCH
See Also:
Constant Field Values
Constructor Detail

ClientConnectionHelper

public ClientConnectionHelper(Client connector)
Constructor.

Parameters:
connector - The helped client connector.
Method Detail

createConnection

protected Connection<Client> createConnection(SocketChannel socketChannel,
                                              ConnectionController controller,
                                              InetSocketAddress socketAddress)
                                       throws IOException
Description copied from class: ConnectionHelper
Creates a connection associated to the given socket.

Specified by:
createConnection in class ConnectionHelper<Client>
Parameters:
socketChannel - The underlying NIO socket channel.
controller - The underlying IO controller.
socketAddress - The associated IP address.
Returns:
The new connection.
Throws:
IOException

createController

protected ConnectionController createController()
Description copied from class: BaseHelper
Creates a new controller.

Specified by:
createController in class BaseHelper<Client>
Returns:
A new controller.

createSocketChannel

protected SocketChannel createSocketChannel(boolean secure,
                                            InetSocketAddress socketAddress)
                                     throws UnknownHostException,
                                            IOException
Creates the socket that will be used to send the request and get the response. This method is called by getBestConnection(Request) when a new connection is to be created. By default, calls the createSocketChannel(boolean, String, int) method.

Parameters:
secure - Indicates if messages will be exchanged confidentially, for example via a SSL-secured connection.
socketAddress - The holder of a host/port pair.
Returns:
The created socket.
Throws:
UnknownHostException
IOException

createSocketChannel

protected SocketChannel createSocketChannel(boolean secure,
                                            String hostDomain,
                                            int hostPort)
                                     throws UnknownHostException,
                                            IOException
Creates the socket channel that will be used to send the request and get the response.

Parameters:
secure - Indicates if messages will be exchanged confidentially, for example via a SSL-secured connection.
hostDomain - The target host domain name.
hostPort - The target host port.
Returns:
The created socket channel.
Throws:
UnknownHostException
IOException

doHandleInbound

public void doHandleInbound(Response response)
Description copied from class: BaseHelper
Effectively handles an inbound message.

Specified by:
doHandleInbound in class BaseHelper<Client>
Parameters:
response - The response to handle.

doHandleOutbound

public void doHandleOutbound(Response response)
Description copied from class: BaseHelper
Effectively handles an outbound message.

Specified by:
doHandleOutbound in class BaseHelper<Client>
Parameters:
response - The response to handle.

getBestConnection

protected Connection<Client> getBestConnection(Request request)
                                        throws UnknownHostException,
                                               IOException
Tries to reuse an existing connection for the given request, or creates a new one. It may return null if the maximum number of connections per host or in general is reached.

Parameters:
request - The request to handle.
Returns:
An existing connection able to handle the request or new one.
Throws:
UnknownHostException
IOException

getProxyHost

public String getProxyHost()
Returns the host name of the HTTP proxy, if specified.

Returns:
the host name of the HTTP proxy, if specified.

getProxyPort

public int getProxyPort()
Returns the port of the HTTP proxy, if specified, 3128 otherwise.

Returns:
the port of the HTTP proxy.

getSocketAddress

protected InetSocketAddress getSocketAddress(Request request)
                                      throws UnknownHostException
Returns an IP socket address representing the target host domain and port for a given request. If the helper relies on a proxy, the socket represents the domain and port of the proxy host. Used by the getBestConnection(Request) method.

Parameters:
request - The given request
Returns:
The IP socket address representing the target host domain and port for a given request.
Throws:
UnknownHostException - If the proxy port is invalid or the host unresolved.

getSocketConnectTimeoutMs

public int getSocketConnectTimeoutMs()
Returns the socket connection timeout.

Returns:
The socket connection timeout.

handle

public void handle(Request request,
                   Response response)
Description copied from class: RestletHelper
Handles a call.

Overrides:
handle in class RestletHelper<Client>
Parameters:
request - The request to handle.
response - The response to update.

handleInbound

protected void handleInbound(Response response)
Description copied from class: BaseHelper
Handle the given inbound message.

Specified by:
handleInbound in class BaseHelper<Client>
Parameters:
response - The message to handle.

handleOutbound

protected void handleOutbound(Response response)
Description copied from class: BaseHelper
Handle the given outbound message.

Specified by:
handleOutbound in class BaseHelper<Client>
Parameters:
response - The message to handle.

isControllerDaemon

public boolean isControllerDaemon()
Description copied from class: BaseHelper
Indicates if the controller thread should be a daemon (not blocking JVM exit).

Specified by:
isControllerDaemon in class BaseHelper<Client>
Returns:
True if the controller thread should be a daemon (not blocking JVM exit).

isProxying

public boolean isProxying()
Description copied from class: ConnectionHelper
Indicates if the helper is going through a client proxy or is a server proxy.

Specified by:
isProxying in class ConnectionHelper<Client>
Returns:
True if the helper is going through a client proxy or is a server proxy.

start

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

Overrides:
start in class BaseHelper<Client>
Throws:
Exception

stop

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

Overrides:
stop in class BaseHelper<Client>
Throws:
Exception

unblock

protected void unblock(Response response)
Unblocks the thread that handles the given request/response pair.

Parameters:
response - The response.


Copyright © 2005-2013 Restlet.