Interface JsonRpcServiceWrapper
- All Superinterfaces:
JsonRpcService
- All Known Implementing Classes:
AbstractJsonRpcService
,DelegatingJsonRpcService
,EchoJsonRpcService
,MathService
,WalletAppKitJsonRpcService
Interface and default methods for wrapping a Java class with JSON-RPC support. The wrapper is responsible for
extracting the JSON-RPC
method
name and params
from the request, calling the appropriate method
in the wrapped object and wrapping the result
in a JsonRpcResponse
.
The wrapped class must contain one or more asynchronous methods that return CompletableFuture
s for objects that represent
JSON-RPC result
values. They are mapped to JSON objects when serialized (via Jackson in the current implementation.)
This interface contains a default
implementation of JsonRpcService.call(JsonRpcRequest)
that
uses callMethod(String, List)
to call the wrapped service object.
Implementations must implement:
getServiceObject()
to return the wrapped object (singleton)getMethod(String)
to return aMethod
object for the named JSON-RPCmethod
.
The trick to GraalVM-compatibility is to use the static
reflect(Class)
method in your
implementation at (static) initialization time so the reflection is done at GraalVM compile-time.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptiondefault <RSLT> CompletableFuture
<JsonRpcResponse<RSLT>> call
(JsonRpcRequest req) Handle a request by calling method, getting a result, and embedding it in a response.Get aMethod
object for a named JSON-RPC methodGet the service object.Use reflection/introspection to generate a map of methods.
-
Field Details
-
log
-
-
Method Details
-
getServiceObject
Get the service object.Implementations will return their configured service object here.
- Returns:
- the service object
-
getMethod
Get aMethod
object for a named JSON-RPC method- Parameters:
methodName
- the name of the method to call- Returns:
- method handle
-
call
Handle a request by calling method, getting a result, and embedding it in a response.- Specified by:
call
in interfaceJsonRpcService
- Type Parameters:
RSLT
- Generic type for the JSON-RPC result inJsonRpcResponse.getResult()
- Parameters:
req
- The Request POJO- Returns:
- A future JSON RPC Response
-
reflect
Use reflection/introspection to generate a map of methods. Generally this is called to initialize aMap
stored in a static field, so the reflection can be done during GraalVM compile-time..- Parameters:
apiClass
- The service class to reflect/introspect- Returns:
- a map of method names to method objects
-