2.17.2: 2011-06-17

net.sf.basedb.clients.jobagent.handlers
Class MultiProtocolRequestHandler

java.lang.Object
  extended by net.sf.basedb.clients.jobagent.handlers.MultiProtocolRequestHandler
All Implemented Interfaces:
RequestHandler

public class MultiProtocolRequestHandler
extends Object
implements RequestHandler

Request handler implementation that forwards all requests to a registered protocol-specific handler. All unknown protocols are forwarded to a default request handler. Protocols and their handlers are registered with . An incoming request should be of the form: protocol://additional-info. Requests for protocols that doesn't have a registered handler and requests that doesn't follow the above form are forwarded to the default handler.

Since:
2.16
Author:
Nicklas
Last modified
$Date: 2010-10-19 13:02:17 +0200 (Tue, 19 Oct 2010) $

Field Summary
private  Agent agent
           
private  RequestHandler defaultHandler
           
private  Map<String,RequestHandler> handlers
           
private  boolean isClosed
           
private static Logger log
          Logger.
 
Constructor Summary
MultiProtocolRequestHandler(Agent agent, RequestHandler defaultHandler)
          Create a new multi-protocol request handler.
 
Method Summary
 void close()
          Close this handler.
 String handleCmd(Socket socket, String cmd)
          Handle a command that was sent by an incoming request.
 boolean isClosed()
          If the request handler is closed, it will igore all method calls.
 void registerProtocols(RequestHandler handler, String... protocols)
          Register a handler for one or more protocols.
 void unregisterProtocols(String... protocols)
          Unregister a handler for one or more protocols.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final Logger log
Logger.


agent

private final Agent agent

defaultHandler

private final RequestHandler defaultHandler

handlers

private final Map<String,RequestHandler> handlers

isClosed

private boolean isClosed
Constructor Detail

MultiProtocolRequestHandler

public MultiProtocolRequestHandler(Agent agent,
                                   RequestHandler defaultHandler)
Create a new multi-protocol request handler.

Parameters:
defaultHandler - The default handler that should receive all requests that hasn't a registered specific handler
Method Detail

handleCmd

public String handleCmd(Socket socket,
                        String cmd)
Description copied from interface: RequestHandler
Handle a command that was sent by an incoming request.

Specified by:
handleCmd in interface RequestHandler
Parameters:
socket - The socket that is handling the communication with the remote client
cmd - The command
Returns:
The answer

registerProtocols

public void registerProtocols(RequestHandler handler,
                              String... protocols)
Register a handler for one or more protocols. Ignored if this request handler has been closed.

Parameters:
handler - The handler
protocols - An array with protocol names

unregisterProtocols

public void unregisterProtocols(String... protocols)
Unregister a handler for one or more protocols. Ignored if this request handler has been closed.

Parameters:
protocols - An array with protocol names
Since:
2.16

close

public void close()
Close this handler. It can't be used again.


isClosed

public boolean isClosed()
If the request handler is closed, it will igore all method calls.


2.17.2: 2011-06-17