@ComponentSpecification public interface RemoteInvocationServiceCaller extends AbstractRemoteInvocationServiceCaller, RemoteInvocationCaller<RemoteInvocationServiceQueue>
RemoteInvocationService
s 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 useRemoteInvocationServiceCaller
caller = getServiceCaller(); MyService myService = caller.getServiceClient
(MyService.class, MyResult.class, this::onSuccess, failure -> getLogger().error(failure)); myService.myMethod(myArgument1, myArgument2);
RemoteInvocationServiceQueue
as 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-stubRemoteInvocationServiceCaller
caller = getServiceCaller();RemoteInvocationServiceQueue
queue = caller.RemoteInvocationCaller.newQueue()
; queue.setDefaultFailureCallback
(this::onFailure); MyService myService = queue.getServiceClient
(MyService.class, MyResult.class, this::onSuccess, null); myService.myMethod(myArgument1, myArgument2); ... queue.commit()
;
myService
for the
service-interface MyService
is created. On this you can directly invoke the actual service
method, here myMethod
with the according arguments as you would do for a synchronous
invocation. However, the method invocation will always return a dummy result (null
for
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.function
for 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 |
---|---|
<SERVICE extends RemoteInvocationService,RESULT> |
getServiceClient(Class<SERVICE> serviceInterface,
Class<RESULT> returnType,
Consumer<? extends RESULT> successCallback,
Consumer<Throwable> failureCallback)
This method gets a client-stub for calling exactly one single method on a
RemoteInvocationService . |
getServiceClient
getCurrentQueue, newQueue, newQueue, newQueue
static final String CDI_NAME
CDI name
.<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.
queue
that gets committed
automatically after a service method has been called on the returned client-stub.getServiceClient
in interface AbstractRemoteInvocationServiceCaller
SERVICE
- is the generic type of serviceInterface
.RESULT
- is the generic type of returnType
.serviceInterface
- is the interface of the RemoteInvocationService
.returnType
- is the return type
of the
Method
to invoke.successCallback
- is the Consumer
that is asynchronously invoked
on success with when the result of the invoked service Method
has 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.class
as
return type.failureCallback
- is the Consumer
that is asynchronously invoked
on failure with the Throwable
that occurred when calling the invoked service
Method
.RemoteInvocationService
.Copyright © 2001–2016 mmm-Team. All rights reserved.