org.restlet.engine.connector
Class ServerConnectionHelper

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<Server>
                      extended by org.restlet.engine.connector.ServerConnectionHelper
Direct Known Subclasses:
HttpServerHelper

public abstract class ServerConnectionHelper
extends ConnectionHelper<Server>

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

Parameter name Value type Default value Description
useForwardedForHeader boolean false Lookup the "X-Forwarded-For" header supported by popular proxies and caches and uses it to populate the Request.getClientAddresses() method result. This information is only safe for intermediary components within your local network. Other addresses could easily be changed by setting a fake header and should not be trusted for serious security checks.
reuseAddress boolean true Enable/disable the SO_REUSEADDR socket option. See java.io.ServerSocket#reuseAddress property for additional details.

Author:
Jerome Louvel

Field Summary
 
Fields inherited from class org.restlet.engine.connector.BaseHelper
clientSide, controller, inboundMessages, outboundMessages
 
Constructor Summary
ServerConnectionHelper(Server server)
          Constructor.
 
Method Summary
protected abstract  boolean canHandle(Connection<Server> connection, Response response)
          Indicates if the connection can handle the given response at this point in time.
protected  Connection<Server> createConnection(SocketChannel socketChannel, ConnectionController controller, InetSocketAddress socketAddress)
          Creates a connection associated to the given socket.
protected  ServerConnectionController createController()
          Creates a new controller.
protected abstract  Request createRequest(Connection<Server> connection, String methodName, String resourceUri, String protocol)
          Creates a new request.
protected  ServerSocketChannel createServerSocketChannel()
          Create a server socket channel and bind it to the given address
protected  SocketAddress createSocketAddress()
          Creates a socket address to listen on.
 void doHandleInbound(Response response)
          Effectively handles an inbound message.
 void doHandleOutbound(Response response)
          Effectively handles an outbound message.
 ServerConnectionController getController()
          Returns the controller task.
 ServerSocketChannel getServerSocketChannel()
          Returns the server socket channel.
 void handle(Request request, Response response)
          Handles a call by invoking the helped Server's Server.handle(Request, Response) method.
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.
 boolean isReuseAddress()
          Indicates if the controller thread should be a daemon (not blocking JVM exit).
 void setEphemeralPort(int localPort)
          Sets the ephemeral port in the attributes map if necessary.
 void setEphemeralPort(ServerSocket socket)
          Sets the ephemeral port in the attributes map if necessary.
 void start()
          Start callback.
 void stop()
          Stop callback.
 
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, 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
 

Constructor Detail

ServerConnectionHelper

public ServerConnectionHelper(Server server)
Constructor.

Parameters:
server - The server to help.
Method Detail

canHandle

protected abstract boolean canHandle(Connection<Server> connection,
                                     Response response)
                              throws IOException
Indicates if the connection can handle the given response at this point in time.

Parameters:
connection - The parent connection.
response - The response to handle.
Returns:
True if the connection can handle the given response at this point in time.
Throws:
IOException

createConnection

protected Connection<Server> 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<Server>
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 ServerConnectionController createController()
Description copied from class: BaseHelper
Creates a new controller.

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

createRequest

protected abstract Request createRequest(Connection<Server> connection,
                                         String methodName,
                                         String resourceUri,
                                         String protocol)
Creates a new request.

Parameters:
connection - The associated connection.
methodName - The method name.
resourceUri - The target resource URI.
protocol - The protocol name and version.
Returns:
The created request.

createServerSocketChannel

protected ServerSocketChannel createServerSocketChannel()
                                                 throws IOException
Create a server socket channel and bind it to the given address

Returns:
Bound server socket channel.
Throws:
IOException

createSocketAddress

protected SocketAddress createSocketAddress()
                                     throws IOException
Creates a socket address to listen on.

Returns:
The created socket address.
Throws:
IOException

doHandleInbound

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

Specified by:
doHandleInbound in class BaseHelper<Server>
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<Server>
Parameters:
response - The response to handle.

getController

public ServerConnectionController getController()
Description copied from class: BaseHelper
Returns the controller task.

Overrides:
getController in class BaseHelper<Server>
Returns:
The controller task.

getServerSocketChannel

public ServerSocketChannel getServerSocketChannel()
Returns the server socket channel.

Returns:
The server socket channel.

handle

public void handle(Request request,
                   Response response)
Handles a call by invoking the helped Server's Server.handle(Request, Response) method.

Overrides:
handle in class RestletHelper<Server>
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<Server>
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<Server>
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<Server>
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<Server>
Returns:
True if the helper is going through a client proxy or is a server proxy.

isReuseAddress

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

setEphemeralPort

public void setEphemeralPort(int localPort)
Sets the ephemeral port in the attributes map if necessary.

Parameters:
localPort - The ephemeral local port.

setEphemeralPort

public void setEphemeralPort(ServerSocket socket)
Sets the ephemeral port in the attributes map if necessary.

Parameters:
socket - The bound server socket.

start

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

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

stop

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

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


Copyright © 2005-2013 Restlet.