Add ping functionality to two of the stores
authorChristos KK Loverdos <loverdos@gmail.com>
Thu, 17 May 2012 13:18:54 +0000 (16:18 +0300)
committerChristos KK Loverdos <loverdos@gmail.com>
Thu, 17 May 2012 13:18:54 +0000 (16:18 +0300)
src/main/scala/gr/grnet/aquarium/store/IMEventStore.scala
src/main/scala/gr/grnet/aquarium/store/ResourceEventStore.scala
src/main/scala/gr/grnet/aquarium/store/memory/MemStore.scala
src/main/scala/gr/grnet/aquarium/store/mongodb/MongoDBStore.scala

index 811e34b..9999848 100644 (file)
@@ -57,6 +57,8 @@ trait IMEventStore {
 
   def createIMEventFromOther(event: IMEventModel): IMEvent
 
+  def pingIMEventStore(): Unit
+
   /**
    * Insert a new event into the store.
    */
index cbc9380..787a657 100644 (file)
@@ -53,6 +53,8 @@ trait ResourceEventStore {
     throw new AquariumException("Unsupported operation")
   }
 
+  def pingResourceEventStore(): Unit
+
   def insertResourceEvent(event: ResourceEventModel): ResourceEvent
 
   def findResourceEventById(id: String): Option[ResourceEvent]
index 0f1ae6b..341121c 100644 (file)
@@ -228,6 +228,10 @@ class MemStore extends UserStateStore
     _resourceEvents = Nil
   }
 
+  def pingResourceEventStore(): Unit = {
+    // We are always live and kicking...
+  }
+
   def insertResourceEvent(event: ResourceEventModel) = {
     val localEvent = createResourceEventFromOther(event)
     _resourceEvents ::= localEvent
@@ -308,6 +312,10 @@ class MemStore extends UserStateStore
     StdIMEvent.fromOther(event)
   }
 
+  def pingIMEventStore(): Unit = {
+  }
+
+
   def insertIMEvent(event: IMEventModel) = {
     val localEvent = createIMEventFromOther(event)
     imEventById += (event.id -> localEvent)
index dd4e359..1171045 100644 (file)
@@ -104,6 +104,10 @@ class MongoDBStore(
     MongoDBResourceEvent.fromOther(event, null)
   }
 
+  def pingResourceEventStore(): Unit = {
+    MongoDBStore.ping(mongo)
+  }
+
   def insertResourceEvent(event: ResourceEventModel) = {
     val localEvent = MongoDBResourceEvent.fromOther(event, new ObjectId().toStringMongod)
     MongoDBStore.insertObject(localEvent, resourceEvents, MongoDBStore.jsonSupportToDBObject)
@@ -330,6 +334,10 @@ class MongoDBStore(
     MongoDBStore.createIMEventFromOther(event)
   }
 
+  def pingIMEventStore(): Unit = {
+    MongoDBStore.ping(mongo)
+  }
+
   def insertIMEvent(event: IMEventModel): IMEvent = {
     val localEvent = MongoDBIMEvent.fromOther(event, new ObjectId().toStringMongod)
     MongoDBStore.insertObject(localEvent, imEvents, MongoDBStore.jsonSupportToDBObject)
@@ -429,6 +437,11 @@ object MongoDBStore {
     PolicyEntry.fromJson(JSON.serialize(dbObj))
   }
 
+  def ping(mongo: Mongo): Unit = {
+    // This requires a network roundtrip
+    mongo.isLocked
+  }
+
   def findBy[A >: Null <: AnyRef](name: String,
                                   value: String,
                                   collection: DBCollection,