Trait/Object

scala.actors

Actor

Related Docs: object Actor | package actors

Permalink

trait Actor extends InternalActor with ReplyReactor

Provides lightweight, concurrent actors. Actors are created by extending the Actor trait (alternatively, one of the factory methods in its companion object can be used). The behavior of an Actor subclass is defined by implementing its act method:

class MyActor extends Actor {
  def act() {
    // actor behavior goes here
  }
}

A new Actor instance is started by invoking its start method.

Note: care must be taken when invoking thread-blocking methods other than those provided by the Actor trait or its companion object (such as receive). Blocking the underlying thread inside an actor may lead to starvation of other actors. This also applies to actors hogging their thread for a long time between invoking receive/react.

If actors use blocking operations (for example, methods for blocking I/O), there are several options:

The main ideas of the implementation are explained in the two papers

Annotations
@SerialVersionUID() @deprecated
Deprecated

(Since version 2.11.0) Use the akka.actor package instead. For migration from the scala.actors package refer to the Actors Migration Guide.

Source
Actor.scala
Linear Supertypes
ReplyReactor, InternalActor, Serializable, java.io.Serializable, InputChannel[Any], ActorCanReply, InternalReplyReactor, ReactorCanReply, Reactor[Any], Combinators, AbstractActor, CanReply[Any, Any], OutputChannel[Any], AnyRef, Any
Known Subclasses
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Actor
  2. ReplyReactor
  3. InternalActor
  4. Serializable
  5. Serializable
  6. InputChannel
  7. ActorCanReply
  8. InternalReplyReactor
  9. ReactorCanReply
  10. Reactor
  11. Combinators
  12. AbstractActor
  13. CanReply
  14. OutputChannel
  15. AnyRef
  16. Any
Implicitly
  1. by mkBody
  2. by any2stringadd
  3. by StringFormat
  4. by Ensuring
  5. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. type Future[+P] = actors.Future[P]

    Permalink
    Definition Classes
    ReactorCanReply → CanReply

Abstract Value Members

  1. abstract def act(): Unit

    Permalink

    The reactor's behavior is specified by implementing this method.

    The reactor's behavior is specified by implementing this method.

    Definition Classes
    Reactor

Concrete Value Members

  1. def !(msg: Any): Unit

    Permalink

    Sends msg to this ReplyReactor (asynchronous).

    Sends msg to this ReplyReactor (asynchronous).

    msg

    the message to send

    Definition Classes
    InternalReplyReactorReactorOutputChannel
  2. def !!(msg: Any): Future[Any]

    Permalink

    Sends msg to this actor and immediately returns a future representing the reply value.

    Sends msg to this actor and immediately returns a future representing the reply value.

    msg

    the message to be sent

    returns

    the future

    Definition Classes
    ActorCanReply → ReactorCanReply → CanReply
  3. def !![A](msg: Any, handler: PartialFunction[Any, A]): Future[A]

    Permalink

    Sends msg to this actor and immediately returns a future representing the reply value.

    Sends msg to this actor and immediately returns a future representing the reply value. The reply is post-processed using the partial function handler. This also allows to recover a more precise type for the reply value.

    msg

    the message to be sent

    handler

    the function to be applied to the response

    returns

    the future

    Definition Classes
    ActorCanReply → ReactorCanReply → CanReply
  4. final def !=(arg0: Any): Boolean

    Permalink

    Test two objects for inequality.

    Test two objects for inequality.

    returns

    true if !(this == that), false otherwise.

    Definition Classes
    AnyRef → Any
  5. def !?(msec: Long, msg: Any): Option[Any]

    Permalink

    Sends msg to this actor and awaits reply (synchronous) within msec milliseconds.

    Sends msg to this actor and awaits reply (synchronous) within msec milliseconds.

    msec

    the time span before timeout

    msg

    the message to be sent

    returns

    None in case of timeout, otherwise Some(x) where x is the reply

    Definition Classes
    ActorCanReply → ReactorCanReply → CanReply
  6. def !?(msg: Any): Any

    Permalink

    Sends msg to this actor and awaits reply (synchronous).

    Sends msg to this actor and awaits reply (synchronous).

    msg

    the message to be sent

    returns

    the reply

    Definition Classes
    ActorCanReply → ReactorCanReply → CanReply
  7. final def ##(): Int

    Permalink

    Equivalent to x.hashCode except for boxed numeric types and null.

    Equivalent to x.hashCode except for boxed numeric types and null. For numerics, it returns a hash value which is consistent with value equality: if two value type instances compare as true, then ## will produce the same hash value for each of them. For null returns a hashcode where null.hashCode throws a NullPointerException.

    returns

    a hash value consistent with ==

    Definition Classes
    AnyRef → Any
  8. def +(other: String): String

    Permalink
    Implicit information
    This member is added by an implicit conversion from Actor to any2stringadd[Actor] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  9. def ->[B](y: B): (Actor, B)

    Permalink
    Implicit information
    This member is added by an implicit conversion from Actor to ArrowAssoc[Actor] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  10. final def ==(arg0: Any): Boolean

    Permalink

    The expression x == that is equivalent to if (x eq null) that eq null else x.equals(that).

    The expression x == that is equivalent to if (x eq null) that eq null else x.equals(that).

    returns

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

    Definition Classes
    AnyRef → Any
  11. def ?: Any

    Permalink

    Receives the next message from the mailbox

    Receives the next message from the mailbox

    Definition Classes
    InternalActor → InputChannel
  12. def andThen[b](other: ⇒ b): Unit

    Permalink
    Implicit information
    This member is added by an implicit conversion from Actor to Body[Actor] performed by method mkBody in scala.actors.Actor.
    Definition Classes
    Body
  13. final def asInstanceOf[T0]: T0

    Permalink

    Cast the receiver object to be of type T0.

    Cast the receiver object to be of type T0.

    Note that the success of a cast at runtime is modulo Scala's erasure semantics. Therefore the expression 1.asInstanceOf[String] will throw a ClassCastException at runtime, while the expression List(1).asInstanceOf[List[String]] will not. In the latter example, because the type argument is erased as part of compilation it is not possible to check whether the contents of the list are of the requested type.

    returns

    the receiver object.

    Definition Classes
    Any
    Exceptions thrown

    ClassCastException if the receiver object is not an instance of the erasure of type T0.

  14. def clone(): AnyRef

    Permalink

    Create a copy of the receiver object.

    Create a copy of the receiver object.

    The default implementation of the clone method is platform dependent.

    returns

    a copy of the receiver object.

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
    Note

    not specified by SLS as a member of AnyRef

  15. def continue(): Unit

    Permalink

    Continues with the execution of the closure registered as continuation following andThen.

    Continues with the execution of the closure registered as continuation following andThen. Continues with the execution of the next loop iteration when invoked inside the body of loop or loopWhile.

    Definition Classes
    Combinators
  16. def ensuring(cond: (Actor) ⇒ Boolean, msg: ⇒ Any): Actor

    Permalink
    Implicit information
    This member is added by an implicit conversion from Actor to Ensuring[Actor] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  17. def ensuring(cond: (Actor) ⇒ Boolean): Actor

    Permalink
    Implicit information
    This member is added by an implicit conversion from Actor to Ensuring[Actor] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  18. def ensuring(cond: Boolean, msg: ⇒ Any): Actor

    Permalink
    Implicit information
    This member is added by an implicit conversion from Actor to Ensuring[Actor] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  19. def ensuring(cond: Boolean): Actor

    Permalink
    Implicit information
    This member is added by an implicit conversion from Actor to Ensuring[Actor] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  20. final def eq(arg0: AnyRef): Boolean

    Permalink

    Tests whether the argument (that) is a reference to the receiver object (this).

    Tests whether the argument (that) is a reference to the receiver object (this).

    The eq method implements an equivalence relation on non-null instances of AnyRef, and has three additional properties:

    • It is consistent: for any non-null instances x and y of type AnyRef, multiple invocations of x.eq(y) consistently returns true or consistently returns false.
    • For any non-null instance x of type AnyRef, x.eq(null) and null.eq(x) returns false.
    • null.eq(null) returns true.

    When overriding the equals or hashCode methods, it is important to ensure that their behavior is consistent with reference equality. Therefore, if two objects are references to each other (o1 eq o2), they should be equal to each other (o1 == o2) and they should hash to the same value (o1.hashCode == o2.hashCode).

    returns

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

    Definition Classes
    AnyRef
  21. def equals(arg0: Any): Boolean

    Permalink

    The equality method for reference types.

    The equality method for reference types. Default implementation delegates to eq.

    See also equals in scala.Any.

    returns

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

    Definition Classes
    AnyRef → Any
  22. def exceptionHandler: PartialFunction[Exception, Unit]

    Permalink

    This partial function is applied to exceptions that propagate out of this reactor's body.

    This partial function is applied to exceptions that propagate out of this reactor's body.

    Attributes
    protected[scala.actors]
    Definition Classes
    Reactor
  23. def exit(): Nothing

    Permalink

    Terminates with exit reason 'normal.

    Terminates with exit reason 'normal.

    Attributes
    protected[scala.actors]
    Definition Classes
    InternalActor → Reactor
  24. def exit(reason: AnyRef): Nothing

    Permalink

    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.

    Attributes
    protected[scala.actors]
    Definition Classes
    InternalActor
  25. def finalize(): Unit

    Permalink

    Called by the garbage collector on the receiver object when there are no more references to the object.

    Called by the garbage collector on the receiver object when there are no more references to the object.

    The details of when and if the finalize method is invoked, as well as the interaction between finalize and non-local returns and exceptions, are all platform dependent.

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
    Note

    not specified by SLS as a member of AnyRef

  26. def formatted(fmtstr: String): String

    Permalink
    Implicit information
    This member is added by an implicit conversion from Actor to StringFormat[Actor] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  27. def forward(msg: Any): Unit

    Permalink

    Forwards msg to this ReplyReactor (asynchronous).

    Forwards msg to this ReplyReactor (asynchronous).

    msg

    the message to forward

    Definition Classes
    InternalReplyReactorReactorOutputChannel
  28. final def getClass(): Class[_]

    Permalink

    A representation that corresponds to the dynamic class of the receiver object.

    A representation that corresponds to the dynamic class of the receiver object.

    The nature of the representation is platform dependent.

    returns

    a representation that corresponds to the dynamic class of the receiver object.

    Definition Classes
    AnyRef → Any
    Note

    not specified by SLS as a member of AnyRef

  29. def getState: Actor.State.Value

    Permalink

    State of this actor

    State of this actor

    returns

    the execution state

    Definition Classes
    InternalActor → InternalReplyReactorReactor
  30. def hashCode(): Int

    Permalink

    The hashCode method for reference types.

    The hashCode method for reference types. See hashCode in scala.Any.

    returns

    the hash code value for this object.

    Definition Classes
    AnyRef → Any
  31. def internalSender: OutputChannel[Any]

    Permalink

    Returns the ReplyReactor which sent the last received message.

    Returns the ReplyReactor which sent the last received message.

    Attributes
    protected[scala.actors]
    Definition Classes
    InternalReplyReactor
  32. final def isInstanceOf[T0]: Boolean

    Permalink

    Test whether the dynamic type of the receiver object is T0.

    Test whether the dynamic type of the receiver object is T0.

    Note that the result of the test is modulo Scala's erasure semantics. Therefore the expression 1.isInstanceOf[String] will return false, while the expression List(1).isInstanceOf[List[String]] will return true. In the latter example, because the type argument is erased as part of compilation it is not possible to check whether the contents of the list are of the specified type.

    returns

    true if the receiver object is an instance of erasure of type T0; false otherwise.

    Definition Classes
    Any
  33. def link(body: ⇒ Unit): Actor

    Permalink

    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

    Definition Classes
    InternalActor
  34. def link(to: ActorRef): ActorRef

    Permalink

    Links self to actor to.

    Links self to actor to.

    to

    the actor to link to

    returns

    the parameter actor

    Definition Classes
    InternalActor
  35. def link(to: AbstractActor): AbstractActor

    Permalink

    Links self to actor to.

    Links self to actor to.

    to

    the actor to link to

    returns

    the parameter actor

    Definition Classes
    InternalActor
  36. def loop(body: ⇒ Unit): Unit

    Permalink

    Repeatedly executes body.

    Repeatedly executes body.

    body

    the block to be executed

    Definition Classes
    Combinators
  37. def loopWhile(cond: ⇒ Boolean)(body: ⇒ Unit): Unit

    Permalink

    Repeatedly executes body while the condition cond is true.

    Repeatedly executes body while the condition cond is true.

    cond

    the condition to test

    body

    the block to be executed

    Definition Classes
    Combinators
  38. def mailboxSize: Int

    Permalink
    Attributes
    protected[scala.actors]
    Definition Classes
    Reactor
  39. implicit def mkBody[A](body: ⇒ A): Body[A]

    Permalink

    Enables the composition of suspendable closures using andThen, loop, loopWhile, etc.

    Enables the composition of suspendable closures using andThen, loop, loopWhile, etc.

    Definition Classes
    Reactor → Combinators
  40. final def ne(arg0: AnyRef): Boolean

    Permalink

    Equivalent to !(this eq that).

    Equivalent to !(this eq that).

    returns

    true if the argument is not a reference to the receiver object; false otherwise.

    Definition Classes
    AnyRef
  41. final def notify(): Unit

    Permalink

    Wakes up a single thread that is waiting on the receiver object's monitor.

    Wakes up a single thread that is waiting on the receiver object's monitor.

    Definition Classes
    AnyRef
    Note

    not specified by SLS as a member of AnyRef

  42. final def notifyAll(): Unit

    Permalink

    Wakes up all threads that are waiting on the receiver object's monitor.

    Wakes up all threads that are waiting on the receiver object's monitor.

    Definition Classes
    AnyRef
    Note

    not specified by SLS as a member of AnyRef

  43. def react(handler: PartialFunction[Any, Unit]): Nothing

    Permalink

    See the companion object's react method.

    See the companion object's react method.

    Definition Classes
    InternalActor → InputChannelInternalReplyReactorReactor
  44. def reactWithin(msec: Long)(handler: PartialFunction[Any, Unit]): Nothing

    Permalink

    See the companion object's reactWithin method.

    See the companion object's reactWithin method.

    msec

    the time span before timeout

    Definition Classes
    InternalActor → InputChannelInternalReplyReactor
  45. def receive[R](f: PartialFunction[Any, R]): R

    Permalink

    See the companion object's receive method.

    See the companion object's receive method.

    f

    a partial function with message patterns and actions

    returns

    result of processing the received value

    Definition Classes
    InternalActor → InputChannel
  46. def receiveWithin[R](msec: Long)(f: PartialFunction[Any, R]): R

    Permalink

    See the companion object's receiveWithin method.

    See the companion object's receiveWithin method.

    msec

    the time span before timeout

    f

    a partial function with message patterns and actions

    returns

    result of processing the received value

    Definition Classes
    InternalActor → InputChannel
  47. def receiver: Actor

    Permalink

    Returns the Actor that is receiving from this reactor.

    Returns the Actor that is receiving from this reactor.

    Definition Classes
    ReactorOutputChannel
  48. def reply(msg: Any): Unit

    Permalink

    Replies with msg to the sender.

    Replies with msg to the sender.

    Attributes
    protected[scala.actors]
    Definition Classes
    InternalReplyReactor
  49. def restart(): Unit

    Permalink

    Restarts this reactor.

    Restarts this reactor.

    Definition Classes
    Reactor
    Exceptions thrown

    java.lang.IllegalStateException if the reactor is not in state Actor.State.Terminated

  50. def scheduler: IScheduler

    Permalink
    Attributes
    protected[scala.actors]
    Definition Classes
    InternalActor → Reactor
  51. def send(msg: Any, replyTo: OutputChannel[Any]): Unit

    Permalink

    Sends msg to this reactor (asynchronous) supplying explicit reply destination.

    Sends msg to this reactor (asynchronous) supplying explicit reply destination.

    msg

    the message to send

    replyTo

    the reply destination

    Definition Classes
    ReactorOutputChannel
  52. def sender: OutputChannel[Any]

    Permalink
    Attributes
    protected[scala.actors]
    Definition Classes
    ReplyReactor
  53. def start(): Actor

    Permalink

    Starts this actor.

    Starts this actor. This method is idempotent.

    Definition Classes
    Actor → InternalActor → Reactor
  54. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  55. def toString(): String

    Permalink

    Creates a String representation of this object.

    Creates a String representation of this object. The default representation is platform dependent. On the java platform it is the concatenation of the class name, "@", and the object's hashcode in hexadecimal.

    returns

    a String representation of the object.

    Definition Classes
    AnyRef → Any
  56. def trapExit: Boolean

    Permalink
    Definition Classes
    InternalActor
  57. def trapExit_=(value: Boolean): Unit

    Permalink
    Definition Classes
    InternalActor
  58. def unlink(from: ActorRef): Unit

    Permalink

    Unlinks self from actor from.

    Unlinks self from actor from.

    Definition Classes
    InternalActor
  59. def unlink(from: AbstractActor): Unit

    Permalink

    Unlinks self from actor from.

    Unlinks self from actor from.

    Definition Classes
    InternalActor
  60. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  61. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  62. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  63. def [B](y: B): (Actor, B)

    Permalink
    Implicit information
    This member is added by an implicit conversion from Actor to ArrowAssoc[Actor] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Inherited from ReplyReactor

Inherited from InternalActor

Inherited from Serializable

Inherited from java.io.Serializable

Inherited from InputChannel[Any]

Inherited from ActorCanReply

Inherited from InternalReplyReactor

Inherited from ReactorCanReply

Inherited from Reactor[Any]

Inherited from Combinators

Inherited from AbstractActor

Inherited from CanReply[Any, Any]

Inherited from OutputChannel[Any]

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion mkBody from Actor to Body[Actor]

Inherited by implicit conversion any2stringadd from Actor to any2stringadd[Actor]

Inherited by implicit conversion StringFormat from Actor to StringFormat[Actor]

Inherited by implicit conversion Ensuring from Actor to Ensuring[Actor]

Inherited by implicit conversion ArrowAssoc from Actor to ArrowAssoc[Actor]

Ungrouped