org.redisson.api.RRemoteService Java Examples

The following examples show how to use org.redisson.api.RRemoteService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedissonRemoteServiceTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testPendingInvocations() throws InterruptedException, ExecutionException {
    ExecutorService executor = Executors.newSingleThreadExecutor();
    RRemoteService rs = redisson.getRemoteService();
    rs.register(RemoteInterface.class, new RemoteImpl(), 1, executor);
    
    assertThat(rs.getPendingInvocations(RemoteInterface.class)).isEqualTo(0);
    
    RemoteInterfaceAsync ri = redisson.getRemoteService().get(RemoteInterfaceAsync.class);
    
    for (int i = 0; i < 5; i++) {
        ri.timeoutMethod();
    }
    Thread.sleep(1000);
    assertThat(rs.getPendingInvocations(RemoteInterface.class)).isEqualTo(4);
    Thread.sleep(9000);
    assertThat(rs.getPendingInvocations(RemoteInterface.class)).isEqualTo(0);

    executor.shutdown();
    executor.awaitTermination(1, TimeUnit.MINUTES);
    
    rs.deregister(RemoteInterface.class);
}
 
Example #2
Source File: RedissonRemoteServiceTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testFreeWorkers() throws InterruptedException, ExecutionException {
    RedissonClient r1 = createInstance();
    ExecutorService executor = Executors.newSingleThreadExecutor();
    RRemoteService rs = r1.getRemoteService();
    rs.register(RemoteInterface.class, new RemoteImpl(), 1, executor);
    assertThat(rs.getFreeWorkers(RemoteInterface.class)).isEqualTo(1);
    
    RedissonClient r2 = createInstance();
    RemoteInterfaceAsync ri = r2.getRemoteService().get(RemoteInterfaceAsync.class);
    
    RFuture<Void> f = ri.timeoutMethod();
    Thread.sleep(100);
    assertThat(rs.getFreeWorkers(RemoteInterface.class)).isEqualTo(0);
    f.get();
    assertThat(rs.getFreeWorkers(RemoteInterface.class)).isEqualTo(1);

    r1.shutdown();
    r2.shutdown();
    
    executor.shutdown();
    executor.awaitTermination(1, TimeUnit.MINUTES);
}
 
Example #3
Source File: RedissonTransferQueue.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonTransferQueue(Codec codec, CommandAsyncExecutor commandExecutor, String name, RRemoteService remoteService) {
    super(codec, commandExecutor, name);
    service = remoteService.get(TransferQueueServiceAsync.class, RemoteInvocationOptions.defaults().noAck());
    this.remoteService = remoteService;

    queueName = ((RedissonRemoteService) remoteService).getRequestQueueName(TransferQueueService.class);
    mapName = ((RedissonRemoteService) remoteService).getRequestTasksMapName(TransferQueueService.class);
}
 
Example #4
Source File: RedissonTransferQueue.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonTransferQueue(CommandAsyncExecutor commandExecutor, String name, RRemoteService remoteService) {
    super(commandExecutor, name);
    service = remoteService.get(TransferQueueServiceAsync.class, RemoteInvocationOptions.defaults().noAck());
    this.remoteService = remoteService;

    queueName = ((RedissonRemoteService) remoteService).getRequestQueueName(TransferQueueService.class);
    mapName = ((RedissonRemoteService) remoteService).getRequestTasksMapName(TransferQueueService.class);
}
 
Example #5
Source File: RedissonRemoteServiceTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testConcurrentInvocations() {
    ExecutorService executorService = Executors.newFixedThreadPool(2);
    RRemoteService remoteService = redisson.getRemoteService();
    remoteService.register(RemoteInterface.class, new RemoteImpl());
    RemoteInterface service = redisson.getRemoteService().get(RemoteInterface.class);

    List<Future<?>> futures = new ArrayList<>();

    int iterations = 1000;
    AtomicBoolean bool = new AtomicBoolean();
    for (int i = 0; i < iterations; i++) {
        futures.add(executorService.submit(() -> {
            try {
                if (ThreadLocalRandom.current().nextBoolean()) {
                    service.resultMethod(1L);
                } else {
                    service.methodOverload();
                }
            } catch (Exception e) {
                e.printStackTrace();
                bool.set(true);
            }
        }));
    }

    while (!futures.stream().allMatch(Future::isDone)) {}

    assertThat(bool.get()).isFalse();
    remoteService.deregister(RemoteInterface.class);
}
 
Example #6
Source File: TracingRedissonClient.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RRemoteService getRemoteService() {
  return redissonClient.getRemoteService();
}
 
Example #7
Source File: TracingRedissonClient.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RRemoteService getRemoteService(Codec codec) {
  return redissonClient.getRemoteService(codec);
}
 
Example #8
Source File: TracingRedissonClient.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RRemoteService getRemoteService(String name) {
  return redissonClient.getRemoteService(name);
}
 
Example #9
Source File: TracingRedissonClient.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RRemoteService getRemoteService(String name,
    Codec codec) {
  return redissonClient.getRemoteService(name, codec);
}