diff --git a/akka-core/src/main/scala/stm/Transaction.scala b/akka-core/src/main/scala/stm/Transaction.scala index 7c1e9010a8..6f992d0aee 100644 --- a/akka-core/src/main/scala/stm/Transaction.scala +++ b/akka-core/src/main/scala/stm/Transaction.scala @@ -22,6 +22,7 @@ import org.multiverse.api.ThreadLocalTransaction._ import org.multiverse.templates.{TransactionTemplate, OrElseTemplate} import org.multiverse.api.backoff.ExponentialBackoffPolicy import org.multiverse.stms.alpha.AlphaStm +import org.multiverse.api.StmUtils class NoTransactionInScopeException extends RuntimeException class TransactionRetryException(message: String) extends RuntimeException(message) @@ -45,18 +46,6 @@ object Transaction { * } * * - * Example of atomically-orElse transaction management. - * Which is a good way to reduce contention and transaction collisions. - *
- * import se.scalablesolutions.akka.stm.Transaction.Local._
- *
- * atomically {
- * .. // try to do something
- * } orElse {
- * .. // if transaction clashes try do do something else to minimize contention
- * }
- *
- *
* @author Jonas Bonér
*/
object Local extends TransactionManagement with Logging {
@@ -72,22 +61,6 @@ object Transaction {
}
}.execute()
}
-
- /**
- * See ScalaDoc on Transaction.Local class.
- */
- def atomically[A](firstBody: => A) = elseBody(firstBody)
-
- /**
- * Should only be used together with atomically to form atomically-orElse constructs.
- * See ScalaDoc on class.
- */
- def elseBody[A](firstBody: => A) = new {
- def orElse(secondBody: => A) = new OrElseTemplate[A] {
- def either(t: MultiverseTransaction) = firstBody
- def orelse(t: MultiverseTransaction) = secondBody
- }.execute()
- }
}
/**
@@ -130,6 +103,25 @@ object Transaction {
}
}
+ /**
+ * TODO: document
+ */
+ object Util {
+
+ def deferred[T](body: => T): Unit = StmUtils.scheduleDeferredTask(new Runnable { def run = body })
+
+ def compensating[T](body: => T): Unit = StmUtils.scheduleCompensatingTask(new Runnable { def run = body })
+
+ def retry = StmUtils.retry
+
+ def either[A](firstBody: => A) = new {
+ def orElse(secondBody: => A) = new OrElseTemplate[A] {
+ def either(t: MultiverseTransaction) = firstBody
+ def orelse(t: MultiverseTransaction) = secondBody
+ }.execute()
+ }
+ }
+
/**
* Attach an Akka-specific Transaction to the current Multiverse transaction.
* Must be called within a Multiverse transaction.