Class SingleConsumerQueueChannel<Message>
- java.lang.Object
-
- co.paralleluniverse.strands.channels.QueueChannel<Message>
-
- co.paralleluniverse.strands.channels.SingleConsumerQueueChannel<Message>
-
- All Implemented Interfaces:
Channel<Message>,Port<Message>,PortAutoCloseable,ReceivePort<Message>,Selectable<Message>,SendPort<Message>,StandardChannel<Message>,Stranded,Synchronization,java.io.Serializable,java.lang.AutoCloseable
- Direct Known Subclasses:
Mailbox
public class SingleConsumerQueueChannel<Message> extends QueueChannel<Message> implements Stranded
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface co.paralleluniverse.strands.channels.ReceivePort
ReceivePort.EOFException
-
-
Field Summary
-
Fields inherited from class co.paralleluniverse.strands.channels.QueueChannel
RECORDER
-
-
Constructor Summary
Constructors Constructor Description SingleConsumerQueueChannel(co.paralleluniverse.strands.queues.SingleConsumerQueue<Message> queue, Channels.OverflowPolicy policy)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckClosed()java.lang.ObjectgetOwner()StrandgetStrand()booleanisOwnerAlive()protected voidmaybeSetCurrentStrandAsOwner()protected co.paralleluniverse.strands.queues.SingleConsumerQueue<Message>queue()Messagereceive()Retrieves a message from the channels, possibly blocking until one becomes available.Messagereceive(long timeout, java.util.concurrent.TimeUnit unit)Retrieves a message from the channels, possibly blocking until one becomes available, but no longer than the specified timeout.voidsetStrand(Strand strand)java.lang.StringtoString()MessagetryReceive()Retrieves a message from the channel if one is available.-
Methods inherited from class co.paralleluniverse.strands.channels.QueueChannel
capacity, close, close, equals, getCloseException, getOverflowPolicy, getQueueLength, isClosed, isSingleConsumer, isSingleProducer, receive, receiveFromThread, receiveFromThread, register, register, send, send, send, send0, sendNonSuspendable, sendSync, signalAndWait, signalReceivers, sync, tryNow, trySend, unregister, writeReplace
-
-
-
-
Constructor Detail
-
SingleConsumerQueueChannel
public SingleConsumerQueueChannel(co.paralleluniverse.strands.queues.SingleConsumerQueue<Message> queue, Channels.OverflowPolicy policy)
-
-
Method Detail
-
getOwner
public java.lang.Object getOwner()
-
isOwnerAlive
public boolean isOwnerAlive()
-
maybeSetCurrentStrandAsOwner
protected void maybeSetCurrentStrandAsOwner()
-
checkClosed
protected void checkClosed() throws ReceivePort.EOFException- Throws:
ReceivePort.EOFException
-
tryReceive
public Message tryReceive()
Description copied from interface:ReceivePortRetrieves a message from the channel if one is available. This method never blocks.- Specified by:
tryReceivein interfaceReceivePort<Message>- Overrides:
tryReceivein classQueueChannel<Message>- Returns:
- a message, or
nullif one is not immediately available.
-
receive
public Message receive() throws SuspendExecution, java.lang.InterruptedException
Description copied from interface:ReceivePortRetrieves a message from the channels, possibly blocking until one becomes available.- Specified by:
receivein interfaceReceivePort<Message>- Overrides:
receivein classQueueChannel<Message>- Returns:
- a message, or
nullif the channel has been closed and no more messages await (seePortAutoCloseable.isClosed()). - Throws:
SuspendExecutionjava.lang.InterruptedException
-
receive
public Message receive(long timeout, java.util.concurrent.TimeUnit unit) throws SuspendExecution, java.lang.InterruptedException
Description copied from interface:ReceivePortRetrieves a message from the channels, possibly blocking until one becomes available, but no longer than the specified timeout.- Specified by:
receivein interfaceReceivePort<Message>- Overrides:
receivein classQueueChannel<Message>- Parameters:
timeout- the maximum duration to block waiting for a message.unit- the time unit of the timeout.- Returns:
- a message, or
nullif the channel has been closed and no more messages await (seePortAutoCloseable.isClosed()), or if the timeout has expired. - Throws:
SuspendExecutionjava.lang.InterruptedException
-
queue
protected co.paralleluniverse.strands.queues.SingleConsumerQueue<Message> queue()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classQueueChannel<Message>
-
-