Class Topic<Message>
- java.lang.Object
-
- co.paralleluniverse.strands.channels.Topic<Message>
-
- All Implemented Interfaces:
Port<Message>
,PortAutoCloseable
,SendPort<Message>
,java.lang.AutoCloseable
public class Topic<Message> extends java.lang.Object
A channel that forwards all messages to subscriber channels.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
sendClosed
-
Constructor Summary
Constructors Constructor Description Topic()
-
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.void
close(java.lang.Throwable t)
Closes the channel so that no more messages could be sent to it, and signifies an exception occurred in the producer.protected java.util.Collection<SendPort<? super Message>>
getSubscribers()
Provides read-only access to subscribers for extentions.void
send(Message message)
Sends a message to the channel, possibly blocking until there's room available in the channel.boolean
send(Message message, long timeout, java.util.concurrent.TimeUnit unit)
Sends a message to the channel, possibly blocking until there's room available in the channel, but never longer than the specified timeout.boolean
send(Message message, Timeout timeout)
Sends a message to the channel, possibly blocking until there's room available in the channel, but never longer than the specified timeout.<T extends SendPort<? super Message>>
Tsubscribe(T sub)
boolean
trySend(Message message)
Sends a message to the channel if the channel has room available.void
unsubscribe(SendPort<? super Message> sub)
void
unsubscribeAll()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface co.paralleluniverse.strands.channels.PortAutoCloseable
isClosed
-
-
-
-
Method Detail
-
getSubscribers
protected java.util.Collection<SendPort<? super Message>> getSubscribers()
Provides read-only access to subscribers for extentions. Not meant to be altered.
-
unsubscribeAll
public void unsubscribeAll()
-
send
public void send(Message message) throws SuspendExecution, java.lang.InterruptedException
Description copied from interface:SendPort
Sends a message to the channel, possibly blocking until there's room available in the channel. If the channel is full, this method may block, throw an exception, silently drop the message, or displace an old message from the channel. The behavior is determined by the channel'sOverflowPolicy
, set at construction time.- Specified by:
send
in interfaceSendPort<Message>
- Parameters:
message
- the message- Throws:
SuspendExecution
java.lang.InterruptedException
-
send
public boolean send(Message message, long timeout, java.util.concurrent.TimeUnit unit) throws SuspendExecution, java.lang.InterruptedException
Description copied from interface:SendPort
Sends a message to the channel, possibly blocking until there's room available in the channel, but never longer than the specified timeout. If the channel is full, this method may block, throw an exception, silently drop the message, or displace an old message from the channel. The behavior is determined by the channel'sOverflowPolicy
, set at construction time.- Specified by:
send
in interfaceSendPort<Message>
- Parameters:
message
- the messagetimeout
- the maximum duration this method is allowed to wait.unit
- the timeout's time unit- Returns:
true
if the message has been sent successfully;false
if the timeout has expired.- Throws:
SuspendExecution
java.lang.InterruptedException
-
send
public boolean send(Message message, Timeout timeout) throws SuspendExecution, java.lang.InterruptedException
Description copied from interface:SendPort
Sends a message to the channel, possibly blocking until there's room available in the channel, but never longer than the specified timeout. If the channel is full, this method may block, throw an exception, silently drop the message, or displace an old message from the channel. The behavior is determined by the channel'sOverflowPolicy
, set at construction time.- Specified by:
send
in interfaceSendPort<Message>
- Parameters:
message
- the messagetimeout
- the method will not block for longer than the amount remaining in theTimeout
- Returns:
true
if the message has been sent successfully;false
if the timeout has expired.- Throws:
SuspendExecution
java.lang.InterruptedException
-
trySend
public boolean trySend(Message message)
Description copied from interface:SendPort
Sends a message to the channel if the channel has room available. This method never blocks.
-
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
-
close
public void close(java.lang.Throwable t)
Description copied from interface:SendPort
Closes the channel so that no more messages could be sent to it, and signifies an exception occurred in the producer. The exception will be thrown when the consumer callsReceivePort
'sreceive
ortryReceive
, wrapped by aProducerException
. Messages already sent to the channel prior to calling this method will still be received.
-
-