Class ValChannel<V>
- java.lang.Object
-
- co.paralleluniverse.strands.dataflow.ValChannel<V>
-
- All Implemented Interfaces:
Port<V>,PortAutoCloseable,ReceivePort<V>,Selectable<V>,java.lang.AutoCloseable
public class ValChannel<V> extends java.lang.Object implements ReceivePort<V>, Selectable<V>
An adapter that turns a DelayedVal into a ReceivePort that receives the DelayedVal's value and then closes.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface co.paralleluniverse.strands.channels.ReceivePort
ReceivePort.EOFException
-
-
Constructor Summary
Constructors Constructor Description ValChannel(Val<V> val)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the channel so that no more messages could be sent to it.booleanisClosed()Tests whether the channel has been closed and no more messages await in the channel.Vreceive()Retrieves a message from the channels, possibly blocking until one becomes available.Vreceive(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.Vreceive(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<V> action1)booleantryNow(java.lang.Object token)VtryReceive()Retrieves a message from the channel if one is available.voidunregister(java.lang.Object token)
-
-
-
Method Detail
-
receive
public V 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<V>- Returns:
- a message, or
nullif the channel has been closed and no more messages await (seePortAutoCloseable.isClosed()). - Throws:
SuspendExecutionjava.lang.InterruptedException
-
tryReceive
public V tryReceive()
Description copied from interface:ReceivePortRetrieves a message from the channel if one is available. This method never blocks.- Specified by:
tryReceivein interfaceReceivePort<V>- Returns:
- a message, or
nullif one is not immediately available.
-
receive
public V 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<V>- 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 V 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<V>- 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<V> action1)
- Specified by:
registerin interfaceSelectable<V>
-
tryNow
public boolean tryNow(java.lang.Object token)
- Specified by:
tryNowin interfaceSelectable<V>
-
unregister
public void unregister(java.lang.Object token)
- Specified by:
unregisterin interfaceSelectable<V>
-
-