From 971db49d904a419b253e32fdc273c33b1613e743 Mon Sep 17 00:00:00 2001 From: Christos KK Loverdos Date: Wed, 26 Sep 2012 13:31:49 +0300 Subject: [PATCH] Cache resource mapping --- src/main/scala/gr/grnet/aquarium/Aquarium.scala | 19 ++++++++++++++++++- .../aquarium/actor/service/user/UserActor.scala | 1 - .../grnet/aquarium/charging/ChargingService.scala | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/scala/gr/grnet/aquarium/Aquarium.scala b/src/main/scala/gr/grnet/aquarium/Aquarium.scala index 7c404d4..19c1c71 100644 --- a/src/main/scala/gr/grnet/aquarium/Aquarium.scala +++ b/src/main/scala/gr/grnet/aquarium/Aquarium.scala @@ -57,6 +57,7 @@ import org.slf4j.{LoggerFactory, Logger} import gr.grnet.aquarium.event.CreditsModel import gr.grnet.aquarium.charging.state.UserStateBootstrap import java.util.{Map ⇒ JMap} +import java.util.{HashMap ⇒ JHashMap} /** * @@ -69,6 +70,9 @@ final class Aquarium(env: Env) extends Lifecycle with Loggable { @volatile private[this] var _chargingBehaviorMap = Map[String, ChargingBehavior]() + // Caching value for the latest resource mapping + @volatile private[this] var _resourceMapping = apply(EnvKeys.defaultPolicyMsg).getResourceMapping + private[this] lazy val cachingPolicyStore = new CachingPolicyStore( apply(EnvKeys.defaultPolicyMsg), apply(EnvKeys.storeProvider).policyStore @@ -233,6 +237,9 @@ final class Aquarium(env: Env) extends Lifecycle with Loggable { } + /** + * @deprecated Use `currentResourceMapping` instead + */ def resourceMappingAtMillis(millis: Long): JMap[String, ResourceTypeMsg] = { val policyMspOpt = policyStore.loadPolicyAt(millis) if(policyMspOpt.isEmpty) { @@ -246,7 +253,17 @@ final class Aquarium(env: Env) extends Lifecycle with Loggable { policyMsg.getResourceMapping } -// def resourceTypesMapAtMillis(millis: Long): Map[String, ResourceType] = { + /** + * Provides the current resource mapping. This value is cached. + * + * NOTE: The assumption is that the resource mapping is always updated with new keys, + * that is we allow only the addition of new resource types. + */ + def currentResourceMapping = { + this._resourceMapping synchronized this._resourceMapping + } + + // def resourceTypesMapAtMillis(millis: Long): Map[String, ResourceType] = { // val policyMspOpt = policyStore.loadPolicyAt(millis) // if(policyMspOpt.isEmpty) { // throw new AquariumInternalError( diff --git a/src/main/scala/gr/grnet/aquarium/actor/service/user/UserActor.scala b/src/main/scala/gr/grnet/aquarium/actor/service/user/UserActor.scala index f1feaeb..b19a4da 100644 --- a/src/main/scala/gr/grnet/aquarium/actor/service/user/UserActor.scala +++ b/src/main/scala/gr/grnet/aquarium/actor/service/user/UserActor.scala @@ -142,7 +142,6 @@ class UserActor extends ReflectiveRoleableActor { val historyMsg = MessageFactory.newUserAgreementHistoryMsg(this._userID) this._userAgreementHistoryModel = ModelFactory.newUserAgreementHistoryModel(historyMsg) - // NOTE: this._userID is already set up our caller var _imcounter = 0 val hadCreateEvent = aquarium.imEventStore.foreachIMEventInOccurrenceOrder(this._userID) { imEvent ⇒ diff --git a/src/main/scala/gr/grnet/aquarium/charging/ChargingService.scala b/src/main/scala/gr/grnet/aquarium/charging/ChargingService.scala index 1fc351c..bbd2579 100644 --- a/src/main/scala/gr/grnet/aquarium/charging/ChargingService.scala +++ b/src/main/scala/gr/grnet/aquarium/charging/ChargingService.scala @@ -210,6 +210,7 @@ final class ChargingService extends AquariumAwareSkeleton with Lifecycle with Lo } /** * Processes one resource event and computes relevant, incremental charges. + * If needed, it may go back in time and recompute stuff. * * @param resourceEvent * @param userStateMsg -- 1.7.10.4