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)voidclose()Closes the channel so that no more messages could be sent to it.Mix.SoloEffectgetSoloEffect()<T extends ReceivePort<? extends M>>
java.util.Map<T,Mix.State>getState(T... items)booleanisClosed()Tests whether the channel has been closed and no more messages await in the channel.Mreceive()Retrieves a message from the channels, possibly blocking until one becomes available.Mreceive(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.Mreceive(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)voidsetSoloEffect(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)MtryReceive()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:ReceivePortRetrieves a message from the channel if one is available. This method never blocks.- Specified by:
tryReceivein interfaceReceivePort<M>- Returns:
- a message, or
nullif one is not immediately available.
-
receive
public M 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<M>- Returns:
- a message, or
nullif the channel has been closed and no more messages await (seePortAutoCloseable.isClosed()). - Throws:
SuspendExecutionjava.lang.InterruptedException
-
receive
public M 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<M>- 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
-
receive
public M receive(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, SuspendExecution
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<M>- 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:
java.lang.InterruptedExceptionSuspendExecution
-
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.
-
add
public <T extends ReceivePort<? extends M>> void add(T... items) throws SuspendExecution, java.lang.InterruptedException
- Specified by:
addin interfaceMix<M>- Throws:
SuspendExecutionjava.lang.InterruptedException
-
remove
public <T extends ReceivePort<? extends M>> void remove(T... items) throws SuspendExecution, java.lang.InterruptedException
- Specified by:
removein interfaceMix<M>- Parameters:
items- Ifnullor empty, all items will be removed.- Throws:
SuspendExecutionjava.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:
setStatein interfaceMix<M>items- Ifnullor empty, all items state will be set tostate.- Throws:
SuspendExecutionjava.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:
setStatein interfaceMix<M>- Throws:
SuspendExecutionjava.lang.InterruptedException
-
getSoloEffect
public Mix.SoloEffect getSoloEffect()
- Specified by:
getSoloEffectin interfaceMix<M>
-
setSoloEffect
public void setSoloEffect(Mix.SoloEffect effect) throws SuspendExecution, java.lang.InterruptedException
- Specified by:
setSoloEffectin interfaceMix<M>- Throws:
SuspendExecutionjava.lang.InterruptedException
-
-