From d14ec8ad0ad263a011aff48ac01fdc84b88b8587 Mon Sep 17 00:00:00 2001 From: slavarosin Date: Mon, 10 Oct 2016 20:36:34 +0200 Subject: [PATCH 1/2] Fixed type getRemoteSerivce -> getRemoteService --- .../src/main/java/org/redisson/Redisson.java | 8 +-- .../org/redisson/RedissonExecutorService.java | 2 +- .../java/org/redisson/api/RedissonClient.java | 8 +-- .../redisson/RedissonRemoteServiceTest.java | 66 +++++++++---------- 4 files changed, 41 insertions(+), 43 deletions(-) diff --git a/redisson/src/main/java/org/redisson/Redisson.java b/redisson/src/main/java/org/redisson/Redisson.java index fc410447e..780f728f3 100755 --- a/redisson/src/main/java/org/redisson/Redisson.java +++ b/redisson/src/main/java/org/redisson/Redisson.java @@ -345,22 +345,22 @@ public class Redisson implements RedissonClient { } @Override - public RRemoteService getRemoteSerivce() { + public RRemoteService getRemoteService() { return new RedissonRemoteService(this, commandExecutor); } @Override - public RRemoteService getRemoteSerivce(String name) { + public RRemoteService getRemoteService(String name) { return new RedissonRemoteService(this, name, commandExecutor); } @Override - public RRemoteService getRemoteSerivce(Codec codec) { + public RRemoteService getRemoteService(Codec codec) { return new RedissonRemoteService(codec, this, commandExecutor); } @Override - public RRemoteService getRemoteSerivce(String name, Codec codec) { + public RRemoteService getRemoteService(String name, Codec codec) { return new RedissonRemoteService(codec, this, name, commandExecutor); } diff --git a/redisson/src/main/java/org/redisson/RedissonExecutorService.java b/redisson/src/main/java/org/redisson/RedissonExecutorService.java index bff5ba938..3232b7ac3 100644 --- a/redisson/src/main/java/org/redisson/RedissonExecutorService.java +++ b/redisson/src/main/java/org/redisson/RedissonExecutorService.java @@ -252,7 +252,7 @@ public class RedissonExecutorService implements RScheduledExecutorService { service.setSchedulerChannelName(schedulerChannelName); service.setSchedulerQueueName(schedulerQueueName); - redisson.getRemoteSerivce(name, codec).register(RemoteExecutorService.class, service, workers, executor); + redisson.getRemoteService(name, codec).register(RemoteExecutorService.class, service, workers, executor); } @Override diff --git a/redisson/src/main/java/org/redisson/api/RedissonClient.java b/redisson/src/main/java/org/redisson/api/RedissonClient.java index a4c7c269b..5080ba008 100755 --- a/redisson/src/main/java/org/redisson/api/RedissonClient.java +++ b/redisson/src/main/java/org/redisson/api/RedissonClient.java @@ -678,7 +678,7 @@ public interface RedissonClient { * * @return RemoteService object */ - RRemoteService getRemoteSerivce(); + RRemoteService getRemoteService(); /** * Returns object for remote operations prefixed with the default name (redisson_remote_service) @@ -687,7 +687,7 @@ public interface RedissonClient { * @param codec - codec for response and request * @return RemoteService object */ - RRemoteService getRemoteSerivce(Codec codec); + RRemoteService getRemoteService(Codec codec); /** * Returns object for remote operations prefixed with the specified name @@ -695,7 +695,7 @@ public interface RedissonClient { * @param name - the name used as the Redis key prefix for the services * @return RemoteService object */ - RRemoteService getRemoteSerivce(String name); + RRemoteService getRemoteService(String name); /** * Returns object for remote operations prefixed with the specified name @@ -705,7 +705,7 @@ public interface RedissonClient { * @param codec - codec for response and request * @return RemoteService object */ - RRemoteService getRemoteSerivce(String name, Codec codec); + RRemoteService getRemoteService(String name, Codec codec); /** * Return batch object which executes group of diff --git a/redisson/src/test/java/org/redisson/RedissonRemoteServiceTest.java b/redisson/src/test/java/org/redisson/RedissonRemoteServiceTest.java index efc06f454..7724ae26d 100644 --- a/redisson/src/test/java/org/redisson/RedissonRemoteServiceTest.java +++ b/redisson/src/test/java/org/redisson/RedissonRemoteServiceTest.java @@ -24,8 +24,6 @@ import org.redisson.codec.SerializationCodec; import org.redisson.remote.RemoteServiceAckTimeoutException; import org.redisson.remote.RemoteServiceTimeoutException; -import io.netty.util.concurrent.Future; - public class RedissonRemoteServiceTest extends BaseTest { public static class Pojo { @@ -193,10 +191,10 @@ public class RedissonRemoteServiceTest extends BaseTest { AtomicInteger iterations = new AtomicInteger(); ExecutorService executor = Executors.newSingleThreadExecutor(); r1.getKeys().flushall(); - r1.getRemoteSerivce().register(RemoteInterface.class, new RemoteImpl(iterations), 1, executor); + r1.getRemoteService().register(RemoteInterface.class, new RemoteImpl(iterations), 1, executor); RedissonClient r2 = createInstance(); - RemoteInterfaceAsync ri = r2.getRemoteSerivce().get(RemoteInterfaceAsync.class); + RemoteInterfaceAsync ri = r2.getRemoteService().get(RemoteInterfaceAsync.class); RFuture f = ri.cancelMethod(); Thread.sleep(500); @@ -214,21 +212,21 @@ public class RedissonRemoteServiceTest extends BaseTest { @Test(expected = IllegalArgumentException.class) public void testWrongMethodAsync() throws InterruptedException { - redisson.getRemoteSerivce().get(RemoteInterfaceWrongMethodAsync.class); + redisson.getRemoteService().get(RemoteInterfaceWrongMethodAsync.class); } @Test(expected = IllegalArgumentException.class) public void testWrongParamsAsync() throws InterruptedException { - redisson.getRemoteSerivce().get(RemoteInterfaceWrongParamsAsync.class); + redisson.getRemoteService().get(RemoteInterfaceWrongParamsAsync.class); } @Test public void testAsync() throws InterruptedException { RedissonClient r1 = createInstance(); - r1.getRemoteSerivce().register(RemoteInterface.class, new RemoteImpl()); + r1.getRemoteService().register(RemoteInterface.class, new RemoteImpl()); RedissonClient r2 = createInstance(); - RemoteInterfaceAsync ri = r2.getRemoteSerivce().get(RemoteInterfaceAsync.class); + RemoteInterfaceAsync ri = r2.getRemoteService().get(RemoteInterfaceAsync.class); RFuture f = ri.voidMethod("someName", 100L); f.sync(); @@ -244,10 +242,10 @@ public class RedissonRemoteServiceTest extends BaseTest { public void testExecutorAsync() throws InterruptedException { RedissonClient r1 = createInstance(); ExecutorService executor = Executors.newSingleThreadExecutor(); - r1.getRemoteSerivce().register(RemoteInterface.class, new RemoteImpl(), 1, executor); + r1.getRemoteService().register(RemoteInterface.class, new RemoteImpl(), 1, executor); RedissonClient r2 = createInstance(); - RemoteInterfaceAsync ri = r2.getRemoteSerivce().get(RemoteInterfaceAsync.class); + RemoteInterfaceAsync ri = r2.getRemoteService().get(RemoteInterfaceAsync.class); RFuture f = ri.voidMethod("someName", 100L); f.sync(); @@ -284,7 +282,7 @@ public class RedissonRemoteServiceTest extends BaseTest { // - check if concurrency is greater than what was allowed, and if yes set the concurrencyOfOneIsExceeded flag // - wait 2s // - decr the concurrency - server.getRemoteSerivce().register(RemoteInterface.class, new RemoteImpl() { + server.getRemoteService().register(RemoteInterface.class, new RemoteImpl() { @Override public void timeoutMethod() throws InterruptedException { try { @@ -312,7 +310,7 @@ public class RedissonRemoteServiceTest extends BaseTest { @Override public void run() { try { - RemoteInterface ri = client.getRemoteSerivce().get(RemoteInterface.class, clientAmount * 3, TimeUnit.SECONDS, clientAmount * 3, TimeUnit.SECONDS); + RemoteInterface ri = client.getRemoteService().get(RemoteInterface.class, clientAmount * 3, TimeUnit.SECONDS, clientAmount * 3, TimeUnit.SECONDS); readyLatch.await(); ri.timeoutMethod(); } catch (InterruptedException e) { @@ -348,10 +346,10 @@ public class RedissonRemoteServiceTest extends BaseTest { @Test(expected = RemoteServiceTimeoutException.class) public void testTimeout() throws InterruptedException { RedissonClient r1 = createInstance(); - r1.getRemoteSerivce().register(RemoteInterface.class, new RemoteImpl()); + r1.getRemoteService().register(RemoteInterface.class, new RemoteImpl()); RedissonClient r2 = createInstance(); - RemoteInterface ri = r2.getRemoteSerivce().get(RemoteInterface.class, 1, TimeUnit.SECONDS); + RemoteInterface ri = r2.getRemoteService().get(RemoteInterface.class, 1, TimeUnit.SECONDS); try { ri.timeoutMethod(); @@ -364,10 +362,10 @@ public class RedissonRemoteServiceTest extends BaseTest { @Test public void testInvocations() { RedissonClient r1 = createInstance(); - r1.getRemoteSerivce().register(RemoteInterface.class, new RemoteImpl()); + r1.getRemoteService().register(RemoteInterface.class, new RemoteImpl()); RedissonClient r2 = createInstance(); - RemoteInterface ri = r2.getRemoteSerivce().get(RemoteInterface.class); + RemoteInterface ri = r2.getRemoteService().get(RemoteInterface.class); ri.voidMethod("someName", 100L); assertThat(ri.resultMethod(100L)).isEqualTo(200); @@ -396,11 +394,11 @@ public class RedissonRemoteServiceTest extends BaseTest { RedissonClient server = createInstance(); RedissonClient client = createInstance(); - server.getRemoteSerivce("MyServiceNamespace").register(RemoteInterface.class, new RemoteImpl()); + server.getRemoteService("MyServiceNamespace").register(RemoteInterface.class, new RemoteImpl()); - RemoteInterface serviceRemoteInterface = client.getRemoteSerivce("MyServiceNamespace").get(RemoteInterface.class); - RemoteInterface otherServiceRemoteInterface = client.getRemoteSerivce("MyOtherServiceNamespace").get(RemoteInterface.class); - RemoteInterface defaultServiceRemoteInterface = client.getRemoteSerivce().get(RemoteInterface.class); + RemoteInterface serviceRemoteInterface = client.getRemoteService("MyServiceNamespace").get(RemoteInterface.class); + RemoteInterface otherServiceRemoteInterface = client.getRemoteService("MyOtherServiceNamespace").get(RemoteInterface.class); + RemoteInterface defaultServiceRemoteInterface = client.getRemoteService().get(RemoteInterface.class); assertThat(serviceRemoteInterface.resultMethod(21L)).isEqualTo(42L); @@ -426,7 +424,7 @@ public class RedissonRemoteServiceTest extends BaseTest { public void testProxyToStringEqualsAndHashCode() { RedissonClient client = createInstance(); try { - RemoteInterface service = client.getRemoteSerivce().get(RemoteInterface.class); + RemoteInterface service = client.getRemoteService().get(RemoteInterface.class); try { System.out.println(service.toString()); @@ -456,9 +454,9 @@ public class RedissonRemoteServiceTest extends BaseTest { RedissonClient server = Redisson.create(createConfig().setCodec(new FstCodec())); RedissonClient client = Redisson.create(createConfig().setCodec(new FstCodec())); try { - server.getRemoteSerivce().register(RemoteInterface.class, new RemoteImpl()); + server.getRemoteService().register(RemoteInterface.class, new RemoteImpl()); - RemoteInterface service = client.getRemoteSerivce().get(RemoteInterface.class); + RemoteInterface service = client.getRemoteService().get(RemoteInterface.class); assertThat(service.resultMethod(21L)).as("Should be compatible with FstCodec").isEqualTo(42L); @@ -486,9 +484,9 @@ public class RedissonRemoteServiceTest extends BaseTest { RedissonClient server = Redisson.create(createConfig().setCodec(new SerializationCodec())); RedissonClient client = Redisson.create(createConfig().setCodec(new SerializationCodec())); try { - server.getRemoteSerivce().register(RemoteInterface.class, new RemoteImpl()); + server.getRemoteService().register(RemoteInterface.class, new RemoteImpl()); - RemoteInterface service = client.getRemoteSerivce().get(RemoteInterface.class); + RemoteInterface service = client.getRemoteService().get(RemoteInterface.class); try { assertThat(service.resultMethod(21L)).isEqualTo(42L); @@ -522,11 +520,11 @@ public class RedissonRemoteServiceTest extends BaseTest { RedissonClient server = createInstance(); RedissonClient client = createInstance(); try { - server.getRemoteSerivce().register(RemoteInterface.class, new RemoteImpl()); + server.getRemoteService().register(RemoteInterface.class, new RemoteImpl()); // no ack but an execution timeout of 1 second RemoteInvocationOptions options = RemoteInvocationOptions.defaults().noAck().expectResultWithin(1, TimeUnit.SECONDS); - RemoteInterface service = client.getRemoteSerivce().get(RemoteInterface.class, options); + RemoteInterface service = client.getRemoteService().get(RemoteInterface.class, options); service.voidMethod("noAck", 100L); assertThat(service.resultMethod(21L)).isEqualTo(42); @@ -563,11 +561,11 @@ public class RedissonRemoteServiceTest extends BaseTest { RedissonClient server = createInstance(); RedissonClient client = createInstance(); try { - server.getRemoteSerivce().register(RemoteInterface.class, new RemoteImpl()); + server.getRemoteService().register(RemoteInterface.class, new RemoteImpl()); // no ack but an execution timeout of 1 second RemoteInvocationOptions options = RemoteInvocationOptions.defaults().noAck().expectResultWithin(1, TimeUnit.SECONDS); - RemoteInterfaceAsync service = client.getRemoteSerivce().get(RemoteInterfaceAsync.class, options); + RemoteInterfaceAsync service = client.getRemoteService().get(RemoteInterfaceAsync.class, options); service.voidMethod("noAck", 100L).get(); assertThat(service.resultMethod(21L).get()).isEqualTo(42); @@ -604,11 +602,11 @@ public class RedissonRemoteServiceTest extends BaseTest { RedissonClient server = createInstance(); RedissonClient client = createInstance(); try { - server.getRemoteSerivce().register(RemoteInterface.class, new RemoteImpl()); + server.getRemoteService().register(RemoteInterface.class, new RemoteImpl()); // fire and forget with an ack timeout of 1 sec RemoteInvocationOptions options = RemoteInvocationOptions.defaults().expectAckWithin(1, TimeUnit.SECONDS).noResult(); - RemoteInterface service = client.getRemoteSerivce().get(RemoteInterface.class, options); + RemoteInterface service = client.getRemoteService().get(RemoteInterface.class, options); service.voidMethod("noResult", 100L); @@ -653,12 +651,12 @@ public class RedissonRemoteServiceTest extends BaseTest { RedissonClient server = createInstance(); RedissonClient client = createInstance(); try { - server.getRemoteSerivce().register(RemoteInterface.class, new RemoteImpl()); + server.getRemoteService().register(RemoteInterface.class, new RemoteImpl()); // no ack fire and forget RemoteInvocationOptions options = RemoteInvocationOptions.defaults().noAck().noResult(); - RemoteInterface service = client.getRemoteSerivce().get(RemoteInterface.class, options); - RemoteInterface invalidService = client.getRemoteSerivce("Invalid").get(RemoteInterface.class, options); + RemoteInterface service = client.getRemoteService().get(RemoteInterface.class, options); + RemoteInterface invalidService = client.getRemoteService("Invalid").get(RemoteInterface.class, options); service.voidMethod("noAck/noResult", 100L); From 79b3b8e291a4178ced1c25b4a661c9ca481937af Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Tue, 11 Oct 2016 20:14:44 +0300 Subject: [PATCH 2/2] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 259b3feb5..b51445c88 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ Articles [Introducing Redisson Live Objects (Object Hash Mapping)](https://dzone.com/articles/introducing-redisson-live-object-object-hash-mappi) [Java Remote Method Invocation with Redisson](https://dzone.com/articles/java-remote-method-invocation-with-redisson) [Java Multimaps With Redis](https://dzone.com/articles/multimaps-with-redis) +[Distributed lock with Redis](https://evuvatech.com/2016/02/05/distributed-lock-with-redis/) Quick start ===============================