Class AbstractRpcSingleClient<S>

java.lang.Object
org.knime.core.webui.data.rpc.AbstractRpcClient
org.knime.core.webui.data.rpc.AbstractRpcSingleClient<S>
Type Parameters:
S - the node model's service interface that defines the methods that can be used by the dialog/view to obtain data from it
All Implemented Interfaces:
RpcClient, RpcSingleClient<S>
Direct Known Subclasses:
JsonRpcSingleClient

public abstract class AbstractRpcSingleClient<S> extends AbstractRpcClient implements RpcSingleClient<S>
Base class for node data service client implementations that support only one service interface, such as JsonRpcSingleClient.
Since:
4.3
Author:
Martin Horn, KNIME GmbH, Konstanz, Germany, Carl Witt, KNIME AG, Zurich, Switzerland
  • Constructor Details

    • AbstractRpcSingleClient

      public AbstractRpcSingleClient(Class<S> serviceInterface)
      Parameters:
      serviceInterface - the data retrieval interface offered to the node dialog/view by the node model. This interface is defined and implemented by the node developer.
    • AbstractRpcSingleClient

      protected AbstractRpcSingleClient(Class<S> serviceInterface, RpcTransport rpcTransport)
      For testing only: Constructor to initialize an rpc client with custom transport.
      Parameters:
      serviceInterface -
      rpcTransport - a custom rpc transport implementation for testing
  • Method Details

    • convertCall

      protected String convertCall(String serviceName, Method method, Object[] args)
      Description copied from class: AbstractRpcClient
      Converts a call to the node model's data service interface to String.
      For instance, method countChars("abc", 'b') on a service interface could be represented in JSON-RPC as {"jsonrpc": "2.0", "method": "countChars", "params": ["abc", "b"], "id": 3}
      Specified by:
      convertCall in class AbstractRpcClient
      Parameters:
      serviceName - the name of the service to be called
      method - name of the method to call, as provided by the interface this client is generically typed to
      args - method parameters for the invocation
      Returns:
      the representation of the method call
    • convertCall

      protected abstract String convertCall(Method method, Object[] args)
      Parameters:
      method -
      args -
      Returns:
      the call as string
    • callServiceWithRes

      public <R> Future<R> callServiceWithRes(Function<S,R> serviceEvaluator)
      Used to call a method on the node model's data service interface and retrieve the result. Example usage:
       RpcClient m_rpcClient = ...
       Future<List<SomeType>> future =
            m_rpcClient.callServiceWithRes(nodeDataService -> nodeDataService.getSomeData(someParameter));
       try {
           List<SomeType> results = future.get(3, TimeUnit.SECONDS);
       } catch (TimeoutException timeoutException) {
           ...
       
      Specified by:
      callServiceWithRes in interface RpcSingleClient<S>
      Type Parameters:
      R - the result type of the invoked method.
      Parameters:
      serviceEvaluator - the service evaluator is given an implementation of the node model's data service. It then calls one of the methods on the node model's service interface and returns the result.
      Returns:
      a Future containing the result of the invoked method.
    • callService

      public Future<Void> callService(Consumer<S> serviceConsumer)
      Similar to RpcSingleClient.callServiceWithRes(Function) but for void methods. For instance: Future<Void> future = m_rpcClient.callService(nodeDataService -> nodeDataService.sendSomeData(someData));
      Specified by:
      callService in interface RpcSingleClient<S>
      Parameters:
      serviceConsumer - used to invoke the method on the service interface
      Returns:
      an empty future
    • getService

      public S getService()
      Gives direct access to the service implementation. Please note that a call to the service might block for a while (in case the rpc request is send to the server). It is always advisable to run service calls in an extra thread to not block the ui!
      Specified by:
      getService in interface RpcSingleClient<S>
      Returns:
      the service implementation