scala.actors

Actor

object Actor extends AnyRef

The Actor object provides functions for the definition of actors, as well as actor operations, such as receive, react, reply, etc.

Inherits

  1. AnyRef
  2. Any

Value Members

  1. def ?: Any

    Receives the next message from the mailbox of the current actor self

    Receives the next message from the mailbox of the current actor self.

  2. def actor(body: ⇒ Unit): Actor

    This is a factory method for creating actors

    This is a factory method for creating actors.

    The following example demonstrates its usage:

    import scala.actors.Actor._
    ...
    val a = actor {
      ...
    }
    

    body

    the code block to be executed by the newly created actor

    returns

    the newly created actor. Note that it is automatically started.

  3. def clearSelf: Unit

    Removes any reference to an Actor instance currently stored in thread-local storage

    Removes any reference to an Actor instance currently stored in thread-local storage.

    This allows to release references from threads that are potentially long-running or being re-used (e.g. inside a thread pool). Permanent references in thread-local storage are a potential memory leak.

  4. def continue: Unit

  5. def equals(arg0: Any): Boolean

    This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence

    This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence.

    The default implementations of this method is an equivalence relation:

    • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
    • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
    • It is transitive: for any instances x, y, and z of type AnyRef if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

    If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is often necessary to override hashCode to ensure that objects that are "equal" (o1.equals(o2) returns true) hash to the same Int (o1.hashCode.equals(o2.hashCode)).

    arg0

    the object to compare against this object for equality.

    returns

    true if the receiver object is equivalent to the argument; false otherwise.

    definition classes: AnyRef ⇐ Any
  6. def eventloop(f: PartialFunction[Any, Unit]): Nothing

  7. def exit(): Nothing

    Terminates execution of self with the following effect on linked actors:

    Terminates execution of self with the following effect on linked actors:

    For each linked actor a with trapExit set to true, send message Exit(self, 'normal) to a.

  8. def exit(reason: AnyRef): Nothing

    Terminates execution of self with the following effect on linked actors:

    Terminates execution of self with the following effect on linked actors:

    For each linked actor a with trapExit set to true, send message Exit(self, reason) to a.

    For each linked actor a with trapExit set to false (default), call a.exit(reason) if reason != 'normal.

  9. def hashCode(): Int

    Returns a hash code value for the object

    Returns a hash code value for the object.

    The default hashing algorithm is platform dependent.

    Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

    definition classes: AnyRef ⇐ Any
  10. def link(body: ⇒ Unit): Actor

    Links self to the actor defined by body

    Links self to the actor defined by body.

    body

    the body of the actor to link to

    returns

    the parameter actor

  11. def link(to: AbstractActor): AbstractActor

    Links self to actor to

    Links self to actor to.

    to

    the actor to link to

    returns

    the parameter actor

  12. def loop(body: ⇒ Unit): Unit

    Causes self to repeatedly execute body

    Causes self to repeatedly execute body.

    body

    the code block to be executed

  13. def loopWhile(cond: ⇒ Boolean)(body: ⇒ Unit): Unit

    Causes self to repeatedly execute body while the condition cond is true

    Causes self to repeatedly execute body while the condition cond is true.

    cond

    the condition to test

    body

    the code block to be executed

  14. def mailboxSize: Int

    Returns the number of messages in self's mailbox

    Returns the number of messages in self's mailbox

  15. def mkBody[a](body: ⇒ a): Body[a]

  16. def react(f: PartialFunction[Any, Unit]): Nothing

    Lightweight variant of receive

    Lightweight variant of receive.

    Actions in f have to contain the rest of the computation of self, as this method will never return.

    f

    a partial function specifying patterns and actions

    returns

    this function never returns

  17. def reactWithin(msec: Long)(f: PartialFunction[Any, Unit]): Nothing

    Lightweight variant of receiveWithin

    Lightweight variant of receiveWithin.

    Actions in f have to contain the rest of the computation of self, as this method will never return.

    msec

    the time span before timeout

    f

    a partial function specifying patterns and actions

    returns

    this function never returns

  18. def reactor(body: ⇒ Responder[Unit]): Actor

    This is a factory method for creating actors whose body is defined using a Responder

    This is a factory method for creating actors whose body is defined using a Responder.

    The following example demonstrates its usage:

    import scala.actors.Actor._
    import Responder.exec
    ...
    val a = reactor {
      for {
        res <- b !! MyRequest;
        if exec(println("result: "+res))
      } yield {}
    }
    

    body

    the Responder to be executed by the newly created actor

    returns

    the newly created actor. Note that it is automatically started.

  19. def receive[A](f: PartialFunction[Any, A]): A

    Receives a message from the mailbox of self

    Receives a message from the mailbox of self. Blocks if no message matching any of the cases of f can be received.

    f

    a partial function specifying patterns and actions

    returns

    the result of processing the received message

  20. def receiveWithin[R](msec: Long)(f: PartialFunction[Any, R]): R

    Receives a message from the mailbox of self

    Receives a message from the mailbox of self. Blocks at most msec milliseconds if no message matching any of the cases of f can be received. If no message could be received the TIMEOUT action is executed if specified.

    msec

    the time span before timeout

    f

    a partial function specifying patterns and actions

    returns

    the result of processing the received message

  21. def reply(): Unit

    Send () to the actor waiting in a call to !?

    Send () to the actor waiting in a call to !?.

  22. def reply(msg: Any): Unit

    Send msg to the actor waiting in a call to !?

    Send msg to the actor waiting in a call to !?.

  23. def resetProxy: Unit

    Resets an actor proxy associated with the current thread

    Resets an actor proxy associated with the current thread. It replaces the implicit ActorProxy instance of the current thread (if any) with a new instance.

    This permits to re-use the current thread as an actor even if its ActorProxy has died for some reason.

  24. def respondOn[A, B](fun: (PartialFunction[A, Unit]) ⇒ Nothing): (PartialFunction[A, B]) ⇒ Responder[B]

    Converts a synchronous event-based operation into an asynchronous Responder

    Converts a synchronous event-based operation into an asynchronous Responder.

    The following example demonstrates its usage:

    val adder = reactor {
      for {
        _ <- respondOn(react) { case Add(a, b) => reply(a+b) }
      } yield {}
    }
    

  25. def self: Actor

    Returns the currently executing actor

    Returns the currently executing actor. Should be used instead of this in all blocks of code executed by actors.

  26. def sender: OutputChannel[Any]

    Returns the actor which sent the last received message

    Returns the actor which sent the last received message.

  27. def toString(): String

    Returns a string representation of the object

    Returns a string representation of the object.

    The default representation is platform dependent.

    definition classes: AnyRef ⇐ Any
  28. def unlink(from: Actor): Unit

    Unlinks self from actor from

    Unlinks self from actor from.

    from

    the actor to unlink from