Package org.knime.core.webui.data.rpc
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 Summary
ConstructorsModifierConstructorDescriptionAbstractRpcSingleClient(Class<S> serviceInterface) protectedAbstractRpcSingleClient(Class<S> serviceInterface, RpcTransport rpcTransport) For testing only: Constructor to initialize an rpc client with custom transport. -
Method Summary
Modifier and TypeMethodDescriptioncallService(Consumer<S> serviceConsumer) Similar toRpcSingleClient.callServiceWithRes(Function)but for void methods.<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.protected abstract StringconvertCall(Method method, Object[] args) protected StringconvertCall(String serviceName, Method method, Object[] args) 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}Gives direct access to the service implementation.Methods inherited from class org.knime.core.webui.data.rpc.AbstractRpcClient
callService, callServiceWithRes, convertResult, getService, isConnectedRemotelyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.knime.core.webui.data.rpc.RpcClient
callService, callServiceWithRes, getService, isConnectedRemotelyMethods inherited from interface org.knime.core.webui.data.rpc.RpcSingleClient
callService, callServiceWithRes, getService
-
Constructor Details
-
AbstractRpcSingleClient
- 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
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
Description copied from class:AbstractRpcClientConverts 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:
convertCallin classAbstractRpcClient- Parameters:
serviceName- the name of the service to be calledmethod- name of the method to call, as provided by the interface this client is generically typed toargs- method parameters for the invocation- Returns:
- the representation of the method call
-
convertCall
- Parameters:
method-args-- Returns:
- the call as string
-
callServiceWithRes
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:
callServiceWithResin interfaceRpcSingleClient<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
Futurecontaining the result of the invoked method.
-
callService
Similar toRpcSingleClient.callServiceWithRes(Function)but for void methods. For instance:Future<Void> future = m_rpcClient.callService(nodeDataService -> nodeDataService.sendSomeData(someData));- Specified by:
callServicein interfaceRpcSingleClient<S>- Parameters:
serviceConsumer- used to invoke the method on the service interface- Returns:
- an empty future
-
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:
getServicein interfaceRpcSingleClient<S>- Returns:
- the service implementation
-