Queue
methods are provided
with the same semantics, while further functionality which accomodates the concurrent usecase is also on offer.
Message passing queues provide happens before semantics to messages passed through, namely that writes made by the producer before offering the message are visible to the consuming thread after the message has been polled out of the queue.
Modifier and Type | Class and Description |
---|---|
public static interface | |
public static interface | |
public static interface | |
public static interface |
Modifier and Type | Field and Description |
---|---|
public static final int |
Modifier and Type | Method and Description |
---|---|
public int | Returns: the capacity of this queue orMessagePassingQueue#UNBOUNDED_CAPACITY if not bounded
|
public void | |
public int | Returns: the number of polled elementsRemove up to limit elements from the queue and hand to consume. |
public int | Returns: the number of polled elementsRemove all available item from the queue and hand to consume. |
public void | drain(MessagePassingQueue.
Remove elements from the queue and hand to consume forever. |
public int | Returns: the number of offered elementsStuff the queue with up to limit elements from the supplier. |
public int | Returns: the number of offered elementsStuff the queue with elements from the supplier. |
public void | fill(MessagePassingQueue.
Stuff the queue with elements from the supplier forever. |
public boolean | Returns: true if empty, false otherwiseThis method's accuracy is subject to concurrent modifications happening as the observation is carried out. |
public boolean | Returns: true if element was inserted into the queue, false iff fullnot e)null , will throw NPE if it isCalled from a producer thread subject to the restrictions appropriate to the implementation and
according to the |
public T | Returns: a message from the queue if one is available,null iff emptyCalled from the consumer thread subject to the restrictions appropriate to the implementation and
according to the |
public T | Returns: a message from the queue if one is available,null iff emptyCalled from the consumer thread subject to the restrictions appropriate to the implementation and
according to the |
public boolean | Returns: true if element was inserted into the queue, false if unable to offernot e)null , will throw NPE if it isCalled from a producer thread subject to the restrictions appropriate to the implementation. |
public T | Returns: a message from the queue if one is available,null if unable to peekCalled from the consumer thread subject to the restrictions appropriate to the implementation. |
public T | Returns: a message from the queue if one is available,null if unable to pollCalled from the consumer thread subject to the restrictions appropriate to the implementation. |
public int | Returns: number of messages in the queue, between 0 andInteger#MAX_VALUE but less or equals to
capacity (if bounded).This method's accuracy is subject to concurrent modifications happening as the size is estimated and as such is a best effort rather than absolute value. |
UNBOUNDED_CAPACITY | back to summary |
---|---|
public static final int UNBOUNDED_CAPACITY |
capacity | back to summary |
---|---|
public int capacity()
|
clear | back to summary |
---|---|
public void clear() Removes all items from the queue. Called from the consumer thread subject to the restrictions
appropriate to the implementation and according to the |
drain | back to summary |
---|---|
public int drain(MessagePassingQueue. Remove up to limit elements from the queue and hand to consume. This should be semantically similar to:
There's no strong commitment to the queue being empty at the end of a drain. Called from a consumer thread subject to the restrictions appropriate to the implementation. Warning Explicit assumptions are made with regards to
|
drain | back to summary |
---|---|
public int drain(MessagePassingQueue. Remove all available item from the queue and hand to consume. This should be semantically similar to: M m; while((m = relaxedPoll()) != null){ c.accept(m); }There's no strong commitment to the queue being empty at the end of a drain. Called from a consumer thread subject to the restrictions appropriate to the implementation. Warning Explicit assumptions are made with regards to
|
drain | back to summary |
---|---|
public void drain(MessagePassingQueue. Remove elements from the queue and hand to consume forever. Semantically similar to:
int idleCounter = 0; while (exit.keepRunning()) { E e = relaxedPoll(); if(e==null){ idleCounter = wait.idle(idleCounter); continue; } idleCounter = 0; c.accept(e); } Called from a consumer thread subject to the restrictions appropriate to the implementation. Warning Explicit assumptions are made with regards to
|
fill | back to summary |
---|---|
public int fill(MessagePassingQueue. Stuff the queue with up to limit elements from the supplier. Semantically similar to:
There's no strong commitment to the queue being full at the end of a fill. Called from a producer thread subject to the restrictions appropriate to the implementation Warning Explicit assumptions are made with regards to
|
fill | back to summary |
---|---|
public int fill(MessagePassingQueue. Stuff the queue with elements from the supplier. Semantically similar to: while(relaxedOffer(s.get());There's no strong commitment to the queue being full at the end of a fill. Called from a producer thread subject to the restrictions appropriate to the implementation. Unbounded queues will fill up the queue with a fixed amount rather than fill up to oblivion Warning Explicit assumptions are made with regards to
|
fill | back to summary |
---|---|
public void fill(MessagePassingQueue. Stuff the queue with elements from the supplier forever. Semantically similar to:
Called from a producer thread subject to the restrictions appropriate to the implementation. The main difference
being that implementors MUST assure room in the queue is available BEFORE calling Warning Explicit assumptions are made with regards to
|
isEmpty | back to summary |
---|---|
public boolean isEmpty() This method's accuracy is subject to concurrent modifications happening as the observation is carried out.
|
offer | back to summary |
---|---|
public boolean offer(T e) Called from a producer thread subject to the restrictions appropriate to the implementation and
according to the
|
peek | back to summary |
---|---|
public T peek() Called from the consumer thread subject to the restrictions appropriate to the implementation and
according to the
|
poll | back to summary |
---|---|
public T poll() Called from the consumer thread subject to the restrictions appropriate to the implementation and
according to the
|
relaxedOffer | back to summary |
---|---|
public boolean relaxedOffer(T e) Called from a producer thread subject to the restrictions appropriate to the implementation. As opposed
to
|
relaxedPeek | back to summary |
---|---|
public T relaxedPeek() Called from the consumer thread subject to the restrictions appropriate to the implementation. As
opposed to
|
relaxedPoll | back to summary |
---|---|
public T relaxedPoll() Called from the consumer thread subject to the restrictions appropriate to the implementation. As
opposed to
|
size | back to summary |
---|---|
public int size() This method's accuracy is subject to concurrent modifications happening as the size is estimated and as such is a best effort rather than absolute value. For some implementations this method may be O(n) rather than O(1).
|
Modifier and Type | Method and Description |
---|---|
public void |
accept | back to summary |
---|---|
public void accept(T e) This method will process an element already removed from the queue. This method is expected to never throw an exception. Users should be aware that underlying queue implementations may upfront claim parts of the queue for batch operations and this will effect the view on the queue from the accept method. In particular size and any poll/peek methods may take the view that the full batch has already happened. Warning this method is assumed to never throw. Breaking this assumption can lead to a broken queue.
|
Modifier and Type | Method and Description |
---|---|
public boolean | Returns: true as long as we should keep runningThis method should be implemented such that the flag read or determination cannot be hoisted out of a loop which notmally means a volatile load, but with JDK9 VarHandles may mean getOpaque. |
keepRunning | back to summary |
---|---|
public boolean keepRunning() This method should be implemented such that the flag read or determination cannot be hoisted out of a loop which notmally means a volatile load, but with JDK9 VarHandles may mean getOpaque.
|
Modifier and Type | Method and Description |
---|---|
public T | Returns: new element, NEVERnull This method will return the next value to be written to the queue. |
get | back to summary |
---|---|
public T get() This method will return the next value to be written to the queue. As such the queue implementations are commited to insert the value once the call is made. Users should be aware that underlying queue implementations may upfront claim parts of the queue for batch operations and this will effect the view on the queue from the supplier method. In particular size and any offer methods may take the view that the full batch has already happened. Warning this method is assumed to never throw. Breaking this assumption can lead to a broken queue. Warning this method is assumed to never return
|
Modifier and Type | Method and Description |
---|---|
public int | Returns: new counter value to be used on subsequent idle cycleidle calls counter, managed by the idle method until reset idleCounter)This method can implement static or dynamic backoff. |
idle | back to summary |
---|---|
public int idle(int idleCounter) This method can implement static or dynamic backoff. Dynamic backoff will rely on the counter for estimating how long the caller has been idling. The expected usage is:
|