This sounds interesting. The best way to get it into the product is to
create an issue and assembla:
https://www.assembla.com/spaces/akka/tickets/new
Then I will make sure that it gets prioritized and scheduled for a release.
I also need to read up on 'retry' and how it can be used. It's still
not clear to me.
I would love to get the blocking stuff in Akka. It looks very useful.
This ticket is scheduled for 0.10.
https://www.assembla.com/spaces/akka/tickets/232-blocking-transactions-
I hope to get it in.
Perhaps Peter Vlugter his planning on doing it as part of the STM refactoring.
> And when are you expecting to release the next Akka version? It would be
> nice if we can integratie Multiverse 0.6:
>
> - better scalable clock
This is the highest priority in my opinion.
One minute.
> 2) make sure that the transactionfactory for non actor transactions is
> configured with setExplicitRetryAllowed(true).
Ok. Also simple.
> 3) expose the OrElseTemplate. One of my committers currently is working on
That is done already:
atomically {
..
} orElse {
..
I've already got retry and configurable transaction factory on a private branch. I'm still to test it properly with the ants demo and other things but simple tests all work fine as expected.
I've moved the atomically-orElse to sit with retry under Transaction.Util and I've also renamed it to either-orElse to line up with Multiverse and so that it's usage is not confused with a compensating task.
And I have deferred and compensating methods in there as well (just mapping to the Multiverse StmUtils as well).
The main thing I was going to work on before pushing this branch up was trying to remove the Akka specific transaction class altogether. And there are some other smaller changes too, like trying out package objects. I'm also still to look at exposing the Multiverse transactional objects and refs and looking at extending BasicRef.
Anyway, here's how using retry (and configuring) works at the moment (I just run this in sbt console):
import se.scalablesolutions.akka.stm._
import se.scalablesolutions.akka.stm.Transaction.Local._
import se.scalablesolutions.akka.stm.Transaction.Util._
import se.scalablesolutions.akka.actor.Actor
import se.scalablesolutions.akka.actor.Actor._
import se.scalablesolutions.akka.util.Logging
type Account = Ref[Double]
val account1 = Ref(100.0)
val account2 = Ref(100.0)
case class Transfer(from: Account, to: Account, amount: Double)
class Transferer extends Actor with Logging {
implicit val txFactory = TransactionFactory(trackReads = true, explicitRetries = true)
def receive = {
case Transfer(from, to, amount) =>
atomic {
if (from.getOrElse(0) < amount) {
log.info("not enough money - retrying")
retry
}
log.info("transferring")
from alter (_ - amount)
to alter (_ + amount)
}
}
}
val transferer = actorOf(new Transferer).start
transferer ! Transfer(account1, account2, 500.0)
// INF [20100611-09:06:11.478] Transferer: not enough money - retrying
atomic { account1 alter (_ + 2000) }
// INF [20100611-09:06:35.346] Transferer: transferring
atomic { account1.get }
// Option[Double] = Some(1600.0)
atomic { account2.get }
// Option[Double] = Some(600.0)
transferer.stop
> What is the meaning of 'getOrElse'?
It means get the value or otherwise give me a default value. At the moment ref.get returns an option type. So it would return None or Some(100) depending on whether a value is defined. Like the Maybe type in Haskell. It's possible to use ref.get.get to access the value but if the value was undefined then it would throw an exception (just like the underlying ref.get).
Looking good. This is cool stuff. :-)
--
Jonas Bonér
http://jayway.com
http://akkasource.com
twitter: jboner
> For the retry to work, r...
--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To...
Looking good. This is cool stuff. :-)
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.