From a0ab1cbdbfb033208e9face56e86e33e3b0d422e Mon Sep 17 00:00:00 2001 From: Nikita Date: Tue, 11 Sep 2018 18:41:11 +0300 Subject: [PATCH] Javadocs added --- .../src/main/java/org/redisson/Redisson.java | 4 +- .../java/org/redisson/RedissonBuckets.java | 23 +---- .../java/org/redisson/api/RAtomicDouble.java | 8 +- .../org/redisson/api/RAtomicDoubleAsync.java | 63 ++++++++++++- .../redisson/api/RAtomicDoubleReactive.java | 68 +++++++++++++- .../java/org/redisson/api/RAtomicLong.java | 4 +- .../org/redisson/api/RAtomicLongAsync.java | 63 ++++++++++++- .../org/redisson/api/RAtomicLongReactive.java | 68 +++++++++++++- .../main/java/org/redisson/api/RBatch.java | 2 +- .../java/org/redisson/api/RBatchReactive.java | 4 +- .../org/redisson/api/RBlockingDequeAsync.java | 46 +++++++++- .../redisson/api/RBlockingDequeReactive.java | 45 +++++++++- .../java/org/redisson/api/RBlockingQueue.java | 32 ++++++- .../org/redisson/api/RBlockingQueueAsync.java | 28 +++++- .../redisson/api/RBlockingQueueReactive.java | 90 ++++++++++++++++++- .../java/org/redisson/api/RBloomFilter.java | 36 +++++++- .../redisson/api/RBoundedBlockingQueue.java | 2 +- .../api/RBoundedBlockingQueueAsync.java | 2 +- .../main/java/org/redisson/api/RBucket.java | 60 ++++++++++++- .../java/org/redisson/api/RBucketAsync.java | 58 +++++++++++- .../org/redisson/api/RBucketReactive.java | 58 +++++++++++- .../main/java/org/redisson/api/RBuckets.java | 8 +- .../java/org/redisson/api/RBucketsAsync.java | 2 + .../org/redisson/api/RCollectionAsync.java | 49 +++++----- .../org/redisson/api/RCollectionReactive.java | 71 ++++++++++++++- .../redisson/api/RTransactionReactive.java | 3 + .../RedissonAtomicDoubleReactive.java | 10 +++ .../reactive/RedissonAtomicLongReactive.java | 9 ++ 28 files changed, 828 insertions(+), 88 deletions(-) diff --git a/redisson/src/main/java/org/redisson/Redisson.java b/redisson/src/main/java/org/redisson/Redisson.java index 9f6a3f0ee..34f5bbb7f 100755 --- a/redisson/src/main/java/org/redisson/Redisson.java +++ b/redisson/src/main/java/org/redisson/Redisson.java @@ -235,12 +235,12 @@ public class Redisson implements RedissonClient { @Override public RBuckets getBuckets() { - return new RedissonBuckets(this, connectionManager.getCommandExecutor()); + return new RedissonBuckets(connectionManager.getCommandExecutor()); } @Override public RBuckets getBuckets(Codec codec) { - return new RedissonBuckets(this, codec, connectionManager.getCommandExecutor()); + return new RedissonBuckets(codec, connectionManager.getCommandExecutor()); } @Override diff --git a/redisson/src/main/java/org/redisson/RedissonBuckets.java b/redisson/src/main/java/org/redisson/RedissonBuckets.java index d54ceb476..a1a1ac56c 100644 --- a/redisson/src/main/java/org/redisson/RedissonBuckets.java +++ b/redisson/src/main/java/org/redisson/RedissonBuckets.java @@ -18,13 +18,11 @@ package org.redisson; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import org.redisson.api.RBucket; import org.redisson.api.RBuckets; import org.redisson.api.RFuture; import org.redisson.client.codec.Codec; @@ -45,30 +43,15 @@ public class RedissonBuckets implements RBuckets { private final Codec codec; private final CommandExecutor commandExecutor; - private final Redisson redisson; - public RedissonBuckets(Redisson redisson, CommandExecutor commandExecutor) { - this(redisson, commandExecutor.getConnectionManager().getCodec(), commandExecutor); + public RedissonBuckets(CommandExecutor commandExecutor) { + this(commandExecutor.getConnectionManager().getCodec(), commandExecutor); } - public RedissonBuckets(Redisson redisson, Codec codec, CommandExecutor commandExecutor) { + public RedissonBuckets(Codec codec, CommandExecutor commandExecutor) { super(); this.codec = codec; this.commandExecutor = commandExecutor; - this.redisson = redisson; - } - - @Override - public List> find(String pattern) { - Iterable keys = redisson.getKeys().getKeysByPattern(pattern); - List> buckets = new ArrayList>(); - for (String key : keys) { - if(key == null) { - continue; - } - buckets.add(redisson.getBucket(key, codec)); - } - return buckets; } @Override diff --git a/redisson/src/main/java/org/redisson/api/RAtomicDouble.java b/redisson/src/main/java/org/redisson/api/RAtomicDouble.java index 83b0fdd2b..5f1a66e09 100644 --- a/redisson/src/main/java/org/redisson/api/RAtomicDouble.java +++ b/redisson/src/main/java/org/redisson/api/RAtomicDouble.java @@ -16,7 +16,7 @@ package org.redisson.api; /** - * Distributed alternative to the AtomicDouble + * Distributed implementation to the AtomicDouble * * @author Nikita Koksharov * @@ -57,14 +57,14 @@ public interface RAtomicDouble extends RExpirable, RAtomicDoubleAsync { double decrementAndGet(); /** - * Gets the current value. + * Returns current value. * - * @return the current value + * @return current value */ double get(); /** - * Gets and deletes object + * Returns and deletes object * * @return the current value */ diff --git a/redisson/src/main/java/org/redisson/api/RAtomicDoubleAsync.java b/redisson/src/main/java/org/redisson/api/RAtomicDoubleAsync.java index fe211c2f4..cf2ec3a3e 100644 --- a/redisson/src/main/java/org/redisson/api/RAtomicDoubleAsync.java +++ b/redisson/src/main/java/org/redisson/api/RAtomicDoubleAsync.java @@ -16,37 +16,96 @@ package org.redisson.api; /** - * + * Distributed implementation to the AtomicDouble + * * @author Nikita Koksharov * */ public interface RAtomicDoubleAsync extends RExpirableAsync { + /** + * Atomically sets the value to the given updated value + * only if the current value {@code ==} the expected value. + * + * @param expect the expected value + * @param update the new value + * @return true if successful; or false if the actual value + * was not equal to the expected value. + */ RFuture compareAndSetAsync(double expect, double update); + /** + * Atomically adds the given value to the current value. + * + * @param delta the value to add + * @return the updated value + */ RFuture addAndGetAsync(double delta); + /** + * Atomically decrements the current value by one. + * + * @return the updated value + */ RFuture decrementAndGetAsync(); + /** + * Returns current value. + * + * @return current value + */ RFuture getAsync(); /** - * Gets and deletes object + * Returns and deletes object * * @return the current value */ RFuture getAndDeleteAsync(); + /** + * Atomically adds the given value to the current value. + * + * @param delta the value to add + * @return the updated value + */ RFuture getAndAddAsync(double delta); + /** + * Atomically sets the given value and returns the old value. + * + * @param newValue the new value + * @return the old value + */ RFuture getAndSetAsync(double newValue); + /** + * Atomically increments the current value by one. + * + * @return the updated value + */ RFuture incrementAndGetAsync(); + /** + * Atomically increments the current value by one. + * + * @return the old value + */ RFuture getAndIncrementAsync(); + /** + * Atomically decrements by one the current value. + * + * @return the previous value + */ RFuture getAndDecrementAsync(); + /** + * Atomically sets the given value. + * + * @param newValue the new value + * @return void + */ RFuture setAsync(double newValue); } diff --git a/redisson/src/main/java/org/redisson/api/RAtomicDoubleReactive.java b/redisson/src/main/java/org/redisson/api/RAtomicDoubleReactive.java index d352d2fd2..a95837ebf 100644 --- a/redisson/src/main/java/org/redisson/api/RAtomicDoubleReactive.java +++ b/redisson/src/main/java/org/redisson/api/RAtomicDoubleReactive.java @@ -18,30 +18,96 @@ package org.redisson.api; import org.reactivestreams.Publisher; /** - * + * Distributed implementation to the AtomicDouble + * * @author Nikita Koksharov * */ public interface RAtomicDoubleReactive extends RExpirableReactive { + /** + * Atomically sets the value to the given updated value + * only if the current value {@code ==} the expected value. + * + * @param expect the expected value + * @param update the new value + * @return true if successful; or false if the actual value + * was not equal to the expected value. + */ Publisher compareAndSet(double expect, double update); + /** + * Atomically adds the given value to the current value. + * + * @param delta the value to add + * @return the updated value + */ Publisher addAndGet(double delta); + /** + * Atomically decrements the current value by one. + * + * @return the updated value + */ Publisher decrementAndGet(); + /** + * Returns current value. + * + * @return current value + */ Publisher get(); + /** + * Returns and deletes object + * + * @return the current value + */ + Publisher getAndDelete(); + + /** + * Atomically adds the given value to the current value. + * + * @param delta the value to add + * @return the updated value + */ Publisher getAndAdd(double delta); + /** + * Atomically sets the given value and returns the old value. + * + * @param newValue the new value + * @return the old value + */ Publisher getAndSet(double newValue); + /** + * Atomically increments the current value by one. + * + * @return the updated value + */ Publisher incrementAndGet(); + /** + * Atomically increments the current value by one. + * + * @return the old value + */ Publisher getAndIncrement(); + /** + * Atomically decrements by one the current value. + * + * @return the previous value + */ Publisher getAndDecrement(); + /** + * Atomically sets the given value. + * + * @param newValue the new value + * @return void + */ Publisher set(double newValue); } diff --git a/redisson/src/main/java/org/redisson/api/RAtomicLong.java b/redisson/src/main/java/org/redisson/api/RAtomicLong.java index 056a21010..21bdf7f0b 100644 --- a/redisson/src/main/java/org/redisson/api/RAtomicLong.java +++ b/redisson/src/main/java/org/redisson/api/RAtomicLong.java @@ -16,7 +16,7 @@ package org.redisson.api; /** - * Distributed alternative to the {@link java.util.concurrent.atomic.AtomicLong} + * Distributed implementation of {@link java.util.concurrent.atomic.AtomicLong} * * @author Nikita Koksharov * @@ -57,7 +57,7 @@ public interface RAtomicLong extends RExpirable, RAtomicLongAsync { long decrementAndGet(); /** - * Gets the current value. + * Returns current value. * * @return the current value */ diff --git a/redisson/src/main/java/org/redisson/api/RAtomicLongAsync.java b/redisson/src/main/java/org/redisson/api/RAtomicLongAsync.java index d03f635ee..b31bae5e7 100644 --- a/redisson/src/main/java/org/redisson/api/RAtomicLongAsync.java +++ b/redisson/src/main/java/org/redisson/api/RAtomicLongAsync.java @@ -16,37 +16,96 @@ package org.redisson.api; /** - * + * Distributed async implementation of {@link java.util.concurrent.atomic.AtomicLong} + * * @author Nikita Koksharov * */ public interface RAtomicLongAsync extends RExpirableAsync { + /** + * Atomically sets the value to the given updated value + * only if the current value {@code ==} the expected value. + * + * @param expect the expected value + * @param update the new value + * @return true if successful; or false if the actual value + * was not equal to the expected value. + */ RFuture compareAndSetAsync(long expect, long update); + /** + * Atomically adds the given value to the current value. + * + * @param delta the value to add + * @return the updated value + */ RFuture addAndGetAsync(long delta); + /** + * Atomically decrements the current value by one. + * + * @return the updated value + */ RFuture decrementAndGetAsync(); + /** + * Returns current value. + * + * @return the current value + */ RFuture getAsync(); /** - * Gets and deletes object + * Returns and deletes object * * @return the current value */ RFuture getAndDeleteAsync(); + /** + * Atomically adds the given value to the current value. + * + * @param delta the value to add + * @return the old value before the add + */ RFuture getAndAddAsync(long delta); + /** + * Atomically sets the given value and returns the old value. + * + * @param newValue the new value + * @return the old value + */ RFuture getAndSetAsync(long newValue); + /** + * Atomically increments the current value by one. + * + * @return the updated value + */ RFuture incrementAndGetAsync(); + /** + * Atomically increments the current value by one. + * + * @return the old value + */ RFuture getAndIncrementAsync(); + /** + * Atomically decrements by one the current value. + * + * @return the previous value + */ RFuture getAndDecrementAsync(); + /** + * Atomically sets the given value. + * + * @param newValue the new value + * @return void + */ RFuture setAsync(long newValue); } diff --git a/redisson/src/main/java/org/redisson/api/RAtomicLongReactive.java b/redisson/src/main/java/org/redisson/api/RAtomicLongReactive.java index da8ac084a..f8da9b859 100644 --- a/redisson/src/main/java/org/redisson/api/RAtomicLongReactive.java +++ b/redisson/src/main/java/org/redisson/api/RAtomicLongReactive.java @@ -18,30 +18,96 @@ package org.redisson.api; import org.reactivestreams.Publisher; /** - * + * Distributed reactive implementation of {@link java.util.concurrent.atomic.AtomicLong} + * * @author Nikita Koksharov * */ public interface RAtomicLongReactive extends RExpirableReactive { + /** + * Atomically sets the value to the given updated value + * only if the current value {@code ==} the expected value. + * + * @param expect the expected value + * @param update the new value + * @return true if successful; or false if the actual value + * was not equal to the expected value. + */ Publisher compareAndSet(long expect, long update); + /** + * Atomically adds the given value to the current value. + * + * @param delta the value to add + * @return the updated value + */ Publisher addAndGet(long delta); + /** + * Atomically decrements the current value by one. + * + * @return the updated value + */ Publisher decrementAndGet(); + /** + * Returns current value. + * + * @return the current value + */ Publisher get(); + /** + * Returns and deletes object + * + * @return the current value + */ + Publisher getAndDelete(); + + /** + * Atomically adds the given value to the current value. + * + * @param delta the value to add + * @return the old value before the add + */ Publisher getAndAdd(long delta); + /** + * Atomically sets the given value and returns the old value. + * + * @param newValue the new value + * @return the old value + */ Publisher getAndSet(long newValue); + /** + * Atomically increments the current value by one. + * + * @return the updated value + */ Publisher incrementAndGet(); + /** + * Atomically increments the current value by one. + * + * @return the old value + */ Publisher getAndIncrement(); + /** + * Atomically decrements by one the current value. + * + * @return the previous value + */ Publisher getAndDecrement(); + /** + * Atomically sets the given value. + * + * @param newValue the new value + * @return void + */ Publisher set(long newValue); } diff --git a/redisson/src/main/java/org/redisson/api/RBatch.java b/redisson/src/main/java/org/redisson/api/RBatch.java index 42cfdb0fa..0cd19574c 100644 --- a/redisson/src/main/java/org/redisson/api/RBatch.java +++ b/redisson/src/main/java/org/redisson/api/RBatch.java @@ -21,7 +21,7 @@ import org.redisson.client.RedisException; import org.redisson.client.codec.Codec; /** - * Interface for using pipeline feature. + * Interface for using Redis pipeline feature. *

* All method invocations on objects got through this interface * are batched to separate queue and could be executed later diff --git a/redisson/src/main/java/org/redisson/api/RBatchReactive.java b/redisson/src/main/java/org/redisson/api/RBatchReactive.java index 0cd4ffd3f..9a26e8494 100644 --- a/redisson/src/main/java/org/redisson/api/RBatchReactive.java +++ b/redisson/src/main/java/org/redisson/api/RBatchReactive.java @@ -21,8 +21,8 @@ import org.reactivestreams.Publisher; import org.redisson.client.codec.Codec; /** - * Interface for using pipeline feature. - * + * Interface for using Redis pipeline feature. + *

* All method invocations on objects * from this interface are batched to separate queue and could be executed later * with execute() method. diff --git a/redisson/src/main/java/org/redisson/api/RBlockingDequeAsync.java b/redisson/src/main/java/org/redisson/api/RBlockingDequeAsync.java index d4a68f687..ede31d971 100644 --- a/redisson/src/main/java/org/redisson/api/RBlockingDequeAsync.java +++ b/redisson/src/main/java/org/redisson/api/RBlockingDequeAsync.java @@ -19,7 +19,7 @@ import java.util.concurrent.BlockingDeque; import java.util.concurrent.TimeUnit; /** - * Async interface for {@link BlockingDeque} backed by Redis + * Distributed async implementation of {@link BlockingDeque} * * @author Nikita Koksharov * @param the type of elements held in this collection @@ -56,15 +56,57 @@ public interface RBlockingDequeAsync extends RDequeAsync, RBlockingQueueAs */ RFuture pollLastFromAnyAsync(long timeout, TimeUnit unit, String ... queueNames); + /** + * Adds value to the head of queue. + * + * @param e value + * @return void + */ RFuture putFirstAsync(V e); + /** + * Adds value to the tail of queue. + * + * @param e value + * @return void + */ RFuture putLastAsync(V e); + /** + * Retrieves and removes value at the tail of queue. If necessary waits up to defined timeout for an element become available. + * + * @param timeout how long to wait before giving up, in units of + * {@code unit} + * @param unit a {@code TimeUnit} determining how to interpret the + * {@code timeout} parameter + * @return the element at the head of this queue, or {@code null} if the + * specified waiting time elapses before an element is available + */ RFuture pollLastAsync(long timeout, TimeUnit unit); - + + /** + * Retrieves and removes value at the tail of queue. Waits for an element become available. + * + * @return the tail element of this queue + */ RFuture takeLastAsync(); + /** + * Retrieves and removes value at the head of queue. If necessary waits up to defined timeout for an element become available. + * + * @param timeout how long to wait before giving up, in units of + * {@code unit} + * @param unit a {@code TimeUnit} determining how to interpret the + * {@code timeout} parameter + * @return the element at the tail of this queue, or {@code null} if the + * specified waiting time elapses before an element is available + */ RFuture pollFirstAsync(long timeout, TimeUnit unit); + /** + * Retrieves and removes value at the head of queue. Waits for an element become available. + * + * @return the head element of this queue + */ RFuture takeFirstAsync(); } diff --git a/redisson/src/main/java/org/redisson/api/RBlockingDequeReactive.java b/redisson/src/main/java/org/redisson/api/RBlockingDequeReactive.java index 548764fc7..dc1fc5fc2 100644 --- a/redisson/src/main/java/org/redisson/api/RBlockingDequeReactive.java +++ b/redisson/src/main/java/org/redisson/api/RBlockingDequeReactive.java @@ -21,7 +21,7 @@ import java.util.concurrent.TimeUnit; import org.reactivestreams.Publisher; /** - * Reactive interface for {@link BlockingDeque} backed by Redis + * Distributed reactive implementation of {@link BlockingDeque} * * @author Nikita Koksharov * @param the type of elements held in this collection @@ -58,15 +58,58 @@ public interface RBlockingDequeReactive extends RDequeReactive, RBlockingQ */ Publisher pollLastFromAny(long timeout, TimeUnit unit, String ... queueNames); + /** + * Adds value to the head of queue. + * + * @param e value + * @return void + */ Publisher putFirst(V e); + /** + * Adds value to the tail of queue. + * + * @param e value + * @return void + */ Publisher putLast(V e); + /** + * Retrieves and removes value at the tail of queue. If necessary waits up to defined timeout for an element become available. + * + * @param timeout how long to wait before giving up, in units of + * {@code unit} + * @param unit a {@code TimeUnit} determining how to interpret the + * {@code timeout} parameter + * @return the element at the head of this queue, or {@code null} if the + * specified waiting time elapses before an element is available + */ Publisher pollLast(long timeout, TimeUnit unit); + /** + * Retrieves and removes value at the tail of queue. Waits for an element become available. + * + * @return the tail element of this queue + */ Publisher takeLast(); + /** + * Retrieves and removes value at the head of queue. If necessary waits up to defined timeout for an element become available. + * + * @param timeout how long to wait before giving up, in units of + * {@code unit} + * @param unit a {@code TimeUnit} determining how to interpret the + * {@code timeout} parameter + * @return the element at the tail of this queue, or {@code null} if the + * specified waiting time elapses before an element is available + */ Publisher pollFirst(long timeout, TimeUnit unit); + /** + * Retrieves and removes value at the head of queue. Waits for an element become available. + * + * @return the head element of this queue + */ Publisher takeFirst(); + } diff --git a/redisson/src/main/java/org/redisson/api/RBlockingQueue.java b/redisson/src/main/java/org/redisson/api/RBlockingQueue.java index 1492895e8..5c4ca172f 100644 --- a/redisson/src/main/java/org/redisson/api/RBlockingQueue.java +++ b/redisson/src/main/java/org/redisson/api/RBlockingQueue.java @@ -19,7 +19,7 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.TimeUnit; /** - * {@link BlockingQueue} backed by Redis + * Distributed implementation of {@link BlockingQueue} * * @author Nikita Koksharov * @param the type of elements held in this collection @@ -29,9 +29,9 @@ public interface RBlockingQueue extends BlockingQueue, RQueue, RBlockin /** * Retrieves and removes first available head element of any queue, * waiting up to the specified wait time if necessary for an element to become available - * in any of defined queues including queue own. + * in any of defined queues including queue itself. * - * @param queueNames - names of queue + * @param queueNames - queue names. Queue name itself is always included * @param timeout how long to wait before giving up, in units of * {@code unit} * @param unit a {@code TimeUnit} determining how to interpret the @@ -42,8 +42,32 @@ public interface RBlockingQueue extends BlockingQueue, RQueue, RBlockin */ V pollFromAny(long timeout, TimeUnit unit, String ... queueNames) throws InterruptedException; + /** + * Retrieves and removes last available tail element of any queue and adds it at the head of queueName, + * waiting up to the specified wait time if necessary for an element to become available + * in any of defined queues including queue itself. + * + * @param queueName - names of destination queue + * @param timeout how long to wait before giving up, in units of + * {@code unit} + * @param unit a {@code TimeUnit} determining how to interpret the + * {@code timeout} parameter + * @return the tail of this queue, or {@code null} if the + * specified waiting time elapses before an element is available + * @throws InterruptedException if interrupted while waiting + */ V pollLastAndOfferFirstTo(String queueName, long timeout, TimeUnit unit) throws InterruptedException; - + + /** + * Retrieves and removes last available tail element of any queue and adds it at the head of queueName, + * waiting if necessary for an element to become available + * in any of defined queues including queue itself. + * + * @param queueName - names of destination queue + * @return the tail of this queue, or {@code null} if the + * specified waiting time elapses before an element is available + * @throws InterruptedException if interrupted while waiting + */ V takeLastAndOfferFirstTo(String queueName) throws InterruptedException; } diff --git a/redisson/src/main/java/org/redisson/api/RBlockingQueueAsync.java b/redisson/src/main/java/org/redisson/api/RBlockingQueueAsync.java index 2a85767ca..770ef6e5b 100644 --- a/redisson/src/main/java/org/redisson/api/RBlockingQueueAsync.java +++ b/redisson/src/main/java/org/redisson/api/RBlockingQueueAsync.java @@ -20,7 +20,7 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.TimeUnit; /** - * {@link BlockingQueue} backed by Redis + * Distributed async implementation of {@link BlockingQueue} * * @author Nikita Koksharov * @param the type of elements held in this collection @@ -30,9 +30,9 @@ public interface RBlockingQueueAsync extends RQueueAsync { /** * Retrieves and removes first available head element of any queue in async mode, * waiting up to the specified wait time if necessary for an element to become available - * in any of defined queues including queue own. + * in any of defined queues including queue itself. * - * @param queueNames - names of queue + * @param queueNames - queue names. Queue name itself is always included * @param timeout how long to wait before giving up, in units of * {@code unit} * @param unit a {@code TimeUnit} determining how to interpret the @@ -92,8 +92,30 @@ public interface RBlockingQueueAsync extends RQueueAsync { */ RFuture drainToAsync(Collection c); + /** + * Retrieves and removes last available tail element of any queue and adds it at the head of queueName, + * waiting up to the specified wait time if necessary for an element to become available + * in any of defined queues including queue itself. + * + * @param queueName - names of destination queue + * @param timeout how long to wait before giving up, in units of + * {@code unit} + * @param unit a {@code TimeUnit} determining how to interpret the + * {@code timeout} parameter + * @return the tail of this queue, or {@code null} if the + * specified waiting time elapses before an element is available + */ RFuture pollLastAndOfferFirstToAsync(String queueName, long timeout, TimeUnit unit); + /** + * Retrieves and removes last available tail element of any queue and adds it at the head of queueName, + * waiting if necessary for an element to become available + * in any of defined queues including queue itself. + * + * @param queueName - names of destination queue + * @return the tail of this queue, or {@code null} if the + * specified waiting time elapses before an element is available + */ RFuture takeLastAndOfferFirstToAsync(String queueName); /** diff --git a/redisson/src/main/java/org/redisson/api/RBlockingQueueReactive.java b/redisson/src/main/java/org/redisson/api/RBlockingQueueReactive.java index 9c257d7d4..f497e2481 100644 --- a/redisson/src/main/java/org/redisson/api/RBlockingQueueReactive.java +++ b/redisson/src/main/java/org/redisson/api/RBlockingQueueReactive.java @@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit; import org.reactivestreams.Publisher; /** - * {@link BlockingQueue} backed by Redis + * Distributed reactive implementation of {@link BlockingQueue} * * @author Nikita Koksharov * @param the type of elements held in this collection @@ -44,16 +44,104 @@ public interface RBlockingQueueReactive extends RQueueReactive { */ Publisher pollFromAny(long timeout, TimeUnit unit, String ... queueNames); + /** + * Removes at most the given number of available elements from + * this queue and adds them to the given collection in async mode. A failure + * encountered while attempting to add elements to + * collection {@code c} may result in elements being in neither, + * either or both collections when the associated exception is + * thrown. Attempts to drain a queue to itself result in + * {@code IllegalArgumentException}. Further, the behavior of + * this operation is undefined if the specified collection is + * modified while the operation is in progress. + * + * @param c the collection to transfer elements into + * @param maxElements the maximum number of elements to transfer + * @return the number of elements transferred + * @throws UnsupportedOperationException if addition of elements + * is not supported by the specified collection + * @throws ClassCastException if the class of an element of this queue + * prevents it from being added to the specified collection + * @throws NullPointerException if the specified collection is null + * @throws IllegalArgumentException if the specified collection is this + * queue, or some property of an element of this queue prevents + * it from being added to the specified collection + */ Publisher drainTo(Collection c, int maxElements); + /** + * Removes all available elements from this queue and adds them + * to the given collection in async mode. This operation may be more + * efficient than repeatedly polling this queue. A failure + * encountered while attempting to add elements to + * collection {@code c} may result in elements being in neither, + * either or both collections when the associated exception is + * thrown. Attempts to drain a queue to itself result in + * {@code IllegalArgumentException}. Further, the behavior of + * this operation is undefined if the specified collection is + * modified while the operation is in progress. + * + * @param c the collection to transfer elements into + * @return the number of elements transferred + * @throws UnsupportedOperationException if addition of elements + * is not supported by the specified collection + * @throws ClassCastException if the class of an element of this queue + * prevents it from being added to the specified collection + * @throws NullPointerException if the specified collection is null + * @throws IllegalArgumentException if the specified collection is this + * queue, or some property of an element of this queue prevents + * it from being added to the specified collection + */ Publisher drainTo(Collection c); + /** + * Retrieves and removes last available tail element of any queue and adds it at the head of queueName, + * waiting up to the specified wait time if necessary for an element to become available + * in any of defined queues including queue itself. + * + * @param queueName - names of destination queue + * @param timeout how long to wait before giving up, in units of + * {@code unit} + * @param unit a {@code TimeUnit} determining how to interpret the + * {@code timeout} parameter + * @return the tail of this queue, or {@code null} if the + * specified waiting time elapses before an element is available + */ Publisher pollLastAndOfferFirstTo(String queueName, long timeout, TimeUnit unit); + /** + * Retrieves and removes the head of this queue in async mode, waiting up to the + * specified wait time if necessary for an element to become available. + * + * @param timeout how long to wait before giving up, in units of + * {@code unit} + * @param unit a {@code TimeUnit} determining how to interpret the + * {@code timeout} parameter + * @return the head of this queue, or {@code null} if the + * specified waiting time elapses before an element is available + */ Publisher poll(long timeout, TimeUnit unit); + /** + * Retrieves and removes the head of this queue in async mode, waiting if necessary + * until an element becomes available. + * + * @return the head of this queue + */ Publisher take(); + /** + * Inserts the specified element into this queue in async mode, waiting if necessary + * for space to become available. + * + * @param e the element to add + * @throws ClassCastException if the class of the specified element + * prevents it from being added to this queue + * @throws NullPointerException if the specified element is null + * @throws IllegalArgumentException if some property of the specified + * element prevents it from being added to this queue + * @return void + */ Publisher put(V e); } diff --git a/redisson/src/main/java/org/redisson/api/RBloomFilter.java b/redisson/src/main/java/org/redisson/api/RBloomFilter.java index c7220cac8..da51d0435 100644 --- a/redisson/src/main/java/org/redisson/api/RBloomFilter.java +++ b/redisson/src/main/java/org/redisson/api/RBloomFilter.java @@ -16,7 +16,7 @@ package org.redisson.api; /** - * Bloom filter based on Highway 128-bit hash. + * Distributed implementation of Bloom filter based on Highway 128-bit hash. * * @author Nikita Koksharov * @@ -24,8 +24,22 @@ package org.redisson.api; */ public interface RBloomFilter extends RExpirable { + /** + * Adds element + * + * @param object - element to add + * @return true if element has been added successfully + * false if element is already present + */ boolean add(T object); + /** + * Check for element present + * + * @param object - element + * @return true if element is present + * false if element is not present + */ boolean contains(T object); /** @@ -33,15 +47,27 @@ public interface RBloomFilter extends RExpirable { * calculated from expectedInsertions and falseProbability * Stores config to Redis server. * - * @param expectedInsertions - expected amount of insertions + * @param expectedInsertions - expected amount of insertions per element * @param falseProbability - expected false probability * @return true if Bloom filter initialized * false if Bloom filter already has been initialized */ boolean tryInit(long expectedInsertions, double falseProbability); + /** + * Returns expected amount of insertions per element. + * Calculated during bloom filter initialization. + * + * @return expected amount of insertions per element + */ long getExpectedInsertions(); + /** + * Returns false probability of element presence. + * Calculated during bloom filter initialization. + * + * @return false probability of element presence + */ double getFalseProbability(); /** @@ -51,6 +77,12 @@ public interface RBloomFilter extends RExpirable { */ long getSize(); + /** + * Returns hash iterations amount used per element. + * Calculated during bloom filter initialization. + * + * @return hash iterations amount + */ int getHashIterations(); /** diff --git a/redisson/src/main/java/org/redisson/api/RBoundedBlockingQueue.java b/redisson/src/main/java/org/redisson/api/RBoundedBlockingQueue.java index d95768232..75206660d 100644 --- a/redisson/src/main/java/org/redisson/api/RBoundedBlockingQueue.java +++ b/redisson/src/main/java/org/redisson/api/RBoundedBlockingQueue.java @@ -18,7 +18,7 @@ package org.redisson.api; import java.util.concurrent.BlockingQueue; /** - * Bounded {@link BlockingQueue} backed by Redis + * Distributed implementation of bounded {@link BlockingQueue} * * @author Nikita Koksharov * @param the type of elements held in this collection diff --git a/redisson/src/main/java/org/redisson/api/RBoundedBlockingQueueAsync.java b/redisson/src/main/java/org/redisson/api/RBoundedBlockingQueueAsync.java index 7f44f3d09..4728158ff 100644 --- a/redisson/src/main/java/org/redisson/api/RBoundedBlockingQueueAsync.java +++ b/redisson/src/main/java/org/redisson/api/RBoundedBlockingQueueAsync.java @@ -19,7 +19,7 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.TimeUnit; /** - * Bounded {@link BlockingQueue} backed by Redis + * Distributed async implementation of bounded {@link BlockingQueue} * * @author Nikita Koksharov * @param the type of elements held in this collection diff --git a/redisson/src/main/java/org/redisson/api/RBucket.java b/redisson/src/main/java/org/redisson/api/RBucket.java index 26a094b52..30ced34be 100644 --- a/redisson/src/main/java/org/redisson/api/RBucket.java +++ b/redisson/src/main/java/org/redisson/api/RBucket.java @@ -18,7 +18,7 @@ package org.redisson.api; import java.util.concurrent.TimeUnit; /** - * Any object holder. Max size of object is 512MB + * Object holder. Max size of object is 512MB * * @author Nikita Koksharov * @@ -27,26 +27,80 @@ import java.util.concurrent.TimeUnit; public interface RBucket extends RExpirable, RBucketAsync { /** - * Returns size of object in bytes + * Returns size of object in bytes. * * @return object size */ long size(); + /** + * Retrieves element stored in the holder. + * + * @return element + */ V get(); + /** + * Retrieves element in the holder and removes it. + * + * @return element + */ V getAndDelete(); - + + /** + * Tries to set element atomically into empty holder. + * + * @param value - value to set + * @return {@code true} if successful, or {@code false} if + * element was already set + */ boolean trySet(V value); + /** + * Tries to set element atomically into empty holder with defined timeToLive interval. + * + * @param value - value to set + * @param timeToLive - time to live interval + * @param timeUnit - unit of time to live interval + * @return {@code true} if successful, or {@code false} if + * element was already set + */ boolean trySet(V value, long timeToLive, TimeUnit timeUnit); + /** + * Atomically sets the value to the given updated value + * only if serialized state of the current value equals + * to serialized state of the expected value. + * + * @param expect the expected value + * @param update the new value + * @return {@code true} if successful; or {@code false} if the actual value + * was not equal to the expected value. + */ boolean compareAndSet(V expect, V update); + /** + * Retrieves current element in the holder and replaces it with newValue. + * + * @param newValue - value to set + * @return previous value + */ V getAndSet(V newValue); + /** + * Stores element into the holder. + * + * @param value - value to set + */ void set(V value); + /** + * Stores element into the holder with defined timeToLive interval. + * + * @param value - value to set + * @param timeToLive - time to live interval + * @param timeUnit - unit of time to live interval + */ void set(V value, long timeToLive, TimeUnit timeUnit); } diff --git a/redisson/src/main/java/org/redisson/api/RBucketAsync.java b/redisson/src/main/java/org/redisson/api/RBucketAsync.java index 29d78073c..82a06ce6a 100644 --- a/redisson/src/main/java/org/redisson/api/RBucketAsync.java +++ b/redisson/src/main/java/org/redisson/api/RBucketAsync.java @@ -18,7 +18,7 @@ package org.redisson.api; import java.util.concurrent.TimeUnit; /** - * Async object functions + * Async implementation of object holder. Max size of object is 512MB * * @author Nikita Koksharov * @@ -33,20 +33,76 @@ public interface RBucketAsync extends RExpirableAsync { */ RFuture sizeAsync(); + /** + * Retrieves element stored in the holder. + * + * @return element + */ RFuture getAsync(); + /** + * Retrieves element in the holder and removes it. + * + * @return element + */ RFuture getAndDeleteAsync(); + /** + * Tries to set element atomically into empty holder. + * + * @param value - value to set + * @return {@code true} if successful, or {@code false} if + * element was already set + */ RFuture trySetAsync(V value); + /** + * Tries to set element atomically into empty holder with defined timeToLive interval. + * + * @param value - value to set + * @param timeToLive - time to live interval + * @param timeUnit - unit of time to live interval + * @return {@code true} if successful, or {@code false} if + * element was already set + */ RFuture trySetAsync(V value, long timeToLive, TimeUnit timeUnit); + /** + * Atomically sets the value to the given updated value + * only if serialized state of the current value equals + * to serialized state of the expected value. + * + * @param expect the expected value + * @param update the new value + * @return {@code true} if successful; or {@code false} if the actual value + * was not equal to the expected value. + */ RFuture compareAndSetAsync(V expect, V update); + /** + * Retrieves current element in the holder and replaces it with newValue. + * + * @param newValue - value to set + * @return previous value + */ RFuture getAndSetAsync(V newValue); + /** + * Stores element into the holder. + * + * @param value - value to set + * @return void + */ RFuture setAsync(V value); + /** + * Stores element into the holder with defined timeToLive interval. + * + * @param value - value to set + * @param timeToLive - time to live interval + * @param timeUnit - unit of time to live interval + * @return void + */ RFuture setAsync(V value, long timeToLive, TimeUnit timeUnit); } diff --git a/redisson/src/main/java/org/redisson/api/RBucketReactive.java b/redisson/src/main/java/org/redisson/api/RBucketReactive.java index 6879be489..466347eaf 100644 --- a/redisson/src/main/java/org/redisson/api/RBucketReactive.java +++ b/redisson/src/main/java/org/redisson/api/RBucketReactive.java @@ -21,7 +21,7 @@ import org.reactivestreams.Publisher; /** - * Object holder. Max size of object is 512MB + * Reactive implementation of object holder. Max size of object is 512MB * * @author Nikita Koksharov * @@ -36,20 +36,76 @@ public interface RBucketReactive extends RExpirableReactive { */ Publisher size(); + /** + * Tries to set element atomically into empty holder. + * + * @param value - value to set + * @return {@code true} if successful, or {@code false} if + * element was already set + */ Publisher trySet(V value); + /** + * Tries to set element atomically into empty holder with defined timeToLive interval. + * + * @param value - value to set + * @param timeToLive - time to live interval + * @param timeUnit - unit of time to live interval + * @return {@code true} if successful, or {@code false} if + * element was already set + */ Publisher trySet(V value, long timeToLive, TimeUnit timeUnit); + /** + * Atomically sets the value to the given updated value + * only if serialized state of the current value equals + * to serialized state of the expected value. + * + * @param expect the expected value + * @param update the new value + * @return {@code true} if successful; or {@code false} if the actual value + * was not equal to the expected value. + */ Publisher compareAndSet(V expect, V update); + /** + * Retrieves current element in the holder and replaces it with newValue. + * + * @param newValue - value to set + * @return previous value + */ Publisher getAndSet(V newValue); + /** + * Retrieves element stored in the holder. + * + * @return element + */ Publisher get(); + /** + * Retrieves element in the holder and removes it. + * + * @return element + */ Publisher getAndDelete(); + /** + * Stores element into the holder. + * + * @param value - value to set + * @return void + */ Publisher set(V value); + /** + * Stores element into the holder with defined timeToLive interval. + * + * @param value - value to set + * @param timeToLive - time to live interval + * @param timeUnit - unit of time to live interval + * @return void + */ Publisher set(V value, long timeToLive, TimeUnit timeUnit); } diff --git a/redisson/src/main/java/org/redisson/api/RBuckets.java b/redisson/src/main/java/org/redisson/api/RBuckets.java index c50106b64..ff24e2bd7 100644 --- a/redisson/src/main/java/org/redisson/api/RBuckets.java +++ b/redisson/src/main/java/org/redisson/api/RBuckets.java @@ -15,22 +15,16 @@ */ package org.redisson.api; -import java.util.List; import java.util.Map; /** + * Operations over multiple Bucket objects. * * @author Nikita Koksharov * */ public interface RBuckets extends RBucketsAsync { - /* - * Use RKeys.findKeysByPattern method instead - */ - @Deprecated - List> find(String pattern); - /** * Returns Redis object mapped by key. Result Map is not contains * key-value entry for null values. diff --git a/redisson/src/main/java/org/redisson/api/RBucketsAsync.java b/redisson/src/main/java/org/redisson/api/RBucketsAsync.java index 705fe92b9..f16cef19d 100644 --- a/redisson/src/main/java/org/redisson/api/RBucketsAsync.java +++ b/redisson/src/main/java/org/redisson/api/RBucketsAsync.java @@ -18,6 +18,7 @@ package org.redisson.api; import java.util.Map; /** + * Operations over multiple Bucket objects. * * @author Nikita Koksharov * @@ -48,6 +49,7 @@ public interface RBucketsAsync { * Saves objects mapped by Redis key. * * @param buckets - map of buckets + * @return void */ RFuture setAsync(Map buckets); diff --git a/redisson/src/main/java/org/redisson/api/RCollectionAsync.java b/redisson/src/main/java/org/redisson/api/RCollectionAsync.java index 082e38527..0e3e626d8 100644 --- a/redisson/src/main/java/org/redisson/api/RCollectionAsync.java +++ b/redisson/src/main/java/org/redisson/api/RCollectionAsync.java @@ -18,6 +18,7 @@ package org.redisson.api; import java.util.Collection; /** + * Common async interface for collection object * * @author Nikita Koksharov * @@ -27,9 +28,7 @@ public interface RCollectionAsync extends RExpirableAsync { /** * Retains only the elements in this collection that are contained in the - * specified collection (optional operation). In other words, removes from - * this collection all of its elements that are not contained in the - * specified collection. + * specified collection (optional operation). * * @param c collection containing elements to be retained in this collection * @return true if this collection changed as a result of the call @@ -38,61 +37,65 @@ public interface RCollectionAsync extends RExpirableAsync { /** * Removes all of this collection's elements that are also contained in the - * specified collection (optional operation). After this call returns, - * this collection will contain no elements in common with the specified - * collection. + * specified collection (optional operation). * * @param c collection containing elements to be removed from this collection - * @return true if this collection changed as a result of the + * @return true if this collection changed as a result of the * call */ RFuture removeAllAsync(Collection c); /** - * Returns true if this collection contains the specified element. - * More formally, returns true if and only if this collection - * contains at least one element e such that - * (o==null ? e==null : o.equals(e)). + * Returns true if this collection contains encoded state of the specified element. * * @param o element whose presence in this collection is to be tested - * @return true if this collection contains the specified - * element + * @return true if this collection contains the specified + * element and false otherwise */ RFuture containsAsync(Object o); /** - * Returns true if this collection contains all of the elements + * Returns true if this collection contains all of the elements * in the specified collection. * * @param c collection to be checked for containment in this collection - * @return true if this collection contains all of the elements + * @return true if this collection contains all of the elements * in the specified collection */ RFuture containsAllAsync(Collection c); /** * Removes a single instance of the specified element from this - * collection, if it is present (optional operation). More formally, - * removes an element e such that - * (o==null ? e==null : o.equals(e)), if - * this collection contains one or more such elements. Returns - * true if this collection contained the specified element (or - * equivalently, if this collection changed as a result of the call). + * collection, if it is present (optional operation). * * @param o element to be removed from this collection, if present - * @return true if an element was removed as a result of this call + * @return true if an element was removed as a result of this call */ RFuture removeAsync(Object o); /** - * Returns the number of elements in this collection. + * Returns number of elements in this collection. * * @return size of collection */ RFuture sizeAsync(); + /** + * Adds element into this collection. + * + * @param e - element to add + * @return true if an element was added + * and false if it is already present + */ RFuture addAsync(V e); + /** + * Adds all elements contained in the specified collection + * + * @param c - collection of elements to add + * @return true if at least one element was added + * and false if all elements are already present + */ RFuture addAllAsync(Collection c); } diff --git a/redisson/src/main/java/org/redisson/api/RCollectionReactive.java b/redisson/src/main/java/org/redisson/api/RCollectionReactive.java index 5238d89f3..7868b68b7 100644 --- a/redisson/src/main/java/org/redisson/api/RCollectionReactive.java +++ b/redisson/src/main/java/org/redisson/api/RCollectionReactive.java @@ -20,6 +20,7 @@ import java.util.Collection; import org.reactivestreams.Publisher; /** + * Common reactive interface for collection object * * @author Nikita Koksharov * @@ -27,24 +28,92 @@ import org.reactivestreams.Publisher; */ public interface RCollectionReactive extends RExpirableReactive { + /** + * Returns iterator over collection elements + * + * @return iterator + */ Publisher iterator(); + /** + * Retains only the elements in this collection that are contained in the + * specified collection (optional operation). + * + * @param c collection containing elements to be retained in this collection + * @return true if this collection changed as a result of the call + */ Publisher retainAll(Collection c); + /** + * Removes all of this collection's elements that are also contained in the + * specified collection (optional operation). + * + * @param c collection containing elements to be removed from this collection + * @return true if this collection changed as a result of the + * call + */ Publisher removeAll(Collection c); + /** + * Returns true if this collection contains encoded state of the specified element. + * + * @param o element whose presence in this collection is to be tested + * @return true if this collection contains the specified + * element and false otherwise + */ Publisher contains(V o); + /** + * Returns true if this collection contains all of the elements + * in the specified collection. + * + * @param c collection to be checked for containment in this collection + * @return true if this collection contains all of the elements + * in the specified collection + */ Publisher containsAll(Collection c); + /** + * Removes a single instance of the specified element from this + * collection, if it is present (optional operation). + * + * @param o element to be removed from this collection, if present + * @return true if an element was removed as a result of this call + */ Publisher remove(V o); + /** + * Returns number of elements in this collection. + * + * @return size of collection + */ Publisher size(); + /** + * Adds element into this collection. + * + * @param e - element to add + * @return true if an element was added + * and false if it is already present + */ Publisher add(V e); + /** + * Adds all elements contained in the specified collection + * + * @param c - collection of elements to add + * @return true if at least one element was added + * and false if all elements are already present + */ Publisher addAll(Publisher c); - + + /** + * Adds all elements contained in the specified collection + * + * @param c - collection of elements to add + * @return true if at least one element was added + * and false if all elements are already present + */ Publisher addAll(Collection c); } diff --git a/redisson/src/main/java/org/redisson/api/RTransactionReactive.java b/redisson/src/main/java/org/redisson/api/RTransactionReactive.java index db6418687..b250c406a 100644 --- a/redisson/src/main/java/org/redisson/api/RTransactionReactive.java +++ b/redisson/src/main/java/org/redisson/api/RTransactionReactive.java @@ -146,11 +146,14 @@ public interface RTransactionReactive { /** * Commits all changes made on this transaction. + * + * @return void */ Publisher commit(); /** * Rollback all changes made on this transaction. + * @return void */ Publisher rollback(); diff --git a/redisson/src/main/java/org/redisson/reactive/RedissonAtomicDoubleReactive.java b/redisson/src/main/java/org/redisson/reactive/RedissonAtomicDoubleReactive.java index e359e68d4..5c1767890 100644 --- a/redisson/src/main/java/org/redisson/reactive/RedissonAtomicDoubleReactive.java +++ b/redisson/src/main/java/org/redisson/reactive/RedissonAtomicDoubleReactive.java @@ -129,6 +129,16 @@ public class RedissonAtomicDoubleReactive extends RedissonExpirableReactive impl } }); } + + @Override + public Publisher getAndDelete() { + return reactive(new Supplier>() { + @Override + public RFuture get() { + return instance.getAndDeleteAsync(); + } + }); + } public String toString() { return instance.toString(); diff --git a/redisson/src/main/java/org/redisson/reactive/RedissonAtomicLongReactive.java b/redisson/src/main/java/org/redisson/reactive/RedissonAtomicLongReactive.java index 351df6f21..36aae6e2e 100644 --- a/redisson/src/main/java/org/redisson/reactive/RedissonAtomicLongReactive.java +++ b/redisson/src/main/java/org/redisson/reactive/RedissonAtomicLongReactive.java @@ -88,6 +88,15 @@ public class RedissonAtomicLongReactive extends RedissonExpirableReactive implem }); } + @Override + public Publisher getAndDelete() { + return reactive(new Supplier>() { + @Override + public RFuture get() { + return instance.getAndDeleteAsync(); + } + }); + } @Override public Publisher getAndSet(final long newValue) {