+per #3641 Storage plugin API
- Journal plugin API for storage backends with asynchronous client API (default impl: in-memory journal) - Journal plugin API for storage backends with synchronous client API (default impl: LevelDB journal) - Snapshot store plugin API (default impl: local filesystem snapshot store)
This commit is contained in:
parent
1bda2a43d5
commit
da7490bbc9
33 changed files with 1454 additions and 474 deletions
|
|
@ -0,0 +1,88 @@
|
|||
/**
|
||||
* Copyright (C) 2012-2013 Eligotech BV.
|
||||
*/
|
||||
|
||||
package akka.persistence.snapshot
|
||||
|
||||
import scala.concurrent.Future
|
||||
import scala.util._
|
||||
|
||||
import akka.actor._
|
||||
import akka.pattern.pipe
|
||||
import akka.persistence._
|
||||
|
||||
/**
|
||||
* Abstract snapshot store.
|
||||
*/
|
||||
trait SnapshotStore extends Actor {
|
||||
import SnapshotProtocol._
|
||||
import context.dispatcher
|
||||
|
||||
final def receive = {
|
||||
case LoadSnapshot(processorId, criteria, toSequenceNr) ⇒ {
|
||||
val p = sender
|
||||
loadAsync(processorId, criteria.limit(toSequenceNr)) map {
|
||||
sso ⇒ LoadSnapshotResult(sso, toSequenceNr)
|
||||
} recover {
|
||||
case e ⇒ LoadSnapshotResult(None, toSequenceNr)
|
||||
} pipeTo (p)
|
||||
}
|
||||
case SaveSnapshot(metadata, snapshot) ⇒ {
|
||||
val p = sender
|
||||
val md = metadata.copy(timestamp = System.currentTimeMillis)
|
||||
saveAsync(md, snapshot) map {
|
||||
_ ⇒ SaveSnapshotSuccess(md)
|
||||
} recover {
|
||||
case e ⇒ SaveSnapshotFailure(metadata, e)
|
||||
} to (self, p)
|
||||
}
|
||||
case evt @ SaveSnapshotSuccess(metadata) ⇒ {
|
||||
saved(metadata)
|
||||
sender ! evt // sender is processor
|
||||
}
|
||||
case evt @ SaveSnapshotFailure(metadata, _) ⇒ {
|
||||
delete(metadata)
|
||||
sender ! evt // sender is processor
|
||||
}
|
||||
}
|
||||
|
||||
//#snapshot-store-plugin-api
|
||||
/**
|
||||
* Plugin API.
|
||||
*
|
||||
* Asynchronously loads a snapshot.
|
||||
*
|
||||
* @param processorId processor id.
|
||||
* @param criteria selection criteria for loading.
|
||||
*/
|
||||
def loadAsync(processorId: String, criteria: SnapshotSelectionCriteria): Future[Option[SelectedSnapshot]]
|
||||
|
||||
/**
|
||||
* Plugin API.
|
||||
*
|
||||
* Asynchronously saves a snapshot.
|
||||
*
|
||||
* @param metadata snapshot metadata.
|
||||
* @param snapshot snapshot.
|
||||
*/
|
||||
def saveAsync(metadata: SnapshotMetadata, snapshot: Any): Future[Unit]
|
||||
|
||||
/**
|
||||
* Plugin API.
|
||||
*
|
||||
* Called after successful saving of a snapshot.
|
||||
*
|
||||
* @param metadata snapshot metadata.
|
||||
*/
|
||||
def saved(metadata: SnapshotMetadata)
|
||||
|
||||
/**
|
||||
* Plugin API.
|
||||
*
|
||||
* Deletes the snapshot identified by `metadata`.
|
||||
*
|
||||
* @param metadata snapshot metadata.
|
||||
*/
|
||||
def delete(metadata: SnapshotMetadata)
|
||||
//#snapshot-store-plugin-api
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue