Interface JsonRpcServiceWrapper

All Superinterfaces:
JsonRpcService
All Known Implementing Classes:
AbstractJsonRpcService, DelegatingJsonRpcService, EchoJsonRpcService, MathService, WalletAppKitJsonRpcService

public interface JsonRpcServiceWrapper extends JsonRpcService
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 paramsfrom 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 CompletableFutures 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:

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 Details

    • log

      static final org.slf4j.Logger log
  • Method Details

    • getServiceObject

      Get the service object.

      Implementations will return their configured service object here.

      Returns:
      the service object
    • getMethod

      Method getMethod(String methodName)
      Get a Method 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 interface JsonRpcService
      Type Parameters:
      RSLT - Generic type for the JSON-RPC result in JsonRpcResponse.getResult()
      Parameters:
      req - The Request POJO
      Returns:
      A future JSON RPC Response
    • reflect

      static Map<String,Method> reflect(Class<?> apiClass)
      Use reflection/introspection to generate a map of methods. Generally this is called to initialize a Map 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