package gr.grnet.aquarium.store
-import com.ckkloverdos.maybe.Maybe
-import gr.grnet.aquarium.events.im.IMEventModel
-import gr.grnet.aquarium.util.makeString
+import gr.grnet.aquarium.message.avro.gen.IMEventMsg
/**
* Store for external user events
* @author Georgios Gousios <gousiosg@gmail.com>
*/
trait IMEventStore {
- type IMEvent <: IMEventModel
+ def pingIMEventStore(): Unit
- def isLocalIMEvent(event: IMEventModel): Boolean
-
- def createIMEventFromJson(json: String): IMEvent
-
- def createIMEventFromJsonBytes(jsonBytes: Array[Byte]) = {
- createIMEventFromJson(makeString(jsonBytes))
- }
-
- def createIMEventFromOther(event: IMEventModel): IMEvent
-
- def storeUnparsed(json: String): Maybe[RecordID]
+ /**
+ * Insert a new event into the store.
+ */
+ def insertIMEvent(event: IMEventMsg): IMEventMsg
/**
- * Store an event
+ * Find an event by its ID
*/
- def storeIMEvent(event: IMEventModel): RecordID
+ def findIMEventByID(id: String): Option[IMEventMsg]
/**
- * Find a user event by event ID
+ * Find the `CREATE` even for the given user. Note that there must be only one such event.
*/
- def findIMEventById(id: String): Maybe[IMEvent]
+ def findCreateIMEventByUserID(userID: String): Option[IMEventMsg]
/**
- * Find all user events by user ID
+ * 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 findIMEventsByUserId(userId: String): List[IMEvent]
+ def foreachIMEventInOccurrenceOrder(userID: String)(f: IMEventMsg ⇒ Boolean): Boolean
}
\ No newline at end of file