Merge branch 'snapshots'
[aquarium] / src / main / scala / gr / grnet / aquarium / store / IMEventStore.scala
index 90b9c68..8a36cc9 100644 (file)
 
 package gr.grnet.aquarium.store
 
-import com.ckkloverdos.maybe.Maybe
-import gr.grnet.aquarium.events.IMEvent
+import gr.grnet.aquarium.message.avro.gen.IMEventMsg
 
 /**
  * Store for external user events
  *
+ * @author Christos KK Loverdos <loverdos@gmail.com>
  * @author Georgios Gousios <gousiosg@gmail.com>
  */
 trait IMEventStore {
-  def storeUnparsed(json: String): Maybe[RecordID]
+  def pingIMEventStore(): Unit
 
   /**
-   * Store an event
+   * Insert a new event into the store.
    */
-  def storeIMEvent(event: IMEvent): Maybe[RecordID]
+  def insertIMEvent(event: IMEventMsg): IMEventMsg
 
   /**
-   * Find a user event by event ID
+   * Find an event by its ID
    */
-  def findIMEventById(id: String): Maybe[IMEvent]
+  def findIMEventByID(id: String): Option[IMEventMsg]
 
   /**
-   * Find all user events by user ID
+   * Find the `CREATE` even for the given user. Note that there must be only one such event.
    */
-  def findIMEventsByUserId(userId: String): List[IMEvent]
+  def findCreateIMEventByUserID(userID: String): Option[IMEventMsg]
+
+  /**
+   * Scans events for the given user, sorted by `occurredMillis` in ascending order and runs them through
+   * the given function `f`.
+   *
+   * Any exception is propagated to the caller. The underlying DB resources are properly disposed in any case.
+   */
+  def foreachIMEventInOccurrenceOrder(userID: String)(f: IMEventMsg ⇒ Boolean): Boolean
 }
\ No newline at end of file