public class Dispatcher extends Object implements RequestHandler, NotificationHandler
Use the register() methods to add a request or notification
handler for an RPC method.
Use the process() methods to have an incoming request or
notification processed by the matching handler.
The reportProcTime() method enables reporting of request
processing time (in microseconds) by appending a non-standard "xProcTime"
attribute to the resulting JSON-RPC 2.0 response message.
Example:
{
"result" : "xyz",
"id" : 1,
"jsonrpc" : "2.0",
"xProcTime" : "189 us"
}
Note: The dispatch(...) methods were deprecated in version 1.7. Use process(...) instead.
| Constructor and Description |
|---|
Dispatcher()
Creates a new dispatcher with no registered handlers.
|
| Modifier and Type | Method and Description |
|---|---|
NotificationHandler |
getNotificationHandler(String notificationName)
Gets the handler for the specified JSON-RPC 2.0 notification name.
|
RequestHandler |
getRequestHandler(String requestName)
Gets the handler for the specified JSON-RPC 2.0 request name.
|
String[] |
handledNotifications()
Gets the names of the handled JSON-RPC 2.0 notification methods.
|
String[] |
handledRequests()
Gets the names of the handled JSON-RPC 2.0 request methods.
|
void |
process(JSONRPC2Notification notification,
MessageContext notificationCtx)
Processes a JSON-RPC 2.0 notification.
|
JSONRPC2Response |
process(JSONRPC2Request request,
MessageContext requestCtx)
Processes a JSON-RPC 2.0 request.
|
void |
register(NotificationHandler handler)
Registers a new JSON-RPC 2.0 notification handler.
|
void |
register(RequestHandler handler)
Registers a new JSON-RPC 2.0 request handler.
|
void |
reportProcTime(boolean enable)
Controls reporting of request processing time by appending a
non-standard "xProcTime" attribute to the JSON-RPC 2.0 response.
|
boolean |
reportsProcTime()
Returns
true if reporting of request processing time is
enabled. |
public Dispatcher()
public NotificationHandler getNotificationHandler(String notificationName)
notificationName - The notification name to lookup.null if none was found.public RequestHandler getRequestHandler(String requestName)
requestName - The request name to lookup.null if none was found.public String[] handledNotifications()
NotificationHandlerhandledNotifications in interface NotificationHandlerpublic String[] handledRequests()
RequestHandlerhandledRequests in interface RequestHandlerpublic void process(JSONRPC2Notification notification, MessageContext notificationCtx)
NotificationHandlerNote that JSON-RPC 2.0 notifications don't produce a response!
process in interface NotificationHandlernotification - A valid JSON-RPC 2.0 notification instance.
Must not be null.notificationCtx - Context information about the notification
message, may be null if undefined.public JSONRPC2Response process(JSONRPC2Request request, MessageContext requestCtx)
RequestHandlerprocess in interface RequestHandlerrequest - A valid JSON-RPC 2.0 request instance. Must not be
null.requestCtx - Context information about the request message, may
be null if undefined.public void register(NotificationHandler handler)
handler - The notification handler to register. Must not be null.IllegalArgumentException - On attempting to register a handler that
duplicates an existing notification name.public void register(RequestHandler handler)
handler - The request handler to register. Must not be null.IllegalArgumentException - On attempting to register a handler that
duplicates an existing request name.public void reportProcTime(boolean enable)
enable - true to enable proccessing time reporting,
false to disable it.public boolean reportsProcTime()
true if reporting of request processing time is
enabled. See the reportProcTime description for more
information.true if reporting of request processing time is
enabled, else false.