Class MessageGroupQueue
- All Implemented Interfaces:
Iterable<Message<?>>,Collection<Message<?>>,BlockingQueue<Message<?>>,Queue<Message<?>>
public class MessageGroupQueue extends AbstractQueue<Message<?>> implements BlockingQueue<Message<?>>
A
BlockingQueue that is backed by a MessageGroupStore. Can be used to ensure guaranteed delivery in
the face of transaction rollback (assuming the store is transactional) and also to ensure messages are not lost if
the process dies (assuming the store is durable). To use the queue across process re-starts, the same group id
must be provided, so it needs to be unique but identifiable with a single logical instance of the queue.- Since:
- 2.0
- Author:
- Dave Syer, Oleg Zhurakousky, Gunnar Hillert, Gary Russell, Artem Bilan
-
Constructor Summary
Constructors Constructor Description MessageGroupQueue(BasicMessageGroupStore messageGroupStore, Object groupId)MessageGroupQueue(BasicMessageGroupStore messageGroupStore, Object groupId, int capacity)MessageGroupQueue(BasicMessageGroupStore messageGroupStore, Object groupId, int capacity, Lock storeLock)MessageGroupQueue(BasicMessageGroupStore messageGroupStore, Object groupId, Lock storeLock) -
Method Summary
Modifier and Type Method Description protected booleandoOffer(Message<?> message)It is assumed that the 'storeLock' is being held by the caller, otherwise IllegalMonitorStateException may be thrown.protected Message<?>doPoll()It is assumed that the 'storeLock' is being held by the caller, otherwise IllegalMonitorStateException may be thrown.intdrainTo(Collection<? super Message<?>> c)intdrainTo(Collection<? super Message<?>> collection, int maxElements)protected BasicMessageGroupStoregetMessageGroupStore()Get the store.protected Collection<Message<?>>getMessages()protected ConditiongetMessageStoreNotEmpty()Get the not empty condition.protected ConditiongetMessageStoreNotFull()Get the not full condition.protected LockgetStoreLock()Get the store lock.Iterator<Message<?>>iterator()booleanoffer(Message<?> message)booleanoffer(Message<?> message, long timeout, TimeUnit unit)Message<?>peek()Message<?>poll()Message<?>poll(long timeout, TimeUnit unit)voidput(Message<?> message)intremainingCapacity()voidsetPriority(boolean priority)If true, ensures that the message store supports priority.intsize()Stream<Message<?>>stream()Message<?>take()Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
addAll, clear, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, toArray, toArray, toArray
-
Constructor Details
-
MessageGroupQueue
-
MessageGroupQueue
-
MessageGroupQueue
-
MessageGroupQueue
public MessageGroupQueue(BasicMessageGroupStore messageGroupStore, Object groupId, int capacity, Lock storeLock)
-
-
Method Details
-
setPriority
public void setPriority(boolean priority)If true, ensures that the message store supports priority. If false WARNs if the message store uses priority to determine the message order when receiving.- Parameters:
priority- true if priority is expected to be used.
-
iterator
- Specified by:
iteratorin interfaceCollection<Message<?>>- Specified by:
iteratorin interfaceIterable<Message<?>>- Specified by:
iteratorin classAbstractCollection<Message<?>>
-
getMessageGroupStore
Get the store.- Returns:
- the store.
- Since:
- 5.0.11
-
getStoreLock
Get the store lock.- Returns:
- the lock.
- Since:
- 5.0.11
-
getMessageStoreNotFull
Get the not full condition.- Returns:
- the condition.
- Since:
- 5.0.11
-
getMessageStoreNotEmpty
Get the not empty condition.- Returns:
- the condition.
- Since:
- 5.0.11
-
size
public int size()- Specified by:
sizein interfaceCollection<Message<?>>- Specified by:
sizein classAbstractCollection<Message<?>>
-
peek
-
poll
- Specified by:
pollin interfaceBlockingQueue<Message<?>>- Throws:
InterruptedException
-
poll
-
drainTo
- Specified by:
drainToin interfaceBlockingQueue<Message<?>>
-
drainTo
- Specified by:
drainToin interfaceBlockingQueue<Message<?>>
-
offer
-
offer
- Specified by:
offerin interfaceBlockingQueue<Message<?>>- Throws:
InterruptedException
-
put
- Specified by:
putin interfaceBlockingQueue<Message<?>>- Throws:
InterruptedException
-
remainingCapacity
public int remainingCapacity()- Specified by:
remainingCapacityin interfaceBlockingQueue<Message<?>>
-
take
- Specified by:
takein interfaceBlockingQueue<Message<?>>- Throws:
InterruptedException
-
getMessages
-
stream
- Specified by:
streamin interfaceCollection<Message<?>>
-
doPoll
It is assumed that the 'storeLock' is being held by the caller, otherwise IllegalMonitorStateException may be thrown.- Returns:
- a message // TODO @Nullable
-
doOffer
It is assumed that the 'storeLock' is being held by the caller, otherwise IllegalMonitorStateException may be thrown.- Parameters:
message- the message to offer.- Returns:
- true if offered.
-