public class MultiProtocolRequestHandler extends Object implements RequestHandler
registerProtocols(RequestHandler, String[])
.
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.Modifier and Type | Field and Description |
---|---|
private Agent |
agent |
private RequestHandler |
defaultHandler |
private Map<String,RequestHandler> |
handlers |
private boolean |
isClosed |
private static org.slf4j.Logger |
log
Logger.
|
Constructor and Description |
---|
MultiProtocolRequestHandler(Agent agent,
RequestHandler defaultHandler)
Create a new multi-protocol request handler.
|
Modifier and Type | Method and Description |
---|---|
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.
|
private static final org.slf4j.Logger log
private final Agent agent
private final RequestHandler defaultHandler
private final Map<String,RequestHandler> handlers
private boolean isClosed
public MultiProtocolRequestHandler(Agent agent, RequestHandler defaultHandler)
defaultHandler
- The default handler that should
receive all requests that hasn't a registered specific
handlerpublic String handleCmd(Socket socket, String cmd)
RequestHandler
handleCmd
in interface RequestHandler
socket
- The socket that is handling the communication with the
remote clientcmd
- The commandpublic void registerProtocols(RequestHandler handler, String... protocols)
handler
- The handlerprotocols
- An array with protocol namespublic void unregisterProtocols(String... protocols)
protocols
- An array with protocol namespublic void close()
public boolean isClosed()