2013-10-09 13:11:53 +02:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
|
|
|
|
|
2013-10-08 11:46:02 +02:00
|
|
|
package docs.persistence
|
|
|
|
|
|
|
|
|
|
//#plugin-imports
|
|
|
|
|
import scala.concurrent.Future
|
2013-10-27 08:01:14 +01:00
|
|
|
import scala.collection.immutable.Seq
|
2013-10-08 11:46:02 +02:00
|
|
|
//#plugin-imports
|
|
|
|
|
|
|
|
|
|
import com.typesafe.config._
|
|
|
|
|
|
|
|
|
|
import org.scalatest.WordSpec
|
|
|
|
|
|
|
|
|
|
import akka.actor.ActorSystem
|
|
|
|
|
//#plugin-imports
|
|
|
|
|
import akka.persistence._
|
|
|
|
|
import akka.persistence.journal._
|
|
|
|
|
import akka.persistence.snapshot._
|
|
|
|
|
//#plugin-imports
|
|
|
|
|
|
|
|
|
|
object PersistencePluginDocSpec {
|
|
|
|
|
val config =
|
|
|
|
|
"""
|
2014-01-17 06:58:25 +01:00
|
|
|
//#max-message-batch-size
|
|
|
|
|
akka.persistence.journal.max-message-batch-size = 200
|
|
|
|
|
//#max-message-batch-size
|
2013-10-08 11:46:02 +02:00
|
|
|
//#journal-config
|
|
|
|
|
akka.persistence.journal.leveldb.dir = "target/journal"
|
|
|
|
|
//#journal-config
|
|
|
|
|
//#snapshot-config
|
|
|
|
|
akka.persistence.snapshot-store.local.dir = "target/snapshots"
|
|
|
|
|
//#snapshot-config
|
2013-12-06 12:48:44 +01:00
|
|
|
//#native-config
|
|
|
|
|
akka.persistence.journal.leveldb.native = off
|
|
|
|
|
//#native-config
|
2013-10-08 11:46:02 +02:00
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PersistencePluginDocSpec extends WordSpec {
|
|
|
|
|
new AnyRef {
|
|
|
|
|
val providerConfig =
|
|
|
|
|
"""
|
|
|
|
|
//#journal-plugin-config
|
|
|
|
|
# Path to the journal plugin to be used
|
|
|
|
|
akka.persistence.journal.plugin = "my-journal"
|
|
|
|
|
|
|
|
|
|
# My custom journal plugin
|
|
|
|
|
my-journal {
|
|
|
|
|
# Class name of the plugin.
|
|
|
|
|
class = "docs.persistence.MyJournal"
|
|
|
|
|
# Dispatcher for the plugin actor.
|
|
|
|
|
plugin-dispatcher = "akka.actor.default-dispatcher"
|
|
|
|
|
}
|
|
|
|
|
//#journal-plugin-config
|
|
|
|
|
|
|
|
|
|
//#snapshot-store-plugin-config
|
|
|
|
|
# Path to the snapshot store plugin to be used
|
|
|
|
|
akka.persistence.snapshot-store.plugin = "my-snapshot-store"
|
|
|
|
|
|
|
|
|
|
# My custom snapshot store plugin
|
|
|
|
|
my-snapshot-store {
|
|
|
|
|
# Class name of the plugin.
|
|
|
|
|
class = "docs.persistence.MySnapshotStore"
|
|
|
|
|
# Dispatcher for the plugin actor.
|
|
|
|
|
plugin-dispatcher = "akka.persistence.dispatchers.default-plugin-dispatcher"
|
|
|
|
|
}
|
|
|
|
|
//#snapshot-store-plugin-config
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
val system = ActorSystem("doc", ConfigFactory.parseString(providerConfig).withFallback(ConfigFactory.parseString(PersistencePluginDocSpec.config)))
|
|
|
|
|
val extension = Persistence(system)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-25 12:02:29 +01:00
|
|
|
object SharedLeveldbPluginDocSpec {
|
|
|
|
|
import akka.actor._
|
|
|
|
|
import akka.persistence.journal.leveldb.SharedLeveldbJournal
|
|
|
|
|
|
|
|
|
|
val config =
|
|
|
|
|
"""
|
|
|
|
|
//#shared-journal-config
|
|
|
|
|
akka.persistence.journal.plugin = "akka.persistence.journal.leveldb-shared"
|
|
|
|
|
//#shared-journal-config
|
2013-12-06 12:48:44 +01:00
|
|
|
//#shared-store-native-config
|
|
|
|
|
akka.persistence.journal.leveldb-shared.store.native = off
|
|
|
|
|
//#shared-store-native-config
|
2013-11-25 12:02:29 +01:00
|
|
|
//#shared-store-config
|
|
|
|
|
akka.persistence.journal.leveldb-shared.store.dir = "target/shared"
|
|
|
|
|
//#shared-store-config
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
//#shared-store-usage
|
|
|
|
|
trait SharedStoreUsage extends Actor {
|
|
|
|
|
override def preStart(): Unit = {
|
|
|
|
|
context.actorSelection("akka.tcp://example@127.0.0.1:2552/user/store") ! Identify(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def receive = {
|
2013-12-03 16:34:26 +01:00
|
|
|
case ActorIdentity(1, Some(store)) =>
|
2013-11-25 12:02:29 +01:00
|
|
|
SharedLeveldbJournal.setStore(store, context.system)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//#shared-store-usage
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trait SharedLeveldbPluginDocSpec {
|
|
|
|
|
val system: ActorSystem
|
|
|
|
|
|
|
|
|
|
new AnyRef {
|
|
|
|
|
import akka.actor._
|
|
|
|
|
//#shared-store-creation
|
|
|
|
|
import akka.persistence.journal.leveldb.SharedLeveldbStore
|
|
|
|
|
|
|
|
|
|
val store = system.actorOf(Props[SharedLeveldbStore], "store")
|
|
|
|
|
//#shared-store-creation
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-08 11:46:02 +02:00
|
|
|
class MyJournal extends AsyncWriteJournal {
|
2014-01-17 06:58:25 +01:00
|
|
|
def asyncWriteMessages(messages: Seq[PersistentRepr]): Future[Unit] = ???
|
|
|
|
|
def asyncWriteConfirmations(confirmations: Seq[PersistentConfirmation]): Future[Unit] = ???
|
|
|
|
|
def asyncDeleteMessages(messageIds: Seq[PersistentId], permanent: Boolean): Future[Unit] = ???
|
|
|
|
|
def asyncDeleteMessagesTo(processorId: String, toSequenceNr: Long, permanent: Boolean): Future[Unit] = ???
|
|
|
|
|
def asyncReplayMessages(processorId: String, fromSequenceNr: Long, toSequenceNr: Long, max: Long)(replayCallback: (PersistentRepr) => Unit): Future[Unit] = ???
|
|
|
|
|
def asyncReadHighestSequenceNr(processorId: String, fromSequenceNr: Long): Future[Long] = ???
|
2013-10-08 11:46:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MySnapshotStore extends SnapshotStore {
|
|
|
|
|
def loadAsync(processorId: String, criteria: SnapshotSelectionCriteria): Future[Option[SelectedSnapshot]] = ???
|
|
|
|
|
def saveAsync(metadata: SnapshotMetadata, snapshot: Any): Future[Unit] = ???
|
2013-11-12 09:02:02 +01:00
|
|
|
def saved(metadata: SnapshotMetadata): Unit = ???
|
|
|
|
|
def delete(metadata: SnapshotMetadata): Unit = ???
|
|
|
|
|
def delete(processorId: String, criteria: SnapshotSelectionCriteria): Unit = ???
|
2013-10-08 11:46:02 +02:00
|
|
|
}
|