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 boolean
doOffer(Message<?> message)
It is assumed that the 'storeLock' is being held by the caller, otherwise IllegalMonitorStateException may be thrownprotected Message<?>
doPoll()
It is assumed that the 'storeLock' is being held by the caller, otherwise IllegalMonitorStateException may be thrownint
drainTo(Collection<? super Message<?>> c)
int
drainTo(Collection<? super Message<?>> collection, int maxElements)
protected BasicMessageGroupStore
getMessageGroupStore()
Get the store.protected Collection<Message<?>>
getMessages()
protected Condition
getMessageStoreNotEmpty()
Get the not empty condition.protected Condition
getMessageStoreNotFull()
Get the not full condition.protected Lock
getStoreLock()
Get the store lock.Iterator<Message<?>>
iterator()
boolean
offer(Message<?> message)
boolean
offer(Message<?> message, long timeout, TimeUnit unit)
Message<?>
peek()
Message<?>
poll()
Message<?>
poll(long timeout, TimeUnit unit)
void
put(Message<?> message)
int
remainingCapacity()
void
setPriority(boolean priority)
If true, ensures that the message store supports priority.int
size()
Stream<Message<?>>
stream()
Message<?>
take()
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods 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:
iterator
in interfaceCollection<Message<?>>
- Specified by:
iterator
in interfaceIterable<Message<?>>
- Specified by:
iterator
in 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:
size
in interfaceCollection<Message<?>>
- Specified by:
size
in classAbstractCollection<Message<?>>
-
peek
-
poll
- Specified by:
poll
in interfaceBlockingQueue<Message<?>>
- Throws:
InterruptedException
-
poll
-
drainTo
- Specified by:
drainTo
in interfaceBlockingQueue<Message<?>>
-
drainTo
- Specified by:
drainTo
in interfaceBlockingQueue<Message<?>>
-
offer
-
offer
- Specified by:
offer
in interfaceBlockingQueue<Message<?>>
- Throws:
InterruptedException
-
put
- Specified by:
put
in interfaceBlockingQueue<Message<?>>
- Throws:
InterruptedException
-
remainingCapacity
public int remainingCapacity()- Specified by:
remainingCapacity
in interfaceBlockingQueue<Message<?>>
-
take
- Specified by:
take
in interfaceBlockingQueue<Message<?>>
- Throws:
InterruptedException
-
getMessages
-
stream
- Specified by:
stream
in 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.
-