From d2ed29ef379ccf8a5bf13928ab11344273f6d96f Mon Sep 17 00:00:00 2001 From: ticktock Date: Fri, 19 Nov 2010 09:29:36 -0500 Subject: [PATCH] check reference equality when registering a persistent datastructure, and fail if one is already there with a different reference --- akka-stm/src/main/scala/stm/Transaction.scala | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/akka-stm/src/main/scala/stm/Transaction.scala b/akka-stm/src/main/scala/stm/Transaction.scala index a51bb3d511..6877398ec9 100644 --- a/akka-stm/src/main/scala/stm/Transaction.scala +++ b/akka-stm/src/main/scala/stm/Transaction.scala @@ -112,7 +112,10 @@ object Transaction { def commit = synchronized { log.trace("Committing transaction " + toString) - retry(STATE_RETRIES){persistentStateMap.valuesIterator.foreach(_.commit)} + retry(STATE_RETRIES){ + persistentStateMap.valuesIterator.foreach(_.commit) + persistentStateMap.clear + } status = TransactionStatus.Completed jta.foreach(_.commit) } @@ -160,7 +163,13 @@ object Transaction { private[akka] def isTopLevel = depth.get == 0 //when calling this method, make sure to prefix the uuid with the type so you //have no possibility of kicking a diffferent type with the same uuid out of a transction - private[akka] def register(uuid: String, storage: Committable with Abortable) = persistentStateMap.put(uuid, storage) + private[akka] def register(uuid: String, storage: Committable with Abortable) = { + if(persistentStateMap.getOrElseUpdate(uuid, {storage}) ne storage){ + log.error("existing:"+System.identityHashCode(persistentStateMap.get(uuid).get)) + log.error("new:"+System.identityHashCode(storage)) + throw new IllegalStateException("attempted to register an instance of persistent data structure for id [%s] when there is already a different instance registered".format(uuid)) + } + } private def ensureIsActive = if (status != TransactionStatus.Active) throw new StmConfigurationException(