2013-10-09 13:11:53 +02:00
|
|
|
/**
|
2015-03-07 22:58:48 -08:00
|
|
|
* Copyright (C) 2009-2015 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;
|
|
|
|
|
|
2014-12-08 11:02:14 +01:00
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
2014-07-08 18:30:15 +02:00
|
|
|
import akka.actor.*;
|
2015-06-03 15:56:00 +02:00
|
|
|
import akka.dispatch.Futures;
|
2014-12-08 11:02:14 +01:00
|
|
|
import com.typesafe.config.Config;
|
|
|
|
|
import com.typesafe.config.ConfigFactory;
|
|
|
|
|
import org.iq80.leveldb.util.FileUtils;
|
2014-07-08 18:30:15 +02:00
|
|
|
import akka.persistence.japi.journal.JavaJournalSpec;
|
|
|
|
|
import akka.persistence.japi.snapshot.JavaSnapshotStoreSpec;
|
2013-11-25 12:02:29 +01:00
|
|
|
import akka.persistence.journal.leveldb.SharedLeveldbJournal;
|
|
|
|
|
import akka.persistence.journal.leveldb.SharedLeveldbStore;
|
2014-07-08 18:30:15 +02:00
|
|
|
import scala.concurrent.Future;
|
2014-12-08 11:02:14 +01:00
|
|
|
import akka.japi.Option;
|
|
|
|
|
import akka.japi.Procedure;
|
2014-07-08 18:30:15 +02:00
|
|
|
|
2014-12-08 11:02:14 +01:00
|
|
|
//#plugin-imports
|
|
|
|
|
import akka.persistence.*;
|
|
|
|
|
import akka.persistence.journal.japi.AsyncWriteJournal;
|
|
|
|
|
import akka.persistence.snapshot.japi.SnapshotStore;
|
2014-07-08 18:30:15 +02:00
|
|
|
|
|
|
|
|
//#plugin-imports
|
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
|
2015-06-03 15:56:00 +02:00
|
|
|
public Future<Void> doDelete(SnapshotMetadata metadata) throws Exception {
|
|
|
|
|
return Futures.successful(null);
|
2013-10-08 11:46:02 +02:00
|
|
|
}
|
2013-11-12 09:02:02 +01:00
|
|
|
|
|
|
|
|
@Override
|
2015-06-03 15:56:00 +02:00
|
|
|
public Future<Void> doDelete(String persistenceId, SnapshotSelectionCriteria criteria) throws Exception {
|
|
|
|
|
return Futures.successful(null);
|
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-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-12-08 11:02:14 +01: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
|
|
|
}
|
2014-07-08 18:30:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
static Object o2 = new Object() {
|
|
|
|
|
//#journal-tck-java
|
|
|
|
|
class MyJournalSpecTest extends JavaJournalSpec {
|
|
|
|
|
|
|
|
|
|
public MyJournalSpecTest() {
|
|
|
|
|
super(ConfigFactory.parseString(
|
|
|
|
|
"persistence.journal.plugin = " +
|
|
|
|
|
"\"akka.persistence.journal.leveldb-shared\""));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//#journal-tck-java
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static Object o3 = new Object() {
|
|
|
|
|
//#snapshot-store-tck-java
|
|
|
|
|
class MySnapshotStoreTest extends JavaSnapshotStoreSpec {
|
|
|
|
|
|
|
|
|
|
public MySnapshotStoreTest() {
|
|
|
|
|
super(ConfigFactory.parseString(
|
|
|
|
|
"akka.persistence.snapshot-store.plugin = " +
|
|
|
|
|
"\"akka.persistence.snapshot-store.local\""));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//#snapshot-store-tck-java
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static Object o4 = new Object() {
|
|
|
|
|
//#journal-tck-before-after-java
|
|
|
|
|
class MyJournalSpecTest extends JavaJournalSpec {
|
|
|
|
|
|
|
|
|
|
List<File> storageLocations = new ArrayList<File>();
|
|
|
|
|
|
|
|
|
|
public MyJournalSpecTest() {
|
|
|
|
|
super(ConfigFactory.parseString(
|
|
|
|
|
"persistence.journal.plugin = " +
|
|
|
|
|
"\"akka.persistence.journal.leveldb-shared\""));
|
|
|
|
|
|
|
|
|
|
Config config = system().settings().config();
|
|
|
|
|
storageLocations.add(new File(
|
|
|
|
|
config.getString("akka.persistence.journal.leveldb.dir")));
|
|
|
|
|
storageLocations.add(new File(
|
|
|
|
|
config.getString("akka.persistence.snapshot-store.local.dir")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void beforeAll() {
|
|
|
|
|
for (File storageLocation : storageLocations) {
|
|
|
|
|
FileUtils.deleteRecursively(storageLocation);
|
|
|
|
|
}
|
|
|
|
|
super.beforeAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void afterAll() {
|
|
|
|
|
super.afterAll();
|
|
|
|
|
for (File storageLocation : storageLocations) {
|
|
|
|
|
FileUtils.deleteRecursively(storageLocation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//#journal-tck-before-after-java
|
|
|
|
|
};
|
2013-10-08 11:46:02 +02:00
|
|
|
}
|