2013-10-09 13:11:53 +02:00
|
|
|
/**
|
2014-02-02 19:05:45 -06:00
|
|
|
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
|
2013-10-09 13:11:53 +02:00
|
|
|
*/
|
|
|
|
|
|
2013-10-08 11:46:02 +02:00
|
|
|
package docs.persistence;
|
|
|
|
|
|
|
|
|
|
//#plugin-imports
|
2013-11-25 12:02:29 +01:00
|
|
|
import akka.actor.UntypedActor;
|
2013-10-08 11:46:02 +02:00
|
|
|
import scala.concurrent.Future;
|
|
|
|
|
import akka.japi.Option;
|
|
|
|
|
import akka.japi.Procedure;
|
|
|
|
|
import akka.persistence.*;
|
|
|
|
|
import akka.persistence.journal.japi.*;
|
|
|
|
|
import akka.persistence.snapshot.japi.*;
|
|
|
|
|
//#plugin-imports
|
2013-11-25 12:02:29 +01:00
|
|
|
import akka.actor.*;
|
|
|
|
|
import akka.persistence.journal.leveldb.SharedLeveldbJournal;
|
|
|
|
|
import akka.persistence.journal.leveldb.SharedLeveldbStore;
|
2013-10-08 11:46:02 +02:00
|
|
|
|
|
|
|
|
public class PersistencePluginDocTest {
|
2013-11-25 12:02:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
static Object o1 = new Object() {
|
|
|
|
|
final ActorSystem system = null;
|
|
|
|
|
//#shared-store-creation
|
|
|
|
|
final ActorRef store = system.actorOf(Props.create(SharedLeveldbStore.class), "store");
|
|
|
|
|
//#shared-store-creation
|
|
|
|
|
|
|
|
|
|
//#shared-store-usage
|
|
|
|
|
class SharedStorageUsage extends UntypedActor {
|
|
|
|
|
@Override
|
|
|
|
|
public void preStart() throws Exception {
|
|
|
|
|
String path = "akka.tcp://example@127.0.0.1:2552/user/store";
|
|
|
|
|
ActorSelection selection = getContext().actorSelection(path);
|
|
|
|
|
selection.tell(new Identify(1), getSelf());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onReceive(Object message) throws Exception {
|
|
|
|
|
if (message instanceof ActorIdentity) {
|
|
|
|
|
ActorIdentity identity = (ActorIdentity) message;
|
|
|
|
|
if (identity.correlationId().equals(1)) {
|
|
|
|
|
ActorRef store = identity.getRef();
|
|
|
|
|
if (store != null) {
|
|
|
|
|
SharedLeveldbJournal.setStore(store, getContext().system());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//#shared-store-usage
|
|
|
|
|
};
|
|
|
|
|
|
2013-10-09 13:11:53 +02:00
|
|
|
class MySnapshotStore extends SnapshotStore {
|
|
|
|
|
@Override
|
2014-06-23 14:33:35 +02:00
|
|
|
public Future<Option<SelectedSnapshot>> doLoadAsync(String persistenceId, SnapshotSelectionCriteria criteria) {
|
2013-10-09 13:11:53 +02:00
|
|
|
return null;
|
2013-10-08 11:46:02 +02:00
|
|
|
}
|
|
|
|
|
|
2013-10-09 13:11:53 +02:00
|
|
|
@Override
|
|
|
|
|
public Future<Void> doSaveAsync(SnapshotMetadata metadata, Object snapshot) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2013-10-08 11:46:02 +02:00
|
|
|
|
2013-10-09 13:11:53 +02:00
|
|
|
@Override
|
|
|
|
|
public void onSaved(SnapshotMetadata metadata) throws Exception {
|
|
|
|
|
}
|
2013-10-08 11:46:02 +02:00
|
|
|
|
2013-10-09 13:11:53 +02:00
|
|
|
@Override
|
|
|
|
|
public void doDelete(SnapshotMetadata metadata) throws Exception {
|
2013-10-08 11:46:02 +02:00
|
|
|
}
|
2013-11-12 09:02:02 +01:00
|
|
|
|
|
|
|
|
@Override
|
2014-06-23 14:33:35 +02:00
|
|
|
public void doDelete(String persistenceId, SnapshotSelectionCriteria criteria) throws Exception {
|
2013-11-12 09:02:02 +01:00
|
|
|
}
|
2013-10-09 13:11:53 +02:00
|
|
|
}
|
2013-10-08 11:46:02 +02:00
|
|
|
|
2013-10-09 13:11:53 +02:00
|
|
|
class MyAsyncJournal extends AsyncWriteJournal {
|
|
|
|
|
@Override
|
2014-01-17 06:58:25 +01:00
|
|
|
public Future<Void> doAsyncWriteMessages(Iterable<PersistentRepr> messages) {
|
2013-10-09 13:11:53 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
2013-10-08 11:46:02 +02:00
|
|
|
|
2013-10-09 13:11:53 +02:00
|
|
|
@Override
|
2014-01-17 06:58:25 +01:00
|
|
|
public Future<Void> doAsyncWriteConfirmations(Iterable<PersistentConfirmation> confirmations) {
|
2013-10-27 08:01:14 +01:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-09 13:11:53 +02:00
|
|
|
@Override
|
2014-06-27 11:51:58 +02:00
|
|
|
public Future<Void> doAsyncDeleteMessages(Iterable<PersistentId> messageIds, boolean permanent) {
|
2013-10-09 13:11:53 +02:00
|
|
|
return null;
|
2013-10-08 11:46:02 +02:00
|
|
|
}
|
|
|
|
|
|
2013-10-09 13:11:53 +02:00
|
|
|
@Override
|
2014-06-23 14:33:35 +02:00
|
|
|
public Future<Void> doAsyncDeleteMessagesTo(String persistenceId, long toSequenceNr, boolean permanent) {
|
2014-01-17 06:58:25 +01:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-06-23 14:33:35 +02:00
|
|
|
public Future<Void> doAsyncReplayMessages(String persistenceId, long fromSequenceNr, long toSequenceNr, long max, Procedure<PersistentRepr> replayCallback) {
|
2014-01-17 06:58:25 +01:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-06-23 14:33:35 +02:00
|
|
|
public Future<Long> doAsyncReadHighestSequenceNr(String persistenceId, long fromSequenceNr) {
|
2013-10-09 13:11:53 +02:00
|
|
|
return null;
|
2013-10-08 11:46:02 +02:00
|
|
|
}
|
2013-10-09 13:11:53 +02:00
|
|
|
}
|
2013-10-08 11:46:02 +02:00
|
|
|
}
|