public class MessageGroupQueue extends AbstractQueue<Message<?>> implements BlockingQueue<Message<?>>
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.Constructor and 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) |
Modifier and Type | Method and Description |
---|---|
protected boolean |
doOffer(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
|
int |
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() |
Message<?> |
take() |
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
add, contains, remove
addAll, clear, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray
public MessageGroupQueue(BasicMessageGroupStore messageGroupStore, Object groupId)
public MessageGroupQueue(BasicMessageGroupStore messageGroupStore, Object groupId, int capacity)
public MessageGroupQueue(BasicMessageGroupStore messageGroupStore, Object groupId, Lock storeLock)
public MessageGroupQueue(BasicMessageGroupStore messageGroupStore, Object groupId, int capacity, Lock storeLock)
public void setPriority(boolean priority)
priority
- true if priority is expected to be used.public Iterator<Message<?>> iterator()
iterator
in interface Iterable<Message<?>>
iterator
in interface Collection<Message<?>>
iterator
in class AbstractCollection<Message<?>>
protected BasicMessageGroupStore getMessageGroupStore()
protected Lock getStoreLock()
protected Condition getMessageStoreNotFull()
protected Condition getMessageStoreNotEmpty()
public int size()
size
in interface Collection<Message<?>>
size
in class AbstractCollection<Message<?>>
public Message<?> poll(long timeout, TimeUnit unit) throws InterruptedException
poll
in interface BlockingQueue<Message<?>>
InterruptedException
public int drainTo(Collection<? super Message<?>> c)
drainTo
in interface BlockingQueue<Message<?>>
public int drainTo(Collection<? super Message<?>> collection, int maxElements)
drainTo
in interface BlockingQueue<Message<?>>
public boolean offer(Message<?> message)
public boolean offer(Message<?> message, long timeout, TimeUnit unit) throws InterruptedException
offer
in interface BlockingQueue<Message<?>>
InterruptedException
public void put(Message<?> message) throws InterruptedException
put
in interface BlockingQueue<Message<?>>
InterruptedException
public int remainingCapacity()
remainingCapacity
in interface BlockingQueue<Message<?>>
public Message<?> take() throws InterruptedException
take
in interface BlockingQueue<Message<?>>
InterruptedException
protected Collection<Message<?>> getMessages()
protected Message<?> doPoll()
protected boolean doOffer(Message<?> message)
message
- the message to offer.