Class FlatMappingReceivePort<S,T>
- java.lang.Object
-
- co.paralleluniverse.strands.channels.FlatMappingReceivePort<S,T>
-
- All Implemented Interfaces:
co.paralleluniverse.common.util.DelegatingEquals
,Port<T>
,PortAutoCloseable
,ReceivePort<T>
,java.lang.AutoCloseable
public class FlatMappingReceivePort<S,T> extends java.lang.Object implements ReceivePort<T>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface co.paralleluniverse.strands.channels.ReceivePort
ReceivePort.EOFException
-
-
Field Summary
Fields Modifier and Type Field Description protected ReceivePort<S>
target
-
Constructor Summary
Constructors Constructor Description FlatMappingReceivePort(ReceivePort<S> target)
FlatMappingReceivePort(ReceivePort<S> target, com.google.common.base.Function<S,ReceivePort<T>> f)
-
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
equals(java.lang.Object obj)
int
hashCode()
boolean
isClosed()
Tests whether the channel has been closed and no more messages await in the channel.protected ReceivePort<T>
map(S m)
T
receive()
Retrieves a message from the channels, possibly blocking until one becomes available.T
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.T
receive(Timeout timeout)
Retrieves a message from the channels, possibly blocking until one becomes available, but no longer than the specified timeout.java.lang.String
toString()
T
tryReceive()
Retrieves a message from the channel if one is available.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface co.paralleluniverse.strands.channels.PortAutoCloseable
close
-
-
-
-
Field Detail
-
target
protected final ReceivePort<S> target
-
-
Constructor Detail
-
FlatMappingReceivePort
public FlatMappingReceivePort(ReceivePort<S> target, com.google.common.base.Function<S,ReceivePort<T>> f)
-
FlatMappingReceivePort
public FlatMappingReceivePort(ReceivePort<S> target)
-
-
Method Detail
-
receive
public T 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<S>
- 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 T 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<S>
- 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
-
tryReceive
public T 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<S>
- Returns:
- a message, or
null
if one is not immediately available.
-
receive
public T 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<S>
- 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
-
map
protected ReceivePort<T> map(S m)
-
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.
-
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
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Specified by:
equals
in interfaceco.paralleluniverse.common.util.DelegatingEquals
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-