Class Dispatcher
java.lang.Object
com.thetransactioncompany.jsonrpc2.server.Dispatcher
- All Implemented Interfaces:
NotificationHandler,RequestHandler
Dispatcher for JSON-RPC 2.0 requests and notifications. This class is
tread-safe.
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.
- Author:
- Vladimir Dzhuvinov
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddispatch(JSONRPC2Notification notification, MessageContext notificationCtx) Deprecated.dispatch(JSONRPC2Request request, MessageContext requestCtx) Deprecated.getNotificationHandler(String notificationName) Gets the handler for the specified JSON-RPC 2.0 notification name.getRequestHandler(String requestName) Gets the handler for the specified JSON-RPC 2.0 request name.String[]Gets the names of the handled JSON-RPC 2.0 notification methods.String[]Gets the names of the handled JSON-RPC 2.0 request methods.voidprocess(JSONRPC2Notification notification, MessageContext notificationCtx) Processes a JSON-RPC 2.0 notification.process(JSONRPC2Request request, MessageContext requestCtx) Processes a JSON-RPC 2.0 request.voidregister(NotificationHandler handler) Registers a new JSON-RPC 2.0 notification handler.voidregister(RequestHandler handler) Registers a new JSON-RPC 2.0 request handler.voidreportProcTime(boolean enable) Controls reporting of request processing time by appending a non-standard "xProcTime" attribute to the JSON-RPC 2.0 response.booleanReturnstrueif reporting of request processing time is enabled.
-
Constructor Details
-
Dispatcher
public Dispatcher()Creates a new dispatcher with no registered handlers.
-
-
Method Details
-
register
Registers a new JSON-RPC 2.0 request handler.- Parameters:
handler- The request handler to register. Must not benull.- Throws:
IllegalArgumentException- On attempting to register a handler that duplicates an existing request name.
-
register
Registers a new JSON-RPC 2.0 notification handler.- Parameters:
handler- The notification handler to register. Must not benull.- Throws:
IllegalArgumentException- On attempting to register a handler that duplicates an existing notification name.
-
handledRequests
Description copied from interface:RequestHandlerGets the names of the handled JSON-RPC 2.0 request methods.- Specified by:
handledRequestsin interfaceRequestHandler- Returns:
- The names of the handled JSON-RPC 2.0 request methods.
-
handledNotifications
Description copied from interface:NotificationHandlerGets the names of the handled JSON-RPC 2.0 notification methods.- Specified by:
handledNotificationsin interfaceNotificationHandler- Returns:
- The names of the handled JSON-RPC 2.0 notification methods.
-
getRequestHandler
Gets the handler for the specified JSON-RPC 2.0 request name.- Parameters:
requestName- The request name to lookup.- Returns:
- The corresponding request handler or
nullif none was found.
-
getNotificationHandler
Gets the handler for the specified JSON-RPC 2.0 notification name.- Parameters:
notificationName- The notification name to lookup.- Returns:
- The corresponding notification handler or
nullif none was found.
-
dispatch
Deprecated. -
process
Description copied from interface:RequestHandlerProcesses a JSON-RPC 2.0 request.- Specified by:
processin interfaceRequestHandler- Parameters:
request- A valid JSON-RPC 2.0 request instance. Must not benull.requestCtx- Context information about the request message, may benullif undefined.- Returns:
- The resulting JSON-RPC 2.0 response. It indicates success or an error, such as METHOD_NOT_FOUND.
-
dispatch
Deprecated. -
process
Description copied from interface:NotificationHandlerProcesses a JSON-RPC 2.0 notification.Note that JSON-RPC 2.0 notifications don't produce a response!
- Specified by:
processin interfaceNotificationHandler- Parameters:
notification- A valid JSON-RPC 2.0 notification instance. Must not benull.notificationCtx- Context information about the notification message, may benullif undefined.
-
reportProcTime
public void reportProcTime(boolean enable) Controls reporting of request processing time by appending a non-standard "xProcTime" attribute to the JSON-RPC 2.0 response. Reporting is disabled by default.- Parameters:
enable-trueto enable proccessing time reporting,falseto disable it.
-
reportsProcTime
public boolean reportsProcTime()Returnstrueif reporting of request processing time is enabled. See thereportProcTimedescription for more information.- Returns:
trueif reporting of request processing time is enabled, elsefalse.
-