A few more renames due to the UserEvent -> IMEvent change
[aquarium] / src / main / scala / gr / grnet / aquarium / store / mongodb / MongoDBStoreProvider.scala
index c1cf0fe..68a9227 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011 GRNET S.A. All rights reserved.
+ * Copyright 2011-2012 GRNET S.A. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or
  * without modification, are permitted provided that the following
 package gr.grnet.aquarium.store.mongodb
 
 import com.ckkloverdos.props.Props
-import gr.grnet.aquarium.{MasterConf, Configurable}
-import gr.grnet.aquarium.MasterConf.Keys
+import gr.grnet.aquarium.Configurator.Keys
 import com.mongodb.{MongoException, Mongo, MongoOptions, ServerAddress}
 import gr.grnet.aquarium.store._
+import gr.grnet.aquarium.{AquariumException, Configurable}
 
 /**
  * 
@@ -52,35 +52,30 @@ class MongoDBStoreProvider extends StoreProvider with Configurable {
   private[this] var _username: String = _
   private[this] var _password: String = _
 
-  private[this] var _eventStore: ResourceEventStore = _
-  private[this] var _userStore: UserStore = _
-  private[this] var _walletStore: WalletStore = _
-
   def configure(props: Props) = {
     this._database = props.getEx(Keys.persistence_db)
     this._username = props.getEx(Keys.persistence_username)
     this._password = props.getEx(Keys.persistence_password)
     val host = props.getEx(Keys.persistence_host)
-    val port = props.get(Keys.persistence_port)
-    val foo = port.getOr(throw new Exception("Not a valid port number for MongoDB connection")).toInt
+    val port = props.getEx(Keys.persistence_port).toInt
 
     try {
-      val addr = new ServerAddress(host, foo)
+      val addr = new ServerAddress(host, port)
+
       val opt = new MongoOptions()
+      opt.connectionsPerHost = props.getEx(Keys.mongo_connection_pool_size).toInt
+      opt.threadsAllowedToBlockForConnectionMultiplier = 8
+
       this._mongo = new Mongo(addr, opt)
-      val mongoStore = new MongoDBStore(this._mongo, this._database, this._username, this._password)
-      this._eventStore = mongoStore
-      this._userStore  = mongoStore
-      this._walletStore  = mongoStore
     } catch {
       case e: MongoException =>
-        throw new Exception("Cannot connect to mongo at %s:%s".format(host, port), e)
+        throw new AquariumException("Cannot connect to mongo at %s:%s".format(host, port), e)
     }
   }
 
-  def userStore = _userStore
-
-  def eventStore = _eventStore
-
-  def walletStore = _walletStore
+  def userStateStore = new MongoDBStore(this._mongo, this._database, this._username, this._password)
+  def resourceEventStore = new MongoDBStore(this._mongo, this._database, this._username, this._password)
+  def walletEntryStore = new MongoDBStore(this._mongo, this._database, this._username, this._password)
+  def imEventStore = new MongoDBStore(this._mongo, this._database, this._username, this._password)
+  def policyStore = new MongoDBStore(this._mongo, this._database, this._username, this._password)
 }
\ No newline at end of file