Package co.paralleluniverse.actors
Class ActorRef<Message>
- java.lang.Object
-
- co.paralleluniverse.actors.ActorRef<Message>
-
- All Implemented Interfaces:
Port<Message>
,PortAutoCloseable
,SendPort<Message>
,java.io.Serializable
,java.lang.AutoCloseable
- Direct Known Subclasses:
ActorRefDelegate
public class ActorRef<Message> extends java.lang.Object implements SendPort<Message>, java.io.Serializable
An actor's external API (for use by code not part of the actor).- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
This implementation throwsUnsupportedOperationException
.void
close(java.lang.Throwable t)
This implementation throwsUnsupportedOperationException
.boolean
equals(java.lang.Object obj)
protected ActorImpl<Message>
getImpl()
java.lang.String
getName()
int
hashCode()
protected void
interrupt()
Interrupts the actor's strandvoid
send(Message message)
Sends a message to the actor, possibly blocking until there's room available in the mailbox.boolean
send(Message message, long timeout, java.util.concurrent.TimeUnit unit)
Sends a message to the actor, possibly blocking until there's room available in the mailbox, but never longer than the specified timeout.boolean
send(Message message, Timeout timeout)
Sends a message to the actor, possibly blocking until there's room available in the mailbox, but never longer than the specified timeout.void
sendSync(Message message)
Sends a message to the actor, and attempts to schedule the actor's strand for immediate execution.java.lang.String
toString()
boolean
trySend(Message msg)
Sends a message to the actor if the channel has mailbox available.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface co.paralleluniverse.strands.channels.PortAutoCloseable
isClosed
-
-
-
-
Method Detail
-
getName
public java.lang.String getName()
-
send
public void send(Message message) throws SuspendExecution
Sends a message to the actor, possibly blocking until there's room available in the mailbox. If the mailbox is full, this method may block or silently drop the message. The behavior is determined by the mailbox'sOverflowPolicy
, set at construction time. However, unlike regular channels, this method never throwsQueueCapacityExceededException
. If the mailbox overflows, and has been configured with theTHROW
policy, the exception will be thrown into the actor.- Specified by:
send
in interfaceSendPort<Message>
- Parameters:
message
-- Throws:
SuspendExecution
-
sendSync
public void sendSync(Message message) throws SuspendExecution
Sends a message to the actor, and attempts to schedule the actor's strand for immediate execution. This method may be called when a response message is expected from this actor; in this case, this method might provide better latency thansend(java.lang.Object)
.- Parameters:
message
-- Throws:
SuspendExecution
-
send
public boolean send(Message message, long timeout, java.util.concurrent.TimeUnit unit) throws SuspendExecution, java.lang.InterruptedException
Sends a message to the actor, possibly blocking until there's room available in the mailbox, but never longer than the specified timeout. If the mailbox 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 mailbox'sOverflowPolicy
, set at construction time.Currently, this behavior is not yet supported. The message will be sent using
send(Object)
and the timeout argument will be disregarded- 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 elapsed.- Throws:
SuspendExecution
java.lang.InterruptedException
-
send
public boolean send(Message message, Timeout timeout) throws SuspendExecution, java.lang.InterruptedException
Sends a message to the actor, possibly blocking until there's room available in the mailbox, 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 mailbox'sOverflowPolicy
, set at construction time.Currently, this behavior is not yet supported. The message will be sent using
send(Object)
and the timeout argument will be disregarded- 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 elapsed.- Throws:
SuspendExecution
java.lang.InterruptedException
-
trySend
public boolean trySend(Message msg)
Sends a message to the actor if the channel has mailbox available. This method never blocks.
-
close
public void close()
This implementation throwsUnsupportedOperationException
.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacePortAutoCloseable
-
close
public void close(java.lang.Throwable t)
This implementation throwsUnsupportedOperationException
.
-
interrupt
protected void interrupt()
Interrupts the actor's strand
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-