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 void
checkClosed()
java.lang.Object
getOwner()
Strand
getStrand()
boolean
isOwnerAlive()
protected void
maybeSetCurrentStrandAsOwner()
protected co.paralleluniverse.strands.queues.SingleConsumerQueue<Message>
queue()
Message
receive()
Retrieves a message from the channels, possibly blocking until one becomes available.Message
receive(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.void
setStrand(Strand strand)
java.lang.String
toString()
Message
tryReceive()
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:ReceivePort
Retrieves a message from the channel if one is available. This method never blocks.- Specified by:
tryReceive
in interfaceReceivePort<Message>
- Overrides:
tryReceive
in classQueueChannel<Message>
- Returns:
- a message, or
null
if one is not immediately available.
-
receive
public Message receive() throws SuspendExecution, java.lang.InterruptedException
Description copied from interface:ReceivePort
Retrieves a message from the channels, possibly blocking until one becomes available.- Specified by:
receive
in interfaceReceivePort<Message>
- Overrides:
receive
in classQueueChannel<Message>
- Returns:
- a message, or
null
if the channel has been closed and no more messages await (seePortAutoCloseable.isClosed()
). - Throws:
SuspendExecution
java.lang.InterruptedException
-
receive
public Message receive(long timeout, java.util.concurrent.TimeUnit unit) throws SuspendExecution, java.lang.InterruptedException
Description copied from interface:ReceivePort
Retrieves a message from the channels, possibly blocking until one becomes available, but no longer than the specified timeout.- Specified by:
receive
in interfaceReceivePort<Message>
- Overrides:
receive
in classQueueChannel<Message>
- Parameters:
timeout
- the maximum duration to block waiting for a message.unit
- the time unit of the timeout.- Returns:
- a message, or
null
if the channel has been closed and no more messages await (seePortAutoCloseable.isClosed()
), or if the timeout has expired. - Throws:
SuspendExecution
java.lang.InterruptedException
-
queue
protected co.paralleluniverse.strands.queues.SingleConsumerQueue<Message> queue()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classQueueChannel<Message>
-
-