Scala Library
|
|
scala/actors/Actor.scala
]
object
Actor
extends
AnyRefActor
object provides functions for the definition of
actors, as well as actor operations, such as
receive
, react
, reply
,
etc.Method Summary | |
def
|
?
: Any
Receives the next message from the mailbox of the current actor
self . |
def
|
actor (body : => Unit) : Actor |
def
|
clearSelf
: Unit
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. |
def
|
continue : Unit |
def
|
eventloop (f : PartialFunction[Any, Unit]) : Nothing |
def
|
exit (reason : AnyRef) : Nothing |
def
|
exit : Nothing |
def
|
link
(body : => Unit) : Actor
Links
self to actor defined by body . |
def
|
link
(to : AbstractActor) : AbstractActor
Links
self to actor to . |
def
|
loop
(body : => Unit) : Unit
Causes
self to repeatedly execute
body . |
def
|
loopWhile
(cond : => Boolean)(body : => Unit) : Unit
Causes
self to repeatedly execute
body while the condition
cond is true . |
def
|
mailboxSize
: Int
Returns the number of messages in
self 's mailbox |
implicit def
|
mkBody [a](body : => a) : Body[a] |
def
|
react
(f : PartialFunction[Any, Unit]) : Nothing
Lightweight variant of
receive .
Actions in f have to contain the rest of the
computation of self , as this method will never
return. |
def
|
reactWithin
(msec : Long)(f : PartialFunction[Any, Unit]) : Nothing
Lightweight variant of
receiveWithin .
Actions in f have to contain the rest of the
computation of self , as this method will never
return. |
def
|
reactor (body : => Responder[Unit]) : Actor |
def
|
receive
[A](f : PartialFunction[Any, A]) : A
Receives a message from the mailbox of
self . Blocks if no message matching any of the
cases of f can be received. |
def
|
receiveWithin
[R](msec : Long)(f : PartialFunction[Any, R]) : R
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. |
def
|
reply
(msg : Any) : Unit
Send
msg to the actor waiting in a call to
!? . |
def
|
reply
: Unit
Send
() to the actor waiting in a call to
!? . |
def
|
resetProxy
: Unit
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. |
def
|
respondOn [A, B](fun : (PartialFunction[A, Unit]) => Nothing) : (PartialFunction[A, B]) => Responder[B] |
def
|
self
: Actor
Returns the currently executing actor. Should be used instead
of
this in all blocks of code executed by
actors. |
def
|
sender
: OutputChannel[Any]
Returns the actor which sent the last received message.
|
def
|
unlink
(from : Actor) : Unit
Unlinks
self from actor from . |
Methods inherited from AnyRef | |
getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized |
Methods inherited from Any | |
==, !=, isInstanceOf, asInstanceOf |
Method Details |
def
self : Actor
this
in all blocks of code executed by
actors.
def
resetProxy : Unit
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.
def
clearSelf : Unit
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.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
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
def
? : Any
self
.
def
receive[A](f : PartialFunction[Any, A]) : A
self
. Blocks if no message matching any of the
cases of f
can be received.f -
a partial function specifying patterns and actions
def
receiveWithin[R](msec : Long)(f : PartialFunction[Any, R]) : R
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 timeoutf -
a partial function specifying patterns and actions
def
react(f : PartialFunction[Any, Unit]) : Nothing
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
def
reactWithin(msec : Long)(f : PartialFunction[Any, Unit]) : Nothing
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 timeoutf -
a partial function specifying patterns and actions
def
eventloop(f : PartialFunction[Any, Unit]) : Nothing
def
sender : OutputChannel[Any]
msg
to the actor waiting in a call to
!?
.
def
reply : Unit
()
to the actor waiting in a call to
!?
.
def
mailboxSize : Int
self
's mailboxself
's mailbox
def
respondOn[A, B](fun : (PartialFunction[A, Unit]) => Nothing) : (PartialFunction[A, B]) => Responder[B]
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 {} }
self
to repeatedly execute
body
.body -
the code block to be executedself
to repeatedly execute
body
while the condition
cond
is true
.cond -
the condition to testbody -
the code block to be executed
def
link(to : AbstractActor) : AbstractActor
self
to actor to
.to -
the actor to link toself
to actor defined by body
.body -
...self
from actor from
.from -
the actor to unlink from
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
.
def
exit : Nothing
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
.
def
continue : Unit
Scala Library
|
|