public class MessageQueue extends Object
Implementation note: all operations are coded as update queue followed by update
count. This means that it is possible that size() may not reflect the
actual size of the queue at any given point in time (but usually will).
| Modifier and Type | Class and Description |
|---|---|
static class |
MessageQueue.DiscardAction
Controls how messages are discarded once the threshold is reached.
|
| Constructor and Description |
|---|
MessageQueue(int discardThreshold,
MessageQueue.DiscardAction discardAction) |
| Modifier and Type | Method and Description |
|---|---|
LogMessage |
dequeue()
Removes a message from the front of the queue.
|
LogMessage |
dequeue(long waitTime)
Removes a message from the front of the queue, waiting for a specified number of
milliseconds if the queue is empty.
|
void |
enqueue(LogMessage message)
Adds a message to the end of the queue.
|
MessageQueue.DiscardAction |
getDiscardAction()
Returns the current discard action; this is intended for testing.
|
int |
getDiscardThreshold()
Returns the current discard threshold; this is intended for testing.
|
int |
getDroppedMessageCount()
Returns the number of messages that have been dropped.
|
boolean |
isEmpty()
Determines whether the queue is empty.
|
int |
queueSize()
Returns the current number of elements in the queue, as recorded by the queue
itself.
|
void |
requeue(LogMessage message)
Adds a message to the start of the queue.
|
void |
setDiscardAction(MessageQueue.DiscardAction value)
Changes the discard action
|
void |
setDiscardThreshold(int value)
Changes the discard threshold.
|
int |
size()
Returns the current number of elements in the queue, as recorded by the atomic
counter.
|
List<LogMessage> |
toList()
Copies the current queue contents into a List.
|
public MessageQueue(int discardThreshold,
MessageQueue.DiscardAction discardAction)
public void setDiscardThreshold(int value)
public int getDiscardThreshold()
public void setDiscardAction(MessageQueue.DiscardAction value)
public MessageQueue.DiscardAction getDiscardAction()
public int getDroppedMessageCount()
public boolean isEmpty()
public void enqueue(LogMessage message)
Note: discard policy is checked after adding the message. If the policy is "newest", then this message will be removed.
public void requeue(LogMessage message)
Note: discard policy is checked after adding the message. If the policy is "oldest", then this message will be removed (assuming that someone else has not dequeued it).
public LogMessage dequeue()
public LogMessage dequeue(long waitTime)
public int size()
public int queueSize()
public List<LogMessage> toList()
Copyright © 2023. All rights reserved.