Class ReceivePortGroup<M>
- java.lang.Object
-
- co.paralleluniverse.strands.channels.ReceivePortGroup<M>
-
- All Implemented Interfaces:
Mix<M>
,Port<M>
,PortAutoCloseable
,ReceivePort<M>
,java.lang.AutoCloseable
public class ReceivePortGroup<M> extends java.lang.Object implements Mix<M>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface co.paralleluniverse.strands.channels.Mix
Mix.Mode, Mix.SoloEffect, Mix.State
-
Nested classes/interfaces inherited from interface co.paralleluniverse.strands.channels.ReceivePort
ReceivePort.EOFException
-
-
Constructor Summary
Constructors Constructor Description ReceivePortGroup()
ReceivePortGroup(boolean alwaysOpen)
ReceivePortGroup(ReceivePort<? extends M>... ports)
ReceivePortGroup(java.util.Collection<? extends ReceivePort<? extends M>> ports)
ReceivePortGroup(java.util.Collection<? extends ReceivePort<? extends M>> ports, boolean alwaysOpen)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends ReceivePort<? extends M>>
voidadd(T... items)
void
close()
Closes the channel so that no more messages could be sent to it.Mix.SoloEffect
getSoloEffect()
<T extends ReceivePort<? extends M>>
java.util.Map<T,Mix.State>getState(T... items)
boolean
isClosed()
Tests whether the channel has been closed and no more messages await in the channel.M
receive()
Retrieves a message from the channels, possibly blocking until one becomes available.M
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.M
receive(Timeout timeout)
Retrieves a message from the channels, possibly blocking until one becomes available, but no longer than the specified timeout.<T extends ReceivePort<? extends M>>
voidremove(T... items)
void
setSoloEffect(Mix.SoloEffect effect)
<T extends ReceivePort<? extends M>>
voidsetState(Mix.State state, T... items)
<T extends ReceivePort<? extends M>>
voidsetState(java.util.Map<T,Mix.State> newStates)
M
tryReceive()
Retrieves a message from the channel if one is available.
-
-
-
Constructor Detail
-
ReceivePortGroup
public ReceivePortGroup(java.util.Collection<? extends ReceivePort<? extends M>> ports, boolean alwaysOpen)
-
ReceivePortGroup
public ReceivePortGroup(java.util.Collection<? extends ReceivePort<? extends M>> ports)
-
ReceivePortGroup
public ReceivePortGroup(ReceivePort<? extends M>... ports)
-
ReceivePortGroup
public ReceivePortGroup(boolean alwaysOpen)
-
ReceivePortGroup
public ReceivePortGroup()
-
-
Method Detail
-
tryReceive
public M 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<M>
- Returns:
- a message, or
null
if one is not immediately available.
-
receive
public M 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<M>
- 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 M 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<M>
- 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
-
receive
public M receive(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, SuspendExecution
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<M>
- 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:
java.lang.InterruptedException
SuspendExecution
-
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.
-
add
public <T extends ReceivePort<? extends M>> void add(T... items) throws SuspendExecution, java.lang.InterruptedException
- Specified by:
add
in interfaceMix<M>
- Throws:
SuspendExecution
java.lang.InterruptedException
-
remove
public <T extends ReceivePort<? extends M>> void remove(T... items) throws SuspendExecution, java.lang.InterruptedException
- Specified by:
remove
in interfaceMix<M>
- Parameters:
items
- Ifnull
or empty, all items will be removed.- Throws:
SuspendExecution
java.lang.InterruptedException
-
getState
public <T extends ReceivePort<? extends M>> java.util.Map<T,Mix.State> getState(T... items)
-
setState
public <T extends ReceivePort<? extends M>> void setState(Mix.State state, T... items) throws SuspendExecution, java.lang.InterruptedException
- Specified by:
setState
in interfaceMix<M>
items
- Ifnull
or empty, all items state will be set tostate
.- Throws:
SuspendExecution
java.lang.InterruptedException
-
setState
public <T extends ReceivePort<? extends M>> void setState(java.util.Map<T,Mix.State> newStates) throws SuspendExecution, java.lang.InterruptedException
- Specified by:
setState
in interfaceMix<M>
- Throws:
SuspendExecution
java.lang.InterruptedException
-
getSoloEffect
public Mix.SoloEffect getSoloEffect()
- Specified by:
getSoloEffect
in interfaceMix<M>
-
setSoloEffect
public void setSoloEffect(Mix.SoloEffect effect) throws SuspendExecution, java.lang.InterruptedException
- Specified by:
setSoloEffect
in interfaceMix<M>
- Throws:
SuspendExecution
java.lang.InterruptedException
-
-