Class TickerChannelConsumer<Message>
- java.lang.Object
-
- co.paralleluniverse.strands.channels.TickerChannelConsumer<Message>
-
- All Implemented Interfaces:
Port<Message>,PortAutoCloseable,ReceivePort<Message>,Selectable<Message>,java.lang.AutoCloseable
- Direct Known Subclasses:
TickerChannelConsumer.TickerChannelFloatConsumer
public class TickerChannelConsumer<Message> extends java.lang.Object implements ReceivePort<Message>, Selectable<Message>
AReceivePortwhich is a view of aticker channel. Each ticker-consumer will yield monotonic messages, namely no message will be received more than once, and the messages will be received in the order they're sent, but if the consumer is too slow, messages could be lost.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTickerChannelConsumer.TickerChannelFloatConsumer-
Nested classes/interfaces inherited from interface co.paralleluniverse.strands.channels.ReceivePort
ReceivePort.EOFException
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckClosed()voidclose()Closes the channel so that no more messages could be sent to it.longgetLastIndexRead()booleanhasMessage()booleanisClosed()Tests whether the channel has been closed and no more messages await in the channel.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.java.lang.Objectregister(SelectAction<Message> action)booleantryNow(java.lang.Object token)MessagetryReceive()Retrieves a message from the channel if one is available.voidunregister(java.lang.Object token)
-
-
-
Method Detail
-
checkClosed
protected void checkClosed() throws ReceivePort.EOFException- Throws:
ReceivePort.EOFException
-
hasMessage
public boolean hasMessage()
-
getLastIndexRead
public final long getLastIndexRead()
-
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
-
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
-
isClosed
public boolean isClosed()
Description copied from interface:PortAutoCloseableTests whether the channel has been closed and no more messages await in the channel. If this method returnstrueall future calls toreceiveare guaranteed to returnnull, and calls toreceiveon a primitive channel will throw aEOFException.- Specified by:
isClosedin interfacePortAutoCloseable- Returns:
trueif the channels has been closed and no more messages will be received;falseotherwise.
-
register
public java.lang.Object register(SelectAction<Message> action)
- Specified by:
registerin interfaceSelectable<Message>
-
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>
-
-