@ComponentSpecification public interface RemoteInvocationServiceCaller extends AbstractRemoteInvocationServiceCaller, RemoteInvocationCaller<RemoteInvocationServiceQueue>
RemoteInvocationServices from the client-side. The most simple usage is given in the following example:
However, there are advanced features such as queuing service calls and send them in a single technical request. Therefore you should use
RemoteInvocationServiceCallercaller = getServiceCaller(); MyService myService = caller.
getServiceClient(MyService.class, MyResult.class, this::onSuccess, failure -> getLogger().error(failure)); myService.myMethod(myArgument1, myArgument2);
RemoteInvocationServiceQueueas illustrated by this example:
This might look a little complex on the first view, but it allows very powerful but quite easy usage of asynchronous service invocations. In the example above a client-stub
RemoteInvocationServiceCallercaller = getServiceCaller();
RemoteInvocationServiceQueuequeue = caller.
setDefaultFailureCallback(this::onFailure); MyService myService = queue.
getServiceClient(MyService.class, MyResult.class, this::onSuccess, null); myService.myMethod(myArgument1, myArgument2); ... queue.
myServicefor the service-interface
MyServiceis created. On this you can directly invoke the actual service method, here
myMethodwith the according arguments as you would do for a synchronous invocation. However, the method invocation will always return a dummy result (
nullfor non-primitive return types) that you should ignore. Instead the method invocation including its arguments is recorded by the
RemoteInvocationServiceQueue. It will be send to the server when the top-level queue is
committed. When the result is received from the server, it will be
passed to a callback function.
net.sf.mmm.util.lang.api.functionfor details. If you are using a java version less than 1.8, you can NOT use lambdas and have to provide instances via anonymous classes.
|Modifier and Type||Method and Description|
This method gets a client-stub for calling exactly one single method on a
<SERVICE extends RemoteInvocationService,RESULT> SERVICE getServiceClient(Class<SERVICE> serviceInterface, Class<RESULT> returnType, Consumer<? extends RESULT> successCallback, Consumer<Throwable> failureCallback)
RemoteInvocationService. After this method has been called, the intended method (with the given
returnType) has to be invoked on the resulting client-stub exactly once. This records the desired method invocation and returns a dummy result (typically
null) that shall be ignored.
committedautomatically after a service method has been called on the returned client-stub.
SERVICE- is the generic type of
RESULT- is the generic type of
serviceInterface- is the interface of the
returnType- is the
return typeof the
successCallback- is the
Consumerthat is asynchronously
invokedon success with when the result of the invoked service
Methodhas been received. The generic type may extend result if it is generic itself. E.g. your service might return
List<String>but you can only supply
List.classas return type.
failureCallback- is the
Consumerthat is asynchronously
invokedon failure with the
Throwablethat occurred when calling the invoked service
Copyright © 2001–2014 mmm-Team. All rights reserved.