Class ThreadSendPort<Message>
- java.lang.Object
-
- co.paralleluniverse.strands.channels.ThreadSendPort<Message>
-
public class ThreadSendPort<Message> extends java.lang.Object
This class is a simple convenience wrapper aroundSendPort
that 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 aSendPort
in a thread.
-
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()
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.java.lang.String
toString()
boolean
trySend(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:
true
if the message has been sent successfully;false
if 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:
true
if the message has been sent;false
otherwise.
-
close
public void close()
Closes the channel so that no more messages could be sent to it.
-
hashCode
public final int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public final java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-