|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Transactor
An actor with built-in support for coordinated transactions.
Transactors implement the general pattern for using Coordinated
where
coordination messages are sent to other transactors then the coordinated transaction is
entered. Transactors can also accept explicitly sent Coordinated
messages.
Simple transactors will just implement the atomically
method which is similar to
the actor receive
method but runs within a coordinated transaction.
Example of a simple transactor that will join a coordinated transaction:
class Counter extends Transactor {
val count = Ref(0)
def atomically = implicit txn => {
case Increment => count transform (_ + 1)
}
}
To coordinate with other transactors override the coordinate
method.
The coordinate
method maps a message to a set of SendTo
objects, pairs of ActorRef
and a message.
You can use the include
and sendTo
methods to easily coordinate with other transactors.
The include
method will send on the same message that was received to other transactors.
The sendTo
method allows you to specify both the actor to send to, and message to send.
Example of coordinating an increment:
class FriendlyCounter(friend: ActorRef) extends Transactor {
val count = Ref(0)
override def coordinate = {
case Increment => include(friend)
}
def atomically = implicit txn => {
case Increment => count transform (_ + 1)
}
}
Using include
to include more than one transactor:
override def coordinate = {
case Message => include(actor1, actor2, actor3)
}
Using sendTo
to coordinate transactions but send on a different message
than the one that was received:
override def coordinate = {
case Message => sendTo(someActor -> SomeOtherMessage)
case SomeMessage => sendTo(actor1 -> Message1, actor2 -> Message2)
}
To execute directly before or after the coordinated transaction, override
the before
and after
methods. These methods also expect partial functions
like the receive method. They do not execute within the transaction.
To completely bypass coordinated transactions override the normally
method.
Any message matched by normally
will not be matched by the other methods,
and will not be involved in coordinated transactions. In this method you
can implement normal actor behavior, or use the normal STM atomic for
local transactions.
Coordinated
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface akka.actor.Actor |
---|
Actor.emptyBehavior$ |
Method Summary | |
---|---|
scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> |
after()
A Receive block that runs after the coordinated transaction. |
scala.PartialFunction<java.lang.Object,scala.collection.immutable.Set<SendTo>> |
alone()
Default coordination - no other transactors. |
scala.Function1<scala.concurrent.stm.InTxn,scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit>> |
atomically()
The Receive block to run inside the coordinated transaction. |
scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> |
before()
A Receive block that runs before the coordinated transaction is entered. |
scala.PartialFunction<java.lang.Object,scala.collection.immutable.Set<SendTo>> |
coordinate()
Override this method to coordinate with other transactors. |
scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> |
doNothing()
Default catch-all for the different Receive methods. |
scala.collection.immutable.Set<SendTo> |
include(scala.collection.Seq<ActorRef> actors)
Include other actors in this coordinated transaction and send them the same message as received. |
scala.collection.immutable.Set<SendTo> |
nobody()
Empty set of transactors to send to. |
scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> |
normally()
Bypass transactionality and behave like a normal actor. |
scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> |
receive()
Implement a general pattern for using coordinated transactions. |
scala.collection.immutable.Set<SendTo> |
sendTo(scala.collection.Seq<scala.Tuple2<ActorRef,java.lang.Object>> pairs)
Include other actors in this coordinated transaction and specify the message to send by providing ActorRef -> Message pairs. |
TransactorSettings |
settings()
|
Methods inherited from interface akka.actor.Actor |
---|
context, noSender, postRestart, postStop, preRestart, preStart, self, sender, supervisorStrategy, unhandled |
Method Detail |
---|
TransactorSettings settings()
scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> receive()
receive
in interface Actor
scala.PartialFunction<java.lang.Object,scala.collection.immutable.Set<SendTo>> coordinate()
scala.PartialFunction<java.lang.Object,scala.collection.immutable.Set<SendTo>> alone()
scala.collection.immutable.Set<SendTo> nobody()
scala.collection.immutable.Set<SendTo> include(scala.collection.Seq<ActorRef> actors)
scala.collection.immutable.Set<SendTo> sendTo(scala.collection.Seq<scala.Tuple2<ActorRef,java.lang.Object>> pairs)
scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> before()
scala.Function1<scala.concurrent.stm.InTxn,scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit>> atomically()
For example:
def atomically = implicit txn => {
case Increment => count transform (_ + 1)
}
scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> after()
scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> normally()
scala.PartialFunction<java.lang.Object,scala.runtime.BoxedUnit> doNothing()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |