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 void
close()
Closes the channel so that no more messages could be sent to it.boolean
isClosed()
Tests whether the channel has been closed and no more messages await in the channel.V
receive()
Retrieves a message from the channels, possibly blocking until one becomes available.V
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.V
receive(Timeout timeout)
Retrieves a message from the channels, possibly blocking until one becomes available, but no longer than the specified timeout.java.lang.Object
register(SelectAction<V> action1)
boolean
tryNow(java.lang.Object token)
V
tryReceive()
Retrieves a message from the channel if one is available.void
unregister(java.lang.Object token)
-
-
-
Method Detail
-
receive
public V 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<V>
- Returns:
- a message, or
null
if the channel has been closed and no more messages await (seePortAutoCloseable.isClosed()
). - Throws:
SuspendExecution
java.lang.InterruptedException
-
tryReceive
public V 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<V>
- Returns:
- a message, or
null
if 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: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<V>
- 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
-
receive
public V receive(Timeout timeout) 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<V>
- Parameters:
timeout
- the method will not block for longer than the amount remaining in theTimeout
- 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
-
close
public void close()
Description copied from interface:PortAutoCloseable
Closes the channel so that no more messages could be sent to it. Messages already sent to the channel will still be received.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacePortAutoCloseable
-
isClosed
public boolean isClosed()
Description copied from interface:PortAutoCloseable
Tests whether the channel has been closed and no more messages await in the channel. If this method returnstrue
all future calls toreceive
are guaranteed to returnnull
, and calls toreceive
on a primitive channel will throw aEOFException
.- Specified by:
isClosed
in interfacePortAutoCloseable
- Returns:
true
if the channels has been closed and no more messages will be received;false
otherwise.
-
register
public java.lang.Object register(SelectAction<V> action1)
- Specified by:
register
in interfaceSelectable<V>
-
tryNow
public boolean tryNow(java.lang.Object token)
- Specified by:
tryNow
in interfaceSelectable<V>
-
unregister
public void unregister(java.lang.Object token)
- Specified by:
unregister
in interfaceSelectable<V>
-
-