Class ThreadSendPort<Message>
- java.lang.Object
-
- co.paralleluniverse.strands.channels.ThreadSendPort<Message>
-
public class ThreadSendPort<Message> extends java.lang.ObjectThis class is a simple convenience wrapper aroundSendPortthat can be used by threads (as opposed to fibers). Its methods do not declare they throwSuspendExecution.
-
-
Constructor Summary
Constructors Constructor Description ThreadSendPort(SendPort<Message> p)Creates a new convenience wrapper for using aSendPortin a thread.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the channel so that no more messages could be sent to it.booleanequals(java.lang.Object obj)inthashCode()voidsend(Message message)Sends a message to the channel, possibly blocking until there's room available in the channel.booleansend(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.java.lang.StringtoString()booleantrySend(Message message)Sends a message to the channel if the channel has room available.
-
-
-
Method Detail
-
send
public void send(Message message) throws java.lang.InterruptedException
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.- Parameters:
message-- Throws:
java.lang.InterruptedException
-
send
public boolean send(Message message, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
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.- Parameters:
message-timeout- the maximum duration this method is allowed to wait.unit- the timeout's time unit- Returns:
trueif the message has been sent successfully;falseif the timeout has expired.- Throws:
java.lang.InterruptedException
-
trySend
public boolean trySend(Message message)
Sends a message to the channel if the channel has room available. This method never blocks.- Parameters:
message-- Returns:
trueif the message has been sent;falseotherwise.
-
close
public void close()
Closes the channel so that no more messages could be sent to it.
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-