Class 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 throws UnsupportedOperationException.
      void close​(java.lang.Throwable t)
      This implementation throws UnsupportedOperationException.
      boolean equals​(java.lang.Object obj)  
      protected ActorImpl<Message> getImpl()  
      java.lang.String getName()  
      int hashCode()  
      protected void interrupt()
      Interrupts the actor's strand
      void 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
    • Constructor Detail

      • ActorRef

        protected ActorRef()
    • 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's OverflowPolicy, set at construction time. However, unlike regular channels, this method never throws QueueCapacityExceededException. If the mailbox overflows, and has been configured with the THROW policy, the exception will be thrown into the actor.
        Specified by:
        send in interface SendPort<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 than send(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's OverflowPolicy, 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 interface SendPort<Message>
        Parameters:
        message - the 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 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's OverflowPolicy, 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 interface SendPort<Message>
        Parameters:
        message - the message
        timeout - the method will not block for longer than the amount remaining in the Timeout
        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.
        Specified by:
        trySend in interface SendPort<Message>
        Parameters:
        msg - the message
        Returns:
        true if the message has been sent; false otherwise.
      • close

        public void close()
        This implementation throws UnsupportedOperationException.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface PortAutoCloseable
      • close

        public void close​(java.lang.Throwable t)
        This implementation throws UnsupportedOperationException.
        Specified by:
        close in interface SendPort<Message>
        Parameters:
        t - the exception causing the close
      • interrupt

        protected void interrupt()
        Interrupts the actor's strand
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object