Class QueueChannel<Message>
- java.lang.Object
-
- co.paralleluniverse.strands.channels.QueueChannel<Message>
-
- All Implemented Interfaces:
Channel<Message>,Port<Message>,PortAutoCloseable,ReceivePort<Message>,Selectable<Message>,SendPort<Message>,StandardChannel<Message>,Synchronization,java.io.Serializable,java.lang.AutoCloseable
- Direct Known Subclasses:
QueueObjectChannel,QueuePrimitiveChannel,SingleConsumerQueueChannel
public abstract class QueueChannel<Message> extends java.lang.Object implements StandardChannel<Message>, Selectable<Message>, Synchronization, java.io.Serializable
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface co.paralleluniverse.strands.channels.ReceivePort
ReceivePort.EOFException
-
-
Field Summary
Fields Modifier and Type Field Description static co.paralleluniverse.common.monitoring.FlightRecorderRECORDER
-
Constructor Summary
Constructors Modifier Constructor Description protectedQueueChannel(co.paralleluniverse.strands.queues.BasicQueue<Message> queue, Channels.OverflowPolicy overflowPolicy, boolean singleConsumer)protectedQueueChannel(co.paralleluniverse.strands.queues.BasicQueue<Message> queue, Channels.OverflowPolicy overflowPolicy, boolean singleProducer, boolean singleConsumer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcapacity()The channel's internal buffer capacity.voidclose()Closes the channel so that no more messages could be sent to it.voidclose(java.lang.Throwable t)Closes the channel so that no more messages could be sent to it, and signifies an exception occurred in the producer.booleanequals(java.lang.Object other)protected java.lang.ThrowablegetCloseException()Channels.OverflowPolicygetOverflowPolicy()intgetQueueLength()booleanisClosed()This method must only be called by the channel's owner (the receiver)booleanisSingleConsumer()Whether or not the channel supports a single consumer only.booleanisSingleProducer()Whether or not the channel supports a single producer only.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.Messagereceive(Timeout timeout)Retrieves a message from the channels, possibly blocking until one becomes available, but no longer than the specified timeout.MessagereceiveFromThread()MessagereceiveFromThread(long timeout, java.util.concurrent.TimeUnit unit)java.lang.Objectregister()java.lang.Objectregister(SelectAction<Message> action)voidsend(Message message)Sends a message to the channel, possibly blocking until there's room available in the channel.booleansend(Message message, long timeout, java.util.concurrent.TimeUnit unit)Sends a message to the channel, possibly blocking until there's room available in the channel, but never longer than the specified timeout.booleansend(Message message, Timeout timeout)Sends a message to the channel, possibly blocking until there's room available in the channel, but never longer than the specified timeout.booleansend0(Message message, boolean sync, boolean timed, long nanos)voidsendNonSuspendable(Message message)protected voidsendSync(Message message)protected voidsignalAndWait()protected voidsignalReceivers()protected Conditionsync()java.lang.StringtoString()booleantryNow(java.lang.Object token)MessagetryReceive()Retrieves a message from the channel if one is available.booleantrySend(Message message)Sends a message to the channel if the channel has room available.voidunregister(java.lang.Object token)protected java.lang.ObjectwriteReplace()
-
-
-
Constructor Detail
-
QueueChannel
protected QueueChannel(co.paralleluniverse.strands.queues.BasicQueue<Message> queue, Channels.OverflowPolicy overflowPolicy, boolean singleConsumer)
-
QueueChannel
protected QueueChannel(co.paralleluniverse.strands.queues.BasicQueue<Message> queue, Channels.OverflowPolicy overflowPolicy, boolean singleProducer, boolean singleConsumer)
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
capacity
public int capacity()
Description copied from interface:StandardChannelThe channel's internal buffer capacity.- Specified by:
capacityin interfaceStandardChannel<Message>- Returns:
- the channel's internal buffer capacity,
-1for an unbounded buffer, and0for a transfer channel.
-
isSingleProducer
public boolean isSingleProducer()
Description copied from interface:StandardChannelWhether or not the channel supports a single producer only.- Specified by:
isSingleProducerin interfaceStandardChannel<Message>- Returns:
trueif the channel supports no more than one producer;falseotherwise.
-
isSingleConsumer
public boolean isSingleConsumer()
Description copied from interface:StandardChannelWhether or not the channel supports a single consumer only.- Specified by:
isSingleConsumerin interfaceStandardChannel<Message>- Returns:
trueif the channel supports no more than one consumer;falseotherwise.
-
getOverflowPolicy
public Channels.OverflowPolicy getOverflowPolicy()
-
sync
protected Condition sync()
-
signalReceivers
protected void signalReceivers()
-
signalAndWait
protected void signalAndWait() throws SuspendExecution, java.lang.InterruptedException- Throws:
SuspendExecutionjava.lang.InterruptedException
-
register
public java.lang.Object register(SelectAction<Message> action)
- Specified by:
registerin interfaceSelectable<Message>
-
register
public java.lang.Object register()
- Specified by:
registerin interfaceSynchronization
-
tryNow
public boolean tryNow(java.lang.Object token)
- Specified by:
tryNowin interfaceSelectable<Message>
-
unregister
public void unregister(java.lang.Object token)
- Specified by:
unregisterin interfaceSelectable<Message>- Specified by:
unregisterin interfaceSynchronization
-
send
public void send(Message message) throws SuspendExecution, java.lang.InterruptedException
Description copied from interface:SendPortSends a message to the channel, possibly blocking until there's room available in the channel. If the channel is full, this method may block, throw an exception, silently drop the message, or displace an old message from the channel. The behavior is determined by the channel'sOverflowPolicy, set at construction time.- Specified by:
sendin interfaceSendPort<Message>- Parameters:
message- the message- Throws:
SuspendExecutionjava.lang.InterruptedException
-
send
public boolean send(Message message, long timeout, java.util.concurrent.TimeUnit unit) throws SuspendExecution, java.lang.InterruptedException
Description copied from interface:SendPortSends a message to the channel, possibly blocking until there's room available in the channel, but never longer than the specified timeout. If the channel is full, this method may block, throw an exception, silently drop the message, or displace an old message from the channel. The behavior is determined by the channel'sOverflowPolicy, set at construction time.- Specified by:
sendin interfaceSendPort<Message>- Parameters:
message- the messagetimeout- the maximum duration this method is allowed to wait.unit- the timeout's time unit- Returns:
trueif the message has been sent successfully;falseif the timeout has expired.- Throws:
SuspendExecutionjava.lang.InterruptedException
-
send
public boolean send(Message message, Timeout timeout) throws SuspendExecution, java.lang.InterruptedException
Description copied from interface:SendPortSends a message to the channel, possibly blocking until there's room available in the channel, but never longer than the specified timeout. If the channel is full, this method may block, throw an exception, silently drop the message, or displace an old message from the channel. The behavior is determined by the channel'sOverflowPolicy, set at construction time.- Specified by:
sendin interfaceSendPort<Message>- Parameters:
message- the messagetimeout- the method will not block for longer than the amount remaining in theTimeout- Returns:
trueif the message has been sent successfully;falseif the timeout has expired.- Throws:
SuspendExecutionjava.lang.InterruptedException
-
trySend
public boolean trySend(Message message)
Description copied from interface:SendPortSends a message to the channel if the channel has room available. This method never blocks.
-
sendSync
protected void sendSync(Message message) throws SuspendExecution
- Throws:
SuspendExecution
-
send0
public boolean send0(Message message, boolean sync, boolean timed, long nanos) throws SuspendExecution, java.lang.InterruptedException
- Throws:
SuspendExecutionjava.lang.InterruptedException
-
close
public void close()
Description copied from interface:PortAutoCloseableCloses the channel so that no more messages could be sent to it. Messages already sent to the channel will still be received.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacePortAutoCloseable
-
close
public void close(java.lang.Throwable t)
Description copied from interface:SendPortCloses the channel so that no more messages could be sent to it, and signifies an exception occurred in the producer. The exception will be thrown when the consumer callsReceivePort'sreceiveortryReceive, wrapped by aProducerException. Messages already sent to the channel prior to calling this method will still be received.
-
sendNonSuspendable
public void sendNonSuspendable(Message message) throws co.paralleluniverse.strands.queues.QueueCapacityExceededException
- Throws:
co.paralleluniverse.strands.queues.QueueCapacityExceededException
-
isClosed
public boolean isClosed()
This method must only be called by the channel's owner (the receiver)- Specified by:
isClosedin interfacePortAutoCloseable- Returns:
trueif the channels has been closed and no more messages will be received;falseotherwise.
-
getCloseException
protected java.lang.Throwable getCloseException()
-
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>- 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>- 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>- 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
-
receive
public Message receive(Timeout timeout) 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>- Parameters:
timeout- the method will not block for longer than the amount remaining in theTimeout- 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
-
receiveFromThread
public Message receiveFromThread() throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
receiveFromThread
public Message receiveFromThread(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
getQueueLength
public int getQueueLength()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
writeReplace
protected java.lang.Object writeReplace() throws java.io.ObjectStreamException- Throws:
java.io.ObjectStreamException
-
-