Interface RRemoteService
- All Known Implementing Classes:
RedissonExecutorRemoteService,RedissonRemoteService
1. Server side instance (worker instance). Register object with RRemoteService instance.
RRemoteService remoteService = redisson.getRemoteService();
// register remote service before any remote invocation
remoteService.register(SomeServiceInterface.class, someServiceImpl);
2. Client side instance. Invokes method remotely.
RRemoteService remoteService = redisson.getRemoteService();
SomeServiceInterface service = remoteService.get(SomeServiceInterface.class);
String result = service.doSomeStuff(1L, "secondParam", new AnyParam());
There are two timeouts during execution:
Acknowledge (Ack) timeout.Client side instance waits for acknowledge message from Server side instance.
If acknowledge has not been received by Client side instance then RemoteServiceAckTimeoutException will be thrown.
And next invocation attempt can be made.
If acknowledge has not been received Client side instance but Server side instance has received invocation message already. In this case invocation will be skipped, due to ack timeout checking by Server side instance.
Execution timeout. Client side instance received acknowledge message. If it hasn't received any result or error
from server side during execution timeout then RemoteServiceTimeoutException will be thrown.
- Author:
- Nikita Koksharov
-
Method Summary
Modifier and TypeMethodDescription<T> voidderegister(Class<T> remoteInterface) Deregister all workers for remote service<T> TGet remote service object for remote invocations.<T> TGet remote service object for remote invocations with specified invocation timeout.<T> Tget(Class<T> remoteInterface, long executionTimeout, TimeUnit executionTimeUnit, long ackTimeout, TimeUnit ackTimeUnit) Get remote service object for remote invocations with specified invocation and ack timeouts<T> Tget(Class<T> remoteInterface, RemoteInvocationOptions options) Get remote service object for remote invocations with the specified optionsintgetFreeWorkers(Class<?> remoteInterface) Returns free workers amount available for invocationsintgetPendingInvocations(Class<?> remoteInterface) Returns pending invocations amount for handling in free workers.getPendingInvocationsAsync(Class<?> remoteInterface) Returns pending invocations amount for handling in free workers.<T> voidRegister remote service with single worker<T> voidRegister remote service with custom workers amount<T> voidregister(Class<T> remoteInterface, T object, int workers, ExecutorService executor) Register remote service with custom workers amount and executor for running them<T> booleantryExecute(Class<T> remoteInterface, T object, long timeout, TimeUnit timeUnit) Tries to execute one awaiting remote request.<T> booleantryExecute(Class<T> remoteInterface, T object, ExecutorService executorService, long timeout, TimeUnit timeUnit) Tries to execute one awaiting remote request.tryExecuteAsync(Class<T> remoteInterface, T object) Tries to execute one awaiting remote request.tryExecuteAsync(Class<T> remoteInterface, T object, long timeout, TimeUnit timeUnit) Tries to execute one awaiting remote request.tryExecuteAsync(Class<T> remoteInterface, T object, ExecutorService executorService, long timeout, TimeUnit timeUnit) Tries to execute one awaiting remote request.
-
Method Details
-
getFreeWorkers
Returns free workers amount available for invocations- Parameters:
remoteInterface- - remote service interface- Returns:
- workers amount
-
getPendingInvocations
Returns pending invocations amount for handling in free workers.- Parameters:
remoteInterface- - remote service interface- Returns:
- invocations amount
-
getPendingInvocationsAsync
Returns pending invocations amount for handling in free workers.- Parameters:
remoteInterface- - remote service interface- Returns:
- invocations amount
-
register
Register remote service with single worker- Type Parameters:
T- type of remote service- Parameters:
remoteInterface- - remote service interfaceobject- - remote service object
-
register
Register remote service with custom workers amount- Type Parameters:
T- type of remote service- Parameters:
remoteInterface- - remote service interfaceobject- - remote service objectworkersAmount- - workers amount
-
register
Register remote service with custom workers amount and executor for running them- Type Parameters:
T- type of remote service- Parameters:
remoteInterface- - remote service interfaceobject- - remote service objectworkers- - workers amountexecutor- - executor service used to invoke methods
-
deregister
Deregister all workers for remote service- Type Parameters:
T- type of remote service- Parameters:
remoteInterface- - remote service interface
-
tryExecute
<T> boolean tryExecute(Class<T> remoteInterface, T object, long timeout, TimeUnit timeUnit) throws InterruptedException Tries to execute one awaiting remote request. Waits up totimeoutif necessary until remote request became available.- Type Parameters:
T- - type of remote service- Parameters:
remoteInterface- - remote service interfaceobject- - remote service objecttimeout- - maximum wait time until remote request became availabletimeUnit- - time unit- Returns:
trueif method was successfully executed andfalseif timeout reached before execution- Throws:
InterruptedException- - if the thread is interrupted
-
tryExecute
<T> boolean tryExecute(Class<T> remoteInterface, T object, ExecutorService executorService, long timeout, TimeUnit timeUnit) throws InterruptedException Tries to execute one awaiting remote request. Waits up totimeoutif necessary until remote request became available.- Type Parameters:
T- - type of remote service- Parameters:
remoteInterface- - remote service interfaceobject- - remote service objectexecutorService- - executor service used to invoke methodstimeout- - maximum wait time until remote request became availabletimeUnit- - time unit- Returns:
trueif method was successfully executed andfalseif timeout reached before execution- Throws:
InterruptedException- - if the thread is interrupted
-
tryExecuteAsync
Tries to execute one awaiting remote request.- Type Parameters:
T- - type of remote service- Parameters:
remoteInterface- - remote service interfaceobject- - remote service object- Returns:
trueif method was successfully executed andfalseif timeout reached before execution
-
tryExecuteAsync
<T> RFuture<Boolean> tryExecuteAsync(Class<T> remoteInterface, T object, long timeout, TimeUnit timeUnit) Tries to execute one awaiting remote request. Waits up totimeoutif necessary until remote request became available.- Type Parameters:
T- - type of remote service- Parameters:
remoteInterface- - remote service interfaceobject- - remote service objecttimeout- - maximum wait time until remote request became availabletimeUnit- - time unit- Returns:
trueif method was successfully executed andfalseif timeout reached before execution
-
tryExecuteAsync
<T> RFuture<Boolean> tryExecuteAsync(Class<T> remoteInterface, T object, ExecutorService executorService, long timeout, TimeUnit timeUnit) Tries to execute one awaiting remote request. Waits up totimeoutif necessary until remote request became available.- Type Parameters:
T- - type of remote service- Parameters:
remoteInterface- - remote service interfaceobject- - remote service objectexecutorService- - executor service used to invoke methodstimeout- - maximum wait time until remote request became availabletimeUnit- - time unit- Returns:
trueif method was successfully executed andfalseif timeout reached before execution
-
get
Get remote service object for remote invocations.This method is a shortcut for
get(remoteInterface, RemoteInvocationOptions.defaults())- Type Parameters:
T- type of remote service- Parameters:
remoteInterface- - remote service interface- Returns:
- remote service instance
- See Also:
-
get
Get remote service object for remote invocations with specified invocation timeout.This method is a shortcut for
get(remoteInterface, RemoteInvocationOptions.defaults() .expectResultWithin(executionTimeout, executionTimeUnit))- Type Parameters:
T- type of remote service- Parameters:
remoteInterface- - remote service interfaceexecutionTimeout- - invocation timeoutexecutionTimeUnit- - time unit- Returns:
- remote service instance
- See Also:
-
get
<T> T get(Class<T> remoteInterface, long executionTimeout, TimeUnit executionTimeUnit, long ackTimeout, TimeUnit ackTimeUnit) Get remote service object for remote invocations with specified invocation and ack timeoutsThis method is a shortcut for
get(remoteInterface, RemoteInvocationOptions.defaults() .expectAckWithin(ackTimeout, ackTimeUnit) .expectResultWithin(executionTimeout, executionTimeUnit))- Type Parameters:
T- type of remote service- Parameters:
remoteInterface- - remote service interfaceexecutionTimeout- - invocation timeoutexecutionTimeUnit- - time unitackTimeout- - ack timeoutackTimeUnit- - time unit- Returns:
- remote service object
- See Also:
-
get
Get remote service object for remote invocations with the specified optionsNote that when using the noResult() option, it is expected that the invoked method returns void, or else IllegalArgumentException will be thrown.
- Type Parameters:
T- type of remote service- Parameters:
remoteInterface- - remote service interfaceoptions- - service options- Returns:
- remote service object
- See Also:
-