Package org.knime.core.webui.data.rpc
Class AbstractRpcClient
java.lang.Object
org.knime.core.webui.data.rpc.AbstractRpcClient
- All Implemented Interfaces:
RpcClient
- Direct Known Subclasses:
AbstractRpcSingleClient,JsonRpcClient
Base class for node data service client implementations, such as
JsonRpcClient.- Since:
- 4.3
- Author:
- Martin Horn, KNIME GmbH, Konstanz, Germany, Carl Witt, KNIME AG, Zurich, Switzerland
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedGet the rpc transport from the extension point.protectedAbstractRpcClient(RpcTransport rpcTransport) For testing only: Constructor to initialize an rpc client with custom transport. -
Method Summary
Modifier and TypeMethodDescriptioncallService(Class<S> serviceInterface, String serviceName, Consumer<S> serviceEvaluator) <S,R> Future<R> callServiceWithRes(Class<S> serviceInterface, String serviceName, Function<S, R> serviceEvaluator) Calls a method on the node model's data service implementation of the given interface registered under the given name and returns the result.protected abstract 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}protected abstract <R> RconvertResult(String response, Type valueType) Counterpart forconvertCall(String, Method, Object[]), parses response and converts back to the method return type declared by the service interface.<S> SgetService(Class<S> serviceInterface, String serviceName) booleanMethods 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
-
Constructor Details
-
AbstractRpcClient
protected AbstractRpcClient()Get the rpc transport from the extension point. -
AbstractRpcClient
For testing only: Constructor to initialize an rpc client with custom transport.- Parameters:
rpcTransport- a custom rpc transport for testing
-
-
Method Details
-
convertCall
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}- 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
-
convertResult
Counterpart forconvertCall(String, Method, Object[]), parses response and converts back to the method return type declared by the service interface.- Type Parameters:
R- the return type of the method invoked via remote procedure call- Parameters:
response- the result of the remote procedure callvalueType- the return type of the method invoked via remote procedure call, e.g., as returned bySomeInterface.class.getMethod("someMethodName").getReturnType()- Returns:
- the result as a java object of the specified type
- Throws:
Exception- an exception thrown by the rpc client implementation when processing the request
-
getService
Description copied from interface:RpcClient- Specified by:
getServicein interfaceRpcClient- Returns:
- the service implementation
-
callService
public <S> Future<Void> callService(Class<S> serviceInterface, String serviceName, Consumer<S> serviceEvaluator) Description copied from interface:RpcClient- Specified by:
callServicein interfaceRpcClient- Type Parameters:
S- the interface type of the service to use- Parameters:
serviceInterface- the interface of the service to callserviceName- the name under which the service interface is registered at the server, seeRpcServer.getHandler(String)serviceEvaluator- used to invoke the method on the service interface- Returns:
- an empty future
-
callServiceWithRes
public <S,R> Future<R> callServiceWithRes(Class<S> serviceInterface, String serviceName, Function<S, R> serviceEvaluator) Description copied from interface:RpcClientCalls a method on the node model's data service implementation of the given interface registered under the given name and returns the result. Example usage:RpcClient m_rpcClient = ... Future<List<SomeType>> future = m_rpcClient.callServiceWithRes(MyService.class, "MyServiceInstance3", s -> s.getSomeData(someParameter)); try { List<SomeType> results = future.get(3, TimeUnit.SECONDS); } catch (TimeoutException timeoutException) { ...- Specified by:
callServiceWithResin interfaceRpcClient- Type Parameters:
S- the interface type of the service to useR- the result type of the invoked method- Parameters:
serviceInterface- the interface of the service to call toserviceName- the name under which the service interface is registered at the server, seeRpcServer.getHandler(String)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:
- the result
-
isConnectedRemotely
public boolean isConnectedRemotely()- Specified by:
isConnectedRemotelyin interfaceRpcClient- Returns:
trueif this rpc client is connected to a server, orfalseif the call are just forwarded to a local implementation.
-