RemoteService.get method with timeout invocation added. #434

pull/499/head
Nikita 9 years ago
parent 58472c6cf9
commit 7fc8116066

@ -22,6 +22,7 @@ import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.redisson.core.MessageListener;
@ -110,7 +111,12 @@ public class RedissonRemoteService implements RRemoteService {
}
@Override
public <T> T get(final Class<T> remoteInterface) {
public <T> T get(Class<T> remoteInterface) {
return get(remoteInterface, -1, null);
}
@Override
public <T> T get(final Class<T> remoteInterface, final int timeout, final TimeUnit timeUnit) {
InvocationHandler handler = new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
@ -132,7 +138,11 @@ public class RedissonRemoteService implements RRemoteService {
}
});
latch.await();
if (timeout == -1) {
latch.await();
} else {
latch.await(timeout, timeUnit);
}
topic.removeListener(listenerId);
RemoteServiceResponse msg = response.get();
if (msg.getError() != null) {

@ -15,6 +15,8 @@
*/
package org.redisson.core;
import java.util.concurrent.TimeUnit;
public interface RRemoteService {
/**
@ -42,4 +44,15 @@ public interface RRemoteService {
*/
<T> T get(Class<T> remoteInterface);
/**
* Get remote service object for remote invocations
* with specified timeout invocation
*
* @param remoteInterface
* @param timeout - timeout invocation
* @param timeUnit
* @return
*/
<T> T get(Class<T> remoteInterface, int timeout, TimeUnit timeUnit);
}

Loading…
Cancel
Save