Coordinated
is a message wrapper that adds a CommitBarrier
for explicitly
coordinating transactions across actors or threads.
Akka-specific exception for coordinated transactions.
Akka-specific exception for coordinated transactions.
(Since version 2.3) akka.transactor will be removed
Used for specifying actor refs and messages to send to during coordination.
Used for specifying actor refs and messages to send to during coordination.
(Since version 2.3) akka.transactor will be removed
An actor with built-in support for coordinated transactions.
An actor with built-in support for coordinated transactions.
Transactors implement the general pattern for using akka.transactor.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 akka.transactor.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.
(Since version 2.3) akka.transactor will be removed
(Since version 2.3) akka.transactor will be removed
An UntypedActor version of transactor for using from Java.
An UntypedActor version of transactor for using from Java.
(Since version 2.3) akka.transactor will be removed
Coordinated transactions across actors.
Coordinated transactions across actors.
(Since version 2.3) akka.transactor will be removed
TransactorExtension is an Akka Extension to hold settings for transactors.
TransactorExtension is an Akka Extension to hold settings for transactors.
(Since version 2.3) akka.transactor will be removed
Coordinated
is a message wrapper that adds aCommitBarrier
for explicitly coordinating transactions across actors or threads.Creating a
Coordinated
will create a commit barrier with initially one member. For each member in the coordination set a transaction is expected to be created using the coordinated atomic method, or the coordination cancelled using the cancel method.The number of included members must match the number of transactions, otherwise a successful transaction cannot be coordinated.
To start a new coordinated transaction set that you will also participate in just create a
Coordinated
object:val coordinated = Coordinated()
To start a coordinated transaction that you won't participate in yourself you can create a
Coordinated
object with a message and send it directly to an actor. The recipient of the message will be the first member of the coordination set:To receive a coordinated message in an actor simply match it in a case statement:
To include another actor in the same coordinated transaction set that you've created or received, use the apply method on that object. This will increment the number of parties involved by one and create a new
Coordinated
object to be sent.To enter the coordinated transaction use the atomic method of the coordinated object:
The coordinated transaction will wait for the other transactions before committing. If any of the coordinated transactions fail then they all fail.
(Since version 2.3) akka.transactor will be removed
akka.transactor.Transactor for an actor that implements coordinated transactions