Add one more timestamp to resource event that denotes the reception time.
authorChristos KK Loverdos <loverdos@gmail.com>
Thu, 29 Dec 2011 14:22:11 +0000 (16:22 +0200)
committerChristos KK Loverdos <loverdos@gmail.com>
Thu, 29 Dec 2011 14:22:11 +0000 (16:22 +0200)
src/main/scala/gr/grnet/aquarium/logic/events/AquariumEvent.scala
src/main/scala/gr/grnet/aquarium/logic/events/ResourceEvent.scala
src/main/scala/gr/grnet/aquarium/logic/events/UserEvent.scala
src/main/scala/gr/grnet/aquarium/logic/events/WalletEntry.scala
src/main/scala/gr/grnet/aquarium/util/RandomEventGenerator.scala

index 6e50e78..76f7e10 100644 (file)
@@ -48,8 +48,13 @@ import util.{Loggable, shortClassNameOf}
  * @author Christos KK Loverdos <loverdos@gmail.com>
  */
 
-abstract class AquariumEvent(val id: String, val occurredMillis: Long)
-  extends JsonSupport with XmlSupport with Loggable {
+abstract class AquariumEvent(
+    val id: String,           // The id at the client side (the sender) TODO: Rename to remoteId or something...
+    val occurredMillis: Long, // When it occurred at client side (the sender)
+    val receivedMillis: Long) // When it was received by Aquarium
+  extends JsonSupport
+  with    XmlSupport
+  with    Loggable {
 
   def validate: Boolean
 
index 2d56ef6..d478709 100644 (file)
@@ -46,16 +46,17 @@ import gr.grnet.aquarium.util.json.JsonHelpers
  * @author Georgios Gousios <gousiosg@gmail.com>.
  */
 case class ResourceEvent(
-  override val id: String,
-  userId: String,
-  clientId: String,
-  resource: String,
-  override val occurredMillis: Long,
-  eventVersion: String,
-  value: Float,
-  var aqTimestamp: Long = 0,
-  details: Map[String, String]
-) extends AquariumEvent(id, occurredMillis) {
+    override val id: String,
+    userId: String,
+    clientId: String,
+    resource: String,
+    override val occurredMillis: Long,
+    override val receivedMillis: Long,
+    eventVersion: String,
+    value: Float,
+    var aqTimestamp: Long = 0,
+    details: Map[String, String])
+  extends AquariumEvent(id, occurredMillis, receivedMillis) {
 
   def validate() : Boolean = {
 
index 3e74b38..a543ec9 100644 (file)
@@ -11,17 +11,18 @@ import com.ckkloverdos.maybe.{Failed, NoVal, Just}
  * @author Georgios Gousios <gousiosg@gmail.com>
  */
 case class UserEvent(
-  override val id: String,
-  override val occurredMillis: Long,
-  var aqTimestamp: Long = 0,
-  userId: String,
-  eventVersion: Short,
-  eventType: Short, //1: create, 2: modify
-  state: String,    //ACTIVE, SUSPENDED
-  idp: String,
-  tenant: String,
-  roles: Array[String]
-  ) extends AquariumEvent(id, occurredMillis) {
+    override val id: String,           // The id at the client side (the sender) TODO: Rename to remoteId or something...
+    override val occurredMillis: Long, // When it occurred at client side (the sender)
+    override val receivedMillis: Long, // When it was received by Aquarium
+    var aqTimestamp: Long = 0,
+    userId: String,
+    eventVersion: Short,
+    eventType: Short, //1: create, 2: modify
+    state: String,    //ACTIVE, SUSPENDED
+    idp: String,
+    tenant: String,
+    roles: Array[String])
+  extends AquariumEvent(id, occurredMillis, receivedMillis) {
 
   assert(eventType == 1 || eventType == 2)
   assert(state.equalsIgnoreCase("ACTIVE") ||
index 63ec852..ebd2a74 100644 (file)
@@ -10,14 +10,15 @@ import gr.grnet.aquarium.util.json.JsonHelpers
  * @author Christos KK Loverdos <loverdos@gmail.com>
  */
 case class WalletEntry(
-    override val id: String,
-    override val occurredMillis: Long,
-    sourceEventIDs: List[String], // The events that triggered this WalletEntry
+    override val id: String,           // The id at the client side (the sender) TODO: Rename to remoteId or something...
+    override val occurredMillis: Long, // When it occurred at client side (the sender)
+    override val receivedMillis: Long, // When it was received by Aquarium
+    sourceEventIDs: List[String],      // The events that triggered this WalletEntry
     value: Float,
     reason: String,
     userId: String,
     finalized: Boolean)
-  extends AquariumEvent(id, occurredMillis) {
+  extends AquariumEvent(id, occurredMillis, receivedMillis) {
 
   assert(occurredMillis > 0)
   assert(value > 0F)
@@ -31,5 +32,5 @@ object WalletEntry {
     JsonHelpers.jsonToObject[WalletEntry](json)
   }
 
-  def zero = WalletEntry("", 1L, Nil,1,"","foo", false)
+  def zero = WalletEntry("", 1L, 1L, Nil,1,"","foo", false)
 }
\ No newline at end of file
index 5d1c5e2..c19ff76 100644 (file)
@@ -74,7 +74,7 @@ trait RandomEventGenerator extends AkkaAMQP {
     val tenant = Array("TENTANT1", "TENANT2").apply(rnd.nextInt(2))
     val role = Array("ADMIN", "NORMAL").apply(rnd.nextInt(2))
 
-    UserEvent(sha1, ts.toLong, 0, id.toString, 1, 2, event, idp, tenant, Array(role))
+    UserEvent(sha1, ts.toLong, ts.toLong, 0, id.toString, 1, 2, event, idp, tenant, Array(role))
   }
 
   /**
@@ -100,7 +100,7 @@ trait RandomEventGenerator extends AkkaAMQP {
       i =>
         val sha1 = CryptoUtils.sha1(genRndAsciiString(35))
         val ts = tsFrom + (scala.math.random * ((tsTo - tsFrom) + 1)).asInstanceOf[Long]
-        val user = UserEvent(sha1, ts, 0, i.toString, 1, 1, "ACTIVE", "LOCAL", "TENTANT1", Array("NORMAL"))
+        val user = UserEvent(sha1, ts, ts, 0, i.toString, 1, 1, "ACTIVE", "LOCAL", "TENTANT1", Array("NORMAL"))
         publisher ! Message(user.toBytes, "%s.%s".format(MessagingNames.IM_EVENT_KEY,"CREATED"))
     }
   }
@@ -128,7 +128,7 @@ trait RandomEventGenerator extends AkkaAMQP {
       CryptoUtils.sha1(str),
       rnd.nextInt(userIds.max).toString,
       rnd.nextInt(clientIds.max).toString,
-      res,ts, 1.toString, value, 0, extra)
+      res,ts, ts, 1.toString, value, 0, extra)
   }
 
   def genRndAsciiString(size: Int): String = {