2009-03-23 19:17:10 +01:00
|
|
|
/**
|
2009-12-27 16:01:53 +01:00
|
|
|
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
|
2009-03-23 19:17:10 +01:00
|
|
|
*/
|
|
|
|
|
|
2009-09-02 09:10:21 +02:00
|
|
|
package se.scalablesolutions.akka.stm
|
2009-03-23 19:17:10 +01:00
|
|
|
|
2009-10-06 00:07:27 +02:00
|
|
|
import java.util.concurrent.atomic.AtomicLong
|
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger
|
2010-03-10 22:38:52 +01:00
|
|
|
import java.util.concurrent.TimeUnit
|
2009-10-06 00:07:27 +02:00
|
|
|
|
2010-04-17 19:28:14 +02:00
|
|
|
import javax.transaction.{TransactionManager, UserTransaction, Status}
|
|
|
|
|
|
2010-02-23 19:49:01 +01:00
|
|
|
import scala.collection.mutable.HashMap
|
|
|
|
|
|
2009-10-17 00:37:56 +02:00
|
|
|
import se.scalablesolutions.akka.util.Logging
|
2010-04-17 19:28:14 +02:00
|
|
|
import se.scalablesolutions.akka.config.Config._
|
2009-08-04 16:46:51 +02:00
|
|
|
|
2010-04-05 11:53:43 +02:00
|
|
|
import org.multiverse.api.{Transaction => MultiverseTransaction, TransactionLifecycleListener, TransactionLifecycleEvent}
|
2009-10-24 21:21:43 +02:00
|
|
|
import org.multiverse.api.GlobalStmInstance.getGlobalStmInstance
|
2009-11-25 20:37:00 +01:00
|
|
|
import org.multiverse.api.ThreadLocalTransaction._
|
2010-02-22 13:22:10 +01:00
|
|
|
import org.multiverse.templates.{TransactionTemplate, OrElseTemplate}
|
2010-02-23 19:49:01 +01:00
|
|
|
import org.multiverse.utils.backoff.ExponentialBackoffPolicy
|
|
|
|
|
import org.multiverse.stms.alpha.AlphaStm
|
2009-10-06 00:07:27 +02:00
|
|
|
|
2009-10-17 00:37:56 +02:00
|
|
|
class NoTransactionInScopeException extends RuntimeException
|
2009-10-06 00:07:27 +02:00
|
|
|
class TransactionRetryException(message: String) extends RuntimeException(message)
|
2009-08-04 16:46:51 +02:00
|
|
|
|
2010-04-14 20:47:19 +02:00
|
|
|
/**
|
|
|
|
|
* FIXDOC: document AtomicTemplate
|
|
|
|
|
* AtomicTemplate can be used to create atomic blocks from Java code.
|
|
|
|
|
* <pre>
|
|
|
|
|
* User newUser = new AtomicTemplate[User]() {
|
|
|
|
|
* User atomic() {
|
|
|
|
|
* ... // create user atomically
|
|
|
|
|
* return user;
|
|
|
|
|
* }
|
|
|
|
|
* }.execute();
|
|
|
|
|
* </pre>
|
|
|
|
|
*/
|
|
|
|
|
trait AtomicTemplate[T] {
|
|
|
|
|
def atomic: T
|
|
|
|
|
def execute: T = Transaction.Local.atomic {
|
|
|
|
|
atomic
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-05 11:53:43 +02:00
|
|
|
object Transaction {
|
2009-09-17 09:47:22 +02:00
|
|
|
val idFactory = new AtomicLong(-1L)
|
2010-03-20 09:49:59 +01:00
|
|
|
|
2010-04-05 11:53:43 +02:00
|
|
|
/**
|
|
|
|
|
* Creates a STM atomic transaction and by-passes all transactions hooks
|
|
|
|
|
* such as persistence etc.
|
2010-04-05 13:04:18 +02:00
|
|
|
*
|
2010-04-05 11:53:43 +02:00
|
|
|
* Only for internal usage.
|
|
|
|
|
*/
|
|
|
|
|
private[akka] def atomic0[T](body: => T): T = new TransactionTemplate[T]() {
|
|
|
|
|
def execute(mtx: MultiverseTransaction): T = body
|
|
|
|
|
}.execute()
|
|
|
|
|
|
2010-04-05 12:32:15 +02:00
|
|
|
/**
|
|
|
|
|
* Module for "local" transaction management, local in the context of threads.
|
2010-04-05 13:04:18 +02:00
|
|
|
* You should only use these if you do <b>not</b> need to have one transaction span
|
2010-04-05 12:32:15 +02:00
|
|
|
* multiple threads (or Actors).
|
|
|
|
|
* <p/>
|
|
|
|
|
* Example of atomic transaction management using the atomic block.
|
|
|
|
|
* <p/>
|
|
|
|
|
* <pre>
|
|
|
|
|
* import se.scalablesolutions.akka.stm.Transaction.Local._
|
|
|
|
|
*
|
|
|
|
|
* atomic {
|
|
|
|
|
* .. // do something within a transaction
|
|
|
|
|
* }
|
|
|
|
|
* </pre>
|
|
|
|
|
*
|
2010-04-05 13:04:18 +02:00
|
|
|
* Example of atomically-orElse transaction management.
|
2010-04-05 12:32:15 +02:00
|
|
|
* Which is a good way to reduce contention and transaction collisions.
|
|
|
|
|
* <pre>
|
|
|
|
|
* import se.scalablesolutions.akka.stm.Transaction.Local._
|
|
|
|
|
*
|
|
|
|
|
* atomically {
|
|
|
|
|
* .. // try to do something
|
|
|
|
|
* } orElse {
|
|
|
|
|
* .. // if transaction clashes try do do something else to minimize contention
|
|
|
|
|
* }
|
|
|
|
|
* </pre>
|
|
|
|
|
*
|
|
|
|
|
* Example of atomic transaction management using for comprehensions (monadic):
|
|
|
|
|
*
|
|
|
|
|
* <pre>
|
|
|
|
|
* import se.scalablesolutions.akka.stm.Transaction.Local._
|
2010-04-05 13:04:18 +02:00
|
|
|
* for (tx <- Transaction.Local) {
|
2010-04-05 12:32:15 +02:00
|
|
|
* ... // do transactional stuff
|
|
|
|
|
* }
|
|
|
|
|
*
|
2010-04-05 13:04:18 +02:00
|
|
|
* val result = for (tx <- Transaction.Local) yield {
|
2010-04-05 12:32:15 +02:00
|
|
|
* ... // do transactional stuff yielding a result
|
|
|
|
|
* }
|
|
|
|
|
* </pre>
|
|
|
|
|
*
|
|
|
|
|
* Example of using Transaction and TransactionalRef in for comprehensions (monadic):
|
|
|
|
|
*
|
|
|
|
|
* <pre>
|
|
|
|
|
* // For example, if you have a List with TransactionalRef
|
|
|
|
|
* val refs: List[TransactionalRef] = ...
|
|
|
|
|
*
|
|
|
|
|
* // You can use them together with Transaction in a for comprehension since
|
|
|
|
|
* // TransactionalRef is also monadic
|
|
|
|
|
* for {
|
2010-04-05 13:04:18 +02:00
|
|
|
* tx <- Transaction.Local
|
2010-04-05 12:32:15 +02:00
|
|
|
* ref <- refs
|
|
|
|
|
* } {
|
|
|
|
|
* ... // use the ref inside a transaction
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* val result = for {
|
2010-04-05 13:04:18 +02:00
|
|
|
* tx <- Transaction.Local
|
2010-04-05 12:32:15 +02:00
|
|
|
* ref <- refs
|
|
|
|
|
* } yield {
|
|
|
|
|
* ... // use the ref inside a transaction, yield a result
|
|
|
|
|
* }
|
|
|
|
|
* </pre>
|
|
|
|
|
*
|
|
|
|
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
|
|
|
|
*/
|
2010-04-05 11:53:43 +02:00
|
|
|
object Local extends TransactionManagement with Logging {
|
|
|
|
|
|
2010-04-05 13:04:18 +02:00
|
|
|
/**
|
|
|
|
|
* See ScalaDoc on Transaction.Local class.
|
|
|
|
|
*/
|
|
|
|
|
def map[T](f: => T): T = atomic {f}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* See ScalaDoc on Transaction.Local class.
|
|
|
|
|
*/
|
|
|
|
|
def flatMap[T](f: => T): T = atomic {f}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* See ScalaDoc on Transaction.Local class.
|
|
|
|
|
*/
|
|
|
|
|
def foreach(f: => Unit): Unit = atomic {f}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* See ScalaDoc on Transaction.Local class.
|
|
|
|
|
*/
|
|
|
|
|
def atomic[T](body: => T): T = {
|
|
|
|
|
new TransactionTemplate[T]() {
|
|
|
|
|
def execute(mtx: MultiverseTransaction): T = body
|
|
|
|
|
|
|
|
|
|
override def onStart(mtx: MultiverseTransaction) = {
|
|
|
|
|
val tx = new Transaction
|
|
|
|
|
tx.transaction = Some(mtx)
|
|
|
|
|
setTransaction(Some(tx))
|
|
|
|
|
mtx.registerLifecycleListener(new TransactionLifecycleListener() {
|
|
|
|
|
def notify(tx: MultiverseTransaction, event: TransactionLifecycleEvent) = event.name match {
|
|
|
|
|
case "postCommit" => tx.commit
|
|
|
|
|
case "postAbort" => tx.abort
|
|
|
|
|
case _ => {}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}.execute()
|
|
|
|
|
}
|
2009-11-26 20:37:49 +01:00
|
|
|
|
2010-04-05 13:04:18 +02:00
|
|
|
/**
|
|
|
|
|
* See ScalaDoc on Transaction.Local class.
|
|
|
|
|
*/
|
|
|
|
|
def atomically[A](firstBody: => A) = elseBody(firstBody)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Should only be used together with <code>atomically</code> to form atomically-orElse constructs.
|
|
|
|
|
* See ScalaDoc on class.
|
|
|
|
|
*/
|
|
|
|
|
def elseBody[A](firstBody: => A) = new {
|
|
|
|
|
def orElse(secondBody: => A) = new OrElseTemplate[A] {
|
|
|
|
|
def run(t: MultiverseTransaction) = firstBody
|
|
|
|
|
def orelserun(t: MultiverseTransaction) = secondBody
|
|
|
|
|
}.execute()
|
|
|
|
|
}
|
2010-04-05 11:53:43 +02:00
|
|
|
}
|
2010-03-20 09:49:59 +01:00
|
|
|
|
2010-04-05 12:32:15 +02:00
|
|
|
/**
|
|
|
|
|
* Module for "global" transaction management, global in the context of multiple threads.
|
|
|
|
|
* You have to use these if you do need to have one transaction span multiple threads (or Actors).
|
|
|
|
|
* <p/>
|
|
|
|
|
* Example of atomic transaction management using the atomic block.
|
|
|
|
|
* <p/>
|
2010-04-05 13:04:18 +02:00
|
|
|
* Here are some examples (assuming implicit transaction family name in scope):
|
2010-04-05 12:32:15 +02:00
|
|
|
* <pre>
|
|
|
|
|
* import se.scalablesolutions.akka.stm.Transaction.Global._
|
|
|
|
|
*
|
|
|
|
|
* atomic {
|
|
|
|
|
* .. // do something within a transaction
|
|
|
|
|
* }
|
|
|
|
|
* </pre>
|
|
|
|
|
*
|
|
|
|
|
* Example of atomic transaction management using for comprehensions (monadic):
|
|
|
|
|
*
|
|
|
|
|
* <pre>
|
2010-04-05 13:04:18 +02:00
|
|
|
* import se.scalablesolutions.akka.stm.Transaction
|
|
|
|
|
* for (tx <- Transaction.Global) {
|
2010-04-05 12:32:15 +02:00
|
|
|
* ... // do transactional stuff
|
|
|
|
|
* }
|
|
|
|
|
*
|
2010-04-05 13:04:18 +02:00
|
|
|
* val result = for (tx <- Transaction.Global) yield {
|
2010-04-05 12:32:15 +02:00
|
|
|
* ... // do transactional stuff yielding a result
|
|
|
|
|
* }
|
|
|
|
|
* </pre>
|
|
|
|
|
*
|
|
|
|
|
* Example of using Transaction and TransactionalRef in for comprehensions (monadic):
|
|
|
|
|
*
|
|
|
|
|
* <pre>
|
|
|
|
|
* // For example, if you have a List with TransactionalRef
|
|
|
|
|
* val refs: List[TransactionalRef] = ...
|
|
|
|
|
*
|
|
|
|
|
* // You can use them together with Transaction in a for comprehension since
|
|
|
|
|
* // TransactionalRef is also monadic
|
|
|
|
|
* for {
|
2010-04-05 13:04:18 +02:00
|
|
|
* tx <- Transaction.Global
|
2010-04-05 12:32:15 +02:00
|
|
|
* ref <- refs
|
|
|
|
|
* } {
|
|
|
|
|
* ... // use the ref inside a transaction
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* val result = for {
|
2010-04-05 13:04:18 +02:00
|
|
|
* tx <- Transaction.Global
|
2010-04-05 12:32:15 +02:00
|
|
|
* ref <- refs
|
|
|
|
|
* } yield {
|
|
|
|
|
* ... // use the ref inside a transaction, yield a result
|
|
|
|
|
* }
|
|
|
|
|
* </pre>
|
|
|
|
|
*
|
|
|
|
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
|
|
|
|
*/
|
2010-04-05 11:53:43 +02:00
|
|
|
object Global extends TransactionManagement with Logging {
|
|
|
|
|
|
2010-04-05 13:04:18 +02:00
|
|
|
/**
|
|
|
|
|
* See ScalaDoc on Transaction.Global class.
|
|
|
|
|
*/
|
|
|
|
|
def map[T](f: => T): T = atomic {f}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* See ScalaDoc on Transaction.Global class.
|
|
|
|
|
*/
|
|
|
|
|
def flatMap[T](f: => T): T = atomic {f}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* See ScalaDoc on Transaction.Global class.
|
|
|
|
|
*/
|
|
|
|
|
def foreach(f: => Unit): Unit = atomic {f}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* See ScalaDoc on Transaction.Global class.
|
|
|
|
|
*/
|
|
|
|
|
def atomic[T](body: => T): T = {
|
|
|
|
|
var isTopLevelTransaction = false
|
|
|
|
|
new TransactionTemplate[T]() {
|
|
|
|
|
def execute(mtx: MultiverseTransaction): T = {
|
|
|
|
|
val result = body
|
|
|
|
|
|
|
|
|
|
val txSet = getTransactionSetInScope
|
|
|
|
|
log.trace("Committing transaction [%s]\n\tby joining transaction set [%s]", mtx, txSet)
|
|
|
|
|
txSet.joinCommit(mtx)
|
|
|
|
|
|
|
|
|
|
// FIXME tryJoinCommit(mtx, TransactionManagement.TRANSACTION_TIMEOUT, TimeUnit.MILLISECONDS)
|
|
|
|
|
//getTransactionSetInScope.tryJoinCommit(mtx, TransactionManagement.TRANSACTION_TIMEOUT, TimeUnit.MILLISECONDS)
|
|
|
|
|
|
|
|
|
|
clearTransaction
|
|
|
|
|
result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override def onStart(mtx: MultiverseTransaction) = {
|
|
|
|
|
val txSet =
|
|
|
|
|
if (!isTransactionSetInScope) {
|
|
|
|
|
isTopLevelTransaction = true
|
|
|
|
|
createNewTransactionSet
|
|
|
|
|
} else getTransactionSetInScope
|
|
|
|
|
val tx = new Transaction
|
2010-04-17 19:28:14 +02:00
|
|
|
tx.begin
|
2010-04-05 13:04:18 +02:00
|
|
|
tx.transaction = Some(mtx)
|
|
|
|
|
setTransaction(Some(tx))
|
|
|
|
|
txSet.registerOnCommitTask(new Runnable() {
|
|
|
|
|
def run = tx.commit
|
|
|
|
|
})
|
|
|
|
|
txSet.registerOnAbortTask(new Runnable() {
|
|
|
|
|
def run = tx.abort
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}.execute()
|
|
|
|
|
}
|
2010-04-05 11:53:43 +02:00
|
|
|
}
|
2009-10-08 21:35:08 +02:00
|
|
|
}
|
2009-10-08 19:01:04 +02:00
|
|
|
|
2009-08-04 16:46:51 +02:00
|
|
|
/**
|
2010-04-17 19:28:14 +02:00
|
|
|
* The Akka specific Transaction class, keeping track of persistent data structures (as in on-disc)
|
|
|
|
|
* and JTA support.
|
2010-04-05 13:04:18 +02:00
|
|
|
*
|
2009-08-04 16:46:51 +02:00
|
|
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
|
|
|
|
*/
|
|
|
|
|
@serializable class Transaction extends Logging {
|
2010-04-17 19:28:14 +02:00
|
|
|
val JTA_AWARE = config.getBool("akka.stm.jta-aware", false)
|
|
|
|
|
val jta: Either[Option[UserTransaction], Option[TransactionManager]] = if (JTA_AWARE) {
|
|
|
|
|
JtaTransactionManagerDetector.findUserTransaction match {
|
|
|
|
|
case None => Right(JtaTransactionManagerDetector.findTransactionManager)
|
|
|
|
|
case tm => Left(tm)
|
|
|
|
|
}
|
|
|
|
|
} else Left(None)
|
|
|
|
|
|
2009-09-13 12:20:44 +02:00
|
|
|
val id = Transaction.idFactory.incrementAndGet
|
2009-08-04 16:46:51 +02:00
|
|
|
@volatile private[this] var status: TransactionStatus = TransactionStatus.New
|
2009-10-17 00:37:56 +02:00
|
|
|
private[akka] var transaction: Option[MultiverseTransaction] = None
|
2009-10-06 00:07:27 +02:00
|
|
|
private[this] val persistentStateMap = new HashMap[String, Committable]
|
|
|
|
|
private[akka] val depth = new AtomicInteger(0)
|
2010-02-22 13:22:10 +01:00
|
|
|
|
2010-03-20 09:49:59 +01:00
|
|
|
log.trace("Creating %s", toString)
|
|
|
|
|
|
2009-11-02 22:14:24 +01:00
|
|
|
// --- public methods ---------
|
2009-08-04 16:46:51 +02:00
|
|
|
|
2010-04-17 19:28:14 +02:00
|
|
|
def begin = synchronized {
|
|
|
|
|
jta match {
|
|
|
|
|
case Left(Some(userTx)) => if (!isJtaTxActive(userTx.getStatus)) userTx.begin
|
|
|
|
|
case Right(Some(txMan)) => if (!isJtaTxActive(txMan.getStatus)) txMan.begin
|
|
|
|
|
case _ => {} // do nothing
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-17 00:37:56 +02:00
|
|
|
def commit = synchronized {
|
2010-04-05 13:04:18 +02:00
|
|
|
log.trace("Committing transaction %s", toString)
|
2010-04-05 11:53:43 +02:00
|
|
|
Transaction.atomic0 {
|
2010-03-29 09:33:32 +02:00
|
|
|
persistentStateMap.valuesIterator.foreach(_.commit)
|
2009-08-04 16:46:51 +02:00
|
|
|
}
|
2009-10-17 00:37:56 +02:00
|
|
|
status = TransactionStatus.Completed
|
2010-04-17 19:28:14 +02:00
|
|
|
jta match {
|
|
|
|
|
case Left(Some(userTx)) => if (isJtaTxActive(userTx.getStatus)) userTx.commit
|
|
|
|
|
case Right(Some(txMan)) => if (isJtaTxActive(txMan.getStatus)) txMan.commit
|
|
|
|
|
case _ => {} // do nothing
|
|
|
|
|
}
|
2009-10-06 00:07:27 +02:00
|
|
|
}
|
|
|
|
|
|
2010-02-23 19:49:01 +01:00
|
|
|
def abort = synchronized {
|
2010-04-05 13:04:18 +02:00
|
|
|
log.trace("Aborting transaction %s", toString)
|
2010-04-17 19:28:14 +02:00
|
|
|
jta match {
|
|
|
|
|
case Left(Some(userTx)) => if (isJtaTxActive(userTx.getStatus)) userTx.rollback
|
|
|
|
|
case Right(Some(txMan)) => if (isJtaTxActive(txMan.getStatus)) txMan.rollback
|
|
|
|
|
case _ => {} // do nothing
|
|
|
|
|
}
|
2010-02-23 19:49:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def isNew = synchronized { status == TransactionStatus.New }
|
2009-11-02 22:14:24 +01:00
|
|
|
|
2010-02-23 19:49:01 +01:00
|
|
|
def isActive = synchronized { status == TransactionStatus.Active }
|
2009-11-02 22:14:24 +01:00
|
|
|
|
2010-02-23 19:49:01 +01:00
|
|
|
def isCompleted = synchronized { status == TransactionStatus.Completed }
|
2009-11-02 22:14:24 +01:00
|
|
|
|
2010-02-23 19:49:01 +01:00
|
|
|
def isAborted = synchronized { status == TransactionStatus.Aborted }
|
2009-08-04 16:46:51 +02:00
|
|
|
|
2009-11-02 22:14:24 +01:00
|
|
|
// --- internal methods ---------
|
|
|
|
|
|
2010-04-17 19:28:14 +02:00
|
|
|
private def isJtaTxActive(status: Int) = status == Status.STATUS_ACTIVE
|
|
|
|
|
|
2009-11-02 22:14:24 +01:00
|
|
|
private[akka] def status_? = status
|
|
|
|
|
|
|
|
|
|
private[akka] def increment = depth.incrementAndGet
|
|
|
|
|
|
|
|
|
|
private[akka] def decrement = depth.decrementAndGet
|
|
|
|
|
|
|
|
|
|
private[akka] def isTopLevel = depth.get == 0
|
|
|
|
|
|
|
|
|
|
private[akka] def register(uuid: String, storage: Committable) = persistentStateMap.put(uuid, storage)
|
|
|
|
|
|
2009-08-04 16:46:51 +02:00
|
|
|
private def ensureIsActive = if (status != TransactionStatus.Active)
|
2009-11-30 10:11:52 +01:00
|
|
|
throw new IllegalStateException(
|
|
|
|
|
"Expected ACTIVE transaction - current status [" + status + "]: " + toString)
|
|
|
|
|
|
|
|
|
|
private def ensureIsActiveOrAborted =
|
|
|
|
|
if (!(status == TransactionStatus.Active || status == TransactionStatus.Aborted))
|
2010-02-22 13:22:10 +01:00
|
|
|
throw new IllegalStateException(
|
|
|
|
|
"Expected ACTIVE or ABORTED transaction - current status [" + status + "]: " + toString)
|
2009-11-30 10:11:52 +01:00
|
|
|
|
|
|
|
|
private def ensureIsActiveOrNew =
|
|
|
|
|
if (!(status == TransactionStatus.Active || status == TransactionStatus.New))
|
2010-02-22 13:22:10 +01:00
|
|
|
throw new IllegalStateException(
|
|
|
|
|
"Expected ACTIVE or NEW transaction - current status [" + status + "]: " + toString)
|
2009-08-04 16:46:51 +02:00
|
|
|
|
2010-04-05 13:04:18 +02:00
|
|
|
// For reinitialize transaction after sending it over the wire
|
2010-03-20 09:49:59 +01:00
|
|
|
/* private[akka] def reinit = synchronized {
|
2009-08-04 16:46:51 +02:00
|
|
|
import net.lag.logging.{Logger, Level}
|
2009-12-27 08:24:11 +01:00
|
|
|
if (log eq null) {
|
2009-08-04 16:46:51 +02:00
|
|
|
log = Logger.get(this.getClass.getName)
|
2009-09-24 10:56:51 +02:00
|
|
|
log.setLevel(Level.ALL) // TODO: preserve logging level
|
2009-08-04 16:46:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-03-20 09:49:59 +01:00
|
|
|
*/
|
2009-08-04 16:46:51 +02:00
|
|
|
override def equals(that: Any): Boolean = synchronized {
|
2010-02-22 13:22:10 +01:00
|
|
|
that != null &&
|
2010-03-20 09:49:59 +01:00
|
|
|
that.isInstanceOf[Transaction] &&
|
|
|
|
|
that.asInstanceOf[Transaction].id == this.id
|
2009-08-04 16:46:51 +02:00
|
|
|
}
|
2010-02-22 13:22:10 +01:00
|
|
|
|
2010-03-20 09:49:59 +01:00
|
|
|
override def hashCode: Int = synchronized { id.toInt }
|
2010-02-22 13:22:10 +01:00
|
|
|
|
2010-02-23 19:49:01 +01:00
|
|
|
override def toString = synchronized { "Transaction[" + id + ", " + status + "]" }
|
2009-08-04 16:46:51 +02:00
|
|
|
}
|
|
|
|
|
|
2009-11-02 22:14:24 +01:00
|
|
|
/**
|
|
|
|
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
|
|
|
|
*/
|
2009-06-21 14:08:43 +02:00
|
|
|
@serializable sealed abstract class TransactionStatus
|
2009-11-02 22:14:24 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author <a href="http://jonasboner.com">Jonas Bonér</a>
|
|
|
|
|
*/
|
2009-03-23 19:17:10 +01:00
|
|
|
object TransactionStatus {
|
|
|
|
|
case object New extends TransactionStatus
|
|
|
|
|
case object Active extends TransactionStatus
|
|
|
|
|
case object Aborted extends TransactionStatus
|
|
|
|
|
case object Completed extends TransactionStatus
|
|
|
|
|
}
|
2009-11-02 22:14:24 +01:00
|
|
|
|