Package org.redisson
Class RedissonPriorityBlockingQueue<V>
- java.lang.Object
-
- org.redisson.RedissonObject
-
- org.redisson.RedissonList<V>
-
- org.redisson.RedissonPriorityQueue<V>
-
- org.redisson.RedissonPriorityBlockingQueue<V>
-
- All Implemented Interfaces:
Iterable<V>
,Collection<V>
,BlockingQueue<V>
,List<V>
,Queue<V>
,RandomAccess
,RBlockingQueue<V>
,RBlockingQueueAsync<V>
,RCollectionAsync<V>
,RExpirable
,RExpirableAsync
,RList<V>
,RListAsync<V>
,RObject
,RObjectAsync
,RPriorityBlockingQueue<V>
,RPriorityQueue<V>
,RQueue<V>
,RQueueAsync<V>
,RSortable<List<V>>
,RSortableAsync<List<V>>
public class RedissonPriorityBlockingQueue<V> extends RedissonPriorityQueue<V> implements RPriorityBlockingQueue<V>
Distributed and concurrent implementation of
PriorityBlockingQueue
.Queue size limited by Redis server memory amount. This is why
remainingCapacity()
always returnsInteger.MAX_VALUE
- Author:
- Nikita Koksharov
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.redisson.RedissonPriorityQueue
RedissonPriorityQueue.BinarySearchResult<V>
-
-
Field Summary
-
Fields inherited from class org.redisson.RedissonObject
codec, name
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
RedissonPriorityBlockingQueue(Codec codec, CommandAsyncExecutor commandExecutor, String name, RedissonClient redisson)
protected
RedissonPriorityBlockingQueue(CommandAsyncExecutor commandExecutor, String name, RedissonClient redisson)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
clearExpire()
Clear an expire timeout or expire date for object.protected RFuture<Boolean>
clearExpireAsync(String... keys)
int
drainTo(Collection<? super V> c)
int
drainTo(Collection<? super V> c, int maxElements)
RFuture<Integer>
drainToAsync(Collection<? super V> c)
Removes all available elements from this queue and adds them to the given collection in async mode.RFuture<Integer>
drainToAsync(Collection<? super V> c, int maxElements)
Removes at most the given number of available elements from this queue and adds them to the given collection in async mode.boolean
expire(long timeToLive, TimeUnit timeUnit)
Set a timeout for object.boolean
expire(Instant instant)
Set an expire date for object.protected RFuture<Boolean>
expireAsync(long timeToLive, TimeUnit timeUnit, String... keys)
RFuture<Boolean>
expireAsync(Instant instant)
Set an expire date for object.boolean
expireAt(long timestamp)
UseRExpirable.expire(Instant)
insteadboolean
expireAt(Date timestamp)
UseRExpirable.expire(Instant)
insteadRFuture<Boolean>
expireAtAsync(long timestamp)
UseRExpirableAsync.expireAsync(Instant)
insteadRFuture<Boolean>
expireAtAsync(Date timestamp)
UseRExpirableAsync.expireAsync(Instant)
insteadboolean
offer(V e, long timeout, TimeUnit unit)
RFuture<Boolean>
offerAsync(V e)
Inserts the specified element into this queue.List<V>
poll(int limit)
Retrieves and removes the head elements of this queue.V
poll(long timeout, TimeUnit unit)
RFuture<List<V>>
pollAsync(int limit)
Retrieves and removes the head elements of this queue.RFuture<V>
pollAsync(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.V
pollFromAny(long timeout, TimeUnit unit, String... queueNames)
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 itself.RFuture<V>
pollFromAnyAsync(long timeout, TimeUnit unit, String... queueNames)
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 itself.V
pollLastAndOfferFirstTo(String queueName, long timeout, TimeUnit unit)
Retrieves and removes last available tail element of this queue and adds it at the head ofqueueName
, waiting up to the specified wait time if necessary for an element to become available.RFuture<V>
pollLastAndOfferFirstToAsync(String queueName, long timeout, TimeUnit unit)
Retrieves and removes last available tail element of this queue and adds it at the head ofqueueName
, waiting up to the specified wait time if necessary for an element to become available.void
put(V e)
RFuture<Void>
putAsync(V e)
Inserts the specified element into this queue in async mode, waiting if necessary for space to become available.int
remainingCapacity()
long
remainTimeToLive()
Remaining time to live of Redisson object that has a timeoutRFuture<Long>
remainTimeToLiveAsync()
Remaining time to live of Redisson object that has a timeoutint
subscribeOnElements(Consumer<V> consumer)
Subscribes on elements appeared in this queue.V
take()
RFuture<V>
takeAsync()
Retrieves and removes the head of this queue in async mode, waiting if necessary until an element becomes available.protected <T> void
takeAsync(RPromise<V> result, long delay, long timeoutInMicro, RedisCommand<T> command, Object... params)
V
takeLastAndOfferFirstTo(String queueName)
Retrieves and removes last available tail element of any queue and adds it at the head ofqueueName
, waiting if necessary for an element to become available in any of defined queues including queue itself.RFuture<V>
takeLastAndOfferFirstToAsync(String queueName)
Retrieves and removes last available tail element of any queue and adds it at the head ofqueueName
, waiting if necessary for an element to become available in any of defined queues including queue itself.void
unsubscribe(int listenerId)
Un-subscribes defined listener.-
Methods inherited from class org.redisson.RedissonPriorityQueue
add, addAll, addAsync, binarySearch, clear, clearExpireAsync, comparator, contains, containsAll, deleteAsync, element, expireAsync, expireAtAsync, getFirst, offer, peek, peekAsync, poll, pollAsync, pollLastAndOfferFirstTo, pollLastAndOfferFirstToAsync, remove, remove, removeAll, removeFirst, retainAll, toString, trySetComparator, wrapLockedAsync, wrapLockedAsync
-
Methods inherited from class org.redisson.RedissonList
add, addAfter, addAfterAsync, addAll, addAllAsync, addAllAsync, addAsync, addAsync, addBefore, addBeforeAsync, addListener, addListenerAsync, containsAllAsync, containsAsync, equals, fastRemove, fastRemoveAsync, fastSet, fastSetAsync, get, get, getAsync, getAsync, hashCode, indexOf, indexOfAsync, indexOfAsync, isEmpty, iterator, lastIndexOf, lastIndexOfAsync, lastIndexOfAsync, listIterator, listIterator, mapReduce, range, range, rangeAsync, rangeAsync, readAll, readAllAsync, readSort, readSort, readSort, readSort, readSort, readSort, readSortAlpha, readSortAlpha, readSortAlpha, readSortAlpha, readSortAlpha, readSortAlpha, readSortAlphaAsync, readSortAlphaAsync, readSortAlphaAsync, readSortAlphaAsync, readSortAlphaAsync, readSortAlphaAsync, readSortAsync, readSortAsync, readSortAsync, readSortAsync, readSortAsync, readSortAsync, remove, remove, removeAllAsync, removeAsync, removeAsync, removeAsync, removeIf, removeListener, removeListenerAsync, retainAllAsync, set, setAsync, size, sizeAsync, sortTo, sortTo, sortTo, sortTo, sortTo, sortTo, sortToAsync, sortToAsync, sortToAsync, sortToAsync, sortToAsync, sortToAsync, subList, toArray, toArray, trim, trimAsync
-
Methods inherited from class org.redisson.RedissonObject
addListener, addListenerAsync, copy, copyAsync, delete, deleteAsync, dump, dumpAsync, encode, encode, encode, encode, encodeMapKey, encodeMapKeys, encodeMapValue, encodeMapValues, get, getCodec, getIdleTime, getIdleTimeAsync, getLockByMapKey, getLockByValue, getName, getRawName, getRawName, isExists, isExistsAsync, migrate, migrateAsync, move, moveAsync, prefixName, removeListenersAsync, rename, renameAsync, renamenx, renamenxAsync, restore, restore, restoreAndReplace, restoreAndReplace, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, setName, sizeInMemory, sizeInMemoryAsync, sizeInMemoryAsync, sizeInMemoryAsync, suffixName, toSeconds, toStream, touch, touchAsync, unlink, unlinkAsync
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.BlockingQueue
add, contains, offer, remove
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
replaceAll, sort, spliterator
-
Methods inherited from interface org.redisson.api.RCollectionAsync
addAllAsync, addAsync, containsAllAsync, containsAsync, removeAllAsync, removeAsync, retainAllAsync, sizeAsync
-
Methods inherited from interface org.redisson.api.RExpirable
clearExpire, expire, expire, expireAt, expireAt, remainTimeToLive
-
Methods inherited from interface org.redisson.api.RExpirableAsync
clearExpireAsync, expireAsync, expireAsync, expireAtAsync, expireAtAsync, remainTimeToLiveAsync
-
Methods inherited from interface org.redisson.api.RObject
copy, delete, dump, getCodec, getIdleTime, getName, isExists, migrate, move, removeListener, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, sizeInMemory, touch, unlink
-
Methods inherited from interface org.redisson.api.RObjectAsync
copyAsync, deleteAsync, dumpAsync, getIdleTimeAsync, isExistsAsync, migrateAsync, moveAsync, removeListenerAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, sizeInMemoryAsync, touchAsync, unlinkAsync
-
Methods inherited from interface org.redisson.api.RPriorityQueue
comparator, pollLastAndOfferFirstTo, readAll, trySetComparator
-
Methods inherited from interface org.redisson.api.RQueue
addListener
-
Methods inherited from interface org.redisson.api.RQueueAsync
addListenerAsync, peekAsync, pollAsync, pollLastAndOfferFirstToAsync, readAllAsync
-
-
-
-
Constructor Detail
-
RedissonPriorityBlockingQueue
protected RedissonPriorityBlockingQueue(CommandAsyncExecutor commandExecutor, String name, RedissonClient redisson)
-
RedissonPriorityBlockingQueue
protected RedissonPriorityBlockingQueue(Codec codec, CommandAsyncExecutor commandExecutor, String name, RedissonClient redisson)
-
-
Method Detail
-
put
public void put(V e) throws InterruptedException
- Specified by:
put
in interfaceBlockingQueue<V>
- Throws:
InterruptedException
-
offer
public boolean offer(V e, long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
offer
in interfaceBlockingQueue<V>
- Throws:
InterruptedException
-
takeAsync
public RFuture<V> takeAsync()
Description copied from interface:RBlockingQueueAsync
Retrieves and removes the head of this queue in async mode, waiting if necessary until an element becomes available.- Specified by:
takeAsync
in interfaceRBlockingQueueAsync<V>
- Returns:
- the head of this queue
-
takeAsync
protected <T> void takeAsync(RPromise<V> result, long delay, long timeoutInMicro, RedisCommand<T> command, Object... params)
-
take
public V take() throws InterruptedException
- Specified by:
take
in interfaceBlockingQueue<V>
- Throws:
InterruptedException
-
pollAsync
public RFuture<V> pollAsync(long timeout, TimeUnit unit)
Description copied from interface:RBlockingQueueAsync
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.- Specified by:
pollAsync
in interfaceRBlockingQueueAsync<V>
- Parameters:
timeout
- how long to wait before giving up, in units ofunit
unit
- aTimeUnit
determining how to interpret thetimeout
parameter- Returns:
- the head of this queue, or
null
if the specified waiting time elapses before an element is available
-
poll
public V poll(long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
poll
in interfaceBlockingQueue<V>
- Throws:
InterruptedException
-
pollFromAny
public V pollFromAny(long timeout, TimeUnit unit, String... queueNames) throws InterruptedException
Description copied from interface:RBlockingQueue
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 itself.- Specified by:
pollFromAny
in interfaceRBlockingQueue<V>
- Parameters:
timeout
- how long to wait before giving up, in units ofunit
unit
- aTimeUnit
determining how to interpret thetimeout
parameterqueueNames
- - queue names. Queue name itself is always included- Returns:
- the head of this queue, or
null
if the specified waiting time elapses before an element is available - Throws:
InterruptedException
- if interrupted while waiting
-
pollLastAndOfferFirstToAsync
public RFuture<V> pollLastAndOfferFirstToAsync(String queueName, long timeout, TimeUnit unit)
Description copied from interface:RBlockingQueueAsync
Retrieves and removes last available tail element of this queue and adds it at the head ofqueueName
, waiting up to the specified wait time if necessary for an element to become available.- Specified by:
pollLastAndOfferFirstToAsync
in interfaceRBlockingQueueAsync<V>
- Parameters:
queueName
- - names of destination queuetimeout
- how long to wait before giving up, in units ofunit
unit
- aTimeUnit
determining how to interpret thetimeout
parameter- Returns:
- the tail of this queue, or
null
if the specified waiting time elapses before an element is available
-
pollLastAndOfferFirstTo
public V pollLastAndOfferFirstTo(String queueName, long timeout, TimeUnit unit) throws InterruptedException
Description copied from interface:RBlockingQueue
Retrieves and removes last available tail element of this queue and adds it at the head ofqueueName
, waiting up to the specified wait time if necessary for an element to become available.- Specified by:
pollLastAndOfferFirstTo
in interfaceRBlockingQueue<V>
- Parameters:
queueName
- - names of destination queuetimeout
- how long to wait before giving up, in units ofunit
unit
- aTimeUnit
determining how to interpret thetimeout
parameter- Returns:
- the tail of this queue, or
null
if the specified waiting time elapses before an element is available - Throws:
InterruptedException
- if interrupted while waiting
-
takeLastAndOfferFirstTo
public V takeLastAndOfferFirstTo(String queueName) throws InterruptedException
Description copied from interface:RBlockingQueue
Retrieves and removes last available tail element of any queue and adds it at the head ofqueueName
, waiting if necessary for an element to become available in any of defined queues including queue itself.- Specified by:
takeLastAndOfferFirstTo
in interfaceRBlockingQueue<V>
- Parameters:
queueName
- - names of destination queue- Returns:
- the tail of this queue, or
null
if the specified waiting time elapses before an element is available - Throws:
InterruptedException
- if interrupted while waiting
-
subscribeOnElements
public int subscribeOnElements(Consumer<V> consumer)
Description copied from interface:RBlockingQueue
Subscribes on elements appeared in this queue. Continuously invokesRBlockingQueueAsync.takeAsync()
method to get a new element.- Specified by:
subscribeOnElements
in interfaceRBlockingQueue<V>
- Parameters:
consumer
- - queue elements listener- Returns:
- listenerId - id of listener
-
unsubscribe
public void unsubscribe(int listenerId)
Description copied from interface:RBlockingQueue
Un-subscribes defined listener.- Specified by:
unsubscribe
in interfaceRBlockingQueue<V>
- Parameters:
listenerId
- - id of listener
-
takeLastAndOfferFirstToAsync
public RFuture<V> takeLastAndOfferFirstToAsync(String queueName)
Description copied from interface:RBlockingQueueAsync
Retrieves and removes last available tail element of any queue and adds it at the head ofqueueName
, waiting if necessary for an element to become available in any of defined queues including queue itself.- Specified by:
takeLastAndOfferFirstToAsync
in interfaceRBlockingQueueAsync<V>
- Parameters:
queueName
- - names of destination queue- Returns:
- the tail of this queue, or
null
if the specified waiting time elapses before an element is available
-
remainingCapacity
public int remainingCapacity()
- Specified by:
remainingCapacity
in interfaceBlockingQueue<V>
-
drainTo
public int drainTo(Collection<? super V> c)
- Specified by:
drainTo
in interfaceBlockingQueue<V>
-
drainToAsync
public RFuture<Integer> drainToAsync(Collection<? super V> c)
Description copied from interface:RBlockingQueueAsync
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 collectionc
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 inIllegalArgumentException
. Further, the behavior of this operation is undefined if the specified collection is modified while the operation is in progress.- Specified by:
drainToAsync
in interfaceRBlockingQueueAsync<V>
- Parameters:
c
- the collection to transfer elements into- Returns:
- the number of elements transferred
-
drainTo
public int drainTo(Collection<? super V> c, int maxElements)
- Specified by:
drainTo
in interfaceBlockingQueue<V>
-
drainToAsync
public RFuture<Integer> drainToAsync(Collection<? super V> c, int maxElements)
Description copied from interface:RBlockingQueueAsync
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 collectionc
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 inIllegalArgumentException
. Further, the behavior of this operation is undefined if the specified collection is modified while the operation is in progress.- Specified by:
drainToAsync
in interfaceRBlockingQueueAsync<V>
- Parameters:
c
- the collection to transfer elements intomaxElements
- the maximum number of elements to transfer- Returns:
- the number of elements transferred
-
offerAsync
public RFuture<Boolean> offerAsync(V e)
Description copied from interface:RQueueAsync
Inserts the specified element into this queue.- Specified by:
offerAsync
in interfaceRQueueAsync<V>
- Overrides:
offerAsync
in classRedissonPriorityQueue<V>
- Parameters:
e
- the element to add- Returns:
true
if successful, orfalse
-
pollAsync
public RFuture<List<V>> pollAsync(int limit)
Description copied from interface:RQueueAsync
Retrieves and removes the head elements of this queue. Elements amount limited bylimit
param.- Specified by:
pollAsync
in interfaceRQueueAsync<V>
- Overrides:
pollAsync
in classRedissonPriorityQueue<V>
- Returns:
- list of head elements
-
pollFromAnyAsync
public RFuture<V> pollFromAnyAsync(long timeout, TimeUnit unit, String... queueNames)
Description copied from interface:RBlockingQueueAsync
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 itself.- Specified by:
pollFromAnyAsync
in interfaceRBlockingQueueAsync<V>
- Parameters:
timeout
- how long to wait before giving up, in units ofunit
unit
- aTimeUnit
determining how to interpret thetimeout
parameterqueueNames
- - queue names. Queue name itself is always included- Returns:
- Future object with the head of this queue, or
null
if the specified waiting time elapses before an element is available
-
putAsync
public RFuture<Void> putAsync(V e)
Description copied from interface:RBlockingQueueAsync
Inserts the specified element into this queue in async mode, waiting if necessary for space to become available.- Specified by:
putAsync
in interfaceRBlockingQueueAsync<V>
- Parameters:
e
- the element to add- Returns:
- void
-
poll
public List<V> poll(int limit)
Description copied from interface:RQueue
Retrieves and removes the head elements of this queue. Elements amount limited bylimit
param.
-
expire
public boolean expire(long timeToLive, TimeUnit timeUnit)
Description copied from interface:RExpirable
Set a timeout for object. After the timeout has expired, the key will automatically be deleted.- Specified by:
expire
in interfaceRExpirable
- Parameters:
timeToLive
- - timeout before object will be deletedtimeUnit
- - timeout time unit- Returns:
true
if the timeout was set andfalse
if not
-
expireAt
public boolean expireAt(long timestamp)
Description copied from interface:RExpirable
UseRExpirable.expire(Instant)
instead- Specified by:
expireAt
in interfaceRExpirable
- Parameters:
timestamp
- - expire date in milliseconds (Unix timestamp)- Returns:
true
if the timeout was set andfalse
if not
-
expireAtAsync
public RFuture<Boolean> expireAtAsync(long timestamp)
Description copied from interface:RExpirableAsync
UseRExpirableAsync.expireAsync(Instant)
instead- Specified by:
expireAtAsync
in interfaceRExpirableAsync
- Parameters:
timestamp
- - expire date in milliseconds (Unix timestamp)- Returns:
true
if the timeout was set andfalse
if not
-
expire
public boolean expire(Instant instant)
Description copied from interface:RExpirable
Set an expire date for object. When expire date comes the key will automatically be deleted.- Specified by:
expire
in interfaceRExpirable
- Parameters:
instant
- - expire date- Returns:
true
if the timeout was set andfalse
if not
-
expireAsync
public RFuture<Boolean> expireAsync(Instant instant)
Description copied from interface:RExpirableAsync
Set an expire date for object. When expire date comes the key will automatically be deleted.- Specified by:
expireAsync
in interfaceRExpirableAsync
- Parameters:
instant
- - expire date- Returns:
true
if the timeout was set andfalse
if not
-
expireAt
public boolean expireAt(Date timestamp)
Description copied from interface:RExpirable
UseRExpirable.expire(Instant)
instead- Specified by:
expireAt
in interfaceRExpirable
- Parameters:
timestamp
- - expire date- Returns:
true
if the timeout was set andfalse
if not
-
expireAtAsync
public RFuture<Boolean> expireAtAsync(Date timestamp)
Description copied from interface:RExpirableAsync
UseRExpirableAsync.expireAsync(Instant)
instead- Specified by:
expireAtAsync
in interfaceRExpirableAsync
- Parameters:
timestamp
- - expire date- Returns:
true
if the timeout was set andfalse
if not
-
clearExpire
public boolean clearExpire()
Description copied from interface:RExpirable
Clear an expire timeout or expire date for object.- Specified by:
clearExpire
in interfaceRExpirable
- Returns:
true
if timeout was removedfalse
if object does not exist or does not have an associated timeout
-
remainTimeToLive
public long remainTimeToLive()
Description copied from interface:RExpirable
Remaining time to live of Redisson object that has a timeout- Specified by:
remainTimeToLive
in interfaceRExpirable
- Returns:
- time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
-
remainTimeToLiveAsync
public RFuture<Long> remainTimeToLiveAsync()
Description copied from interface:RExpirableAsync
Remaining time to live of Redisson object that has a timeout- Specified by:
remainTimeToLiveAsync
in interfaceRExpirableAsync
- Returns:
- time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
-
expireAsync
protected RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit, String... keys)
-
-