2014-02-15 23:44:00 -05:00
|
|
|
/**
|
2015-03-07 22:58:48 -08:00
|
|
|
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
2014-02-15 23:44:00 -05:00
|
|
|
*/
|
|
|
|
|
|
2015-06-24 19:58:43 +02:00
|
|
|
package docs.persistence;
|
2014-02-15 23:44:00 -05:00
|
|
|
|
|
|
|
|
//#plugin-imports
|
2015-06-03 15:56:00 +02:00
|
|
|
import akka.dispatch.Futures;
|
2014-02-15 23:44:00 -05:00
|
|
|
import akka.persistence.*;
|
|
|
|
|
import akka.persistence.journal.japi.*;
|
|
|
|
|
import akka.persistence.snapshot.japi.*;
|
|
|
|
|
//#plugin-imports
|
2014-12-08 11:02:14 +01:00
|
|
|
|
2014-02-15 23:44:00 -05:00
|
|
|
import akka.actor.*;
|
|
|
|
|
import akka.persistence.journal.leveldb.SharedLeveldbJournal;
|
|
|
|
|
import akka.persistence.journal.leveldb.SharedLeveldbStore;
|
2014-12-08 11:02:14 +01:00
|
|
|
import akka.japi.pf.ReceiveBuilder;
|
2015-06-25 19:58:47 +02:00
|
|
|
import java.util.ArrayList;
|
2014-12-08 11:02:14 +01:00
|
|
|
import scala.concurrent.Future;
|
2015-06-23 21:01:36 +02:00
|
|
|
import java.util.function.Consumer;
|
2015-06-17 01:23:18 +02:00
|
|
|
import java.util.Optional;
|
2014-12-08 11:02:14 +01:00
|
|
|
|
2014-02-15 23:44:00 -05:00
|
|
|
|
|
|
|
|
public class LambdaPersistencePluginDocTest {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 AbstractActor {
|
|
|
|
|
@Override
|
|
|
|
|
public void preStart() throws Exception {
|
|
|
|
|
String path = "akka.tcp://example@127.0.0.1:2552/user/store";
|
|
|
|
|
ActorSelection selection = context().actorSelection(path);
|
|
|
|
|
selection.tell(new Identify(1), self());
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-20 12:05:32 +01:00
|
|
|
public SharedStorageUsage() {
|
|
|
|
|
receive(ReceiveBuilder.
|
|
|
|
|
match(ActorIdentity.class, ai -> {
|
|
|
|
|
if (ai.correlationId().equals(1)) {
|
|
|
|
|
ActorRef store = ai.getRef();
|
|
|
|
|
if (store != null) {
|
|
|
|
|
SharedLeveldbJournal.setStore(store, context().system());
|
2014-02-15 23:44:00 -05:00
|
|
|
}
|
2014-03-20 12:05:32 +01:00
|
|
|
}
|
|
|
|
|
}).build()
|
|
|
|
|
);
|
2014-02-15 23:44:00 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//#shared-store-usage
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MySnapshotStore extends SnapshotStore {
|
|
|
|
|
@Override
|
2015-06-17 01:23:18 +02:00
|
|
|
public Future<Optional<SelectedSnapshot>> doLoadAsync(String persistenceId, SnapshotSelectionCriteria criteria) {
|
2014-02-15 23:44:00 -05:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Future<Void> doSaveAsync(SnapshotMetadata metadata, Object snapshot) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-06-17 01:23:18 +02:00
|
|
|
public Future<Void> doDeleteAsync(SnapshotMetadata metadata) {
|
2015-06-03 15:56:00 +02:00
|
|
|
return Futures.successful(null);
|
2014-02-15 23:44:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-06-17 01:23:18 +02:00
|
|
|
public Future<Void> doDeleteAsync(String persistenceId, SnapshotSelectionCriteria criteria) {
|
2015-06-03 15:56:00 +02:00
|
|
|
return Futures.successful(null);
|
2014-02-15 23:44:00 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MyAsyncJournal extends AsyncWriteJournal {
|
2015-06-25 19:58:47 +02:00
|
|
|
//#sync-journal-plugin-api
|
2014-02-15 23:44:00 -05:00
|
|
|
@Override
|
2015-06-25 19:58:47 +02:00
|
|
|
public Future<Iterable<Optional<Exception>>> doAsyncWriteMessages(
|
|
|
|
|
Iterable<AtomicWrite> messages) {
|
|
|
|
|
try {
|
|
|
|
|
Iterable<Optional<Exception>> result = new ArrayList<Optional<Exception>>();
|
|
|
|
|
// blocking call here...
|
|
|
|
|
// result.add(..)
|
|
|
|
|
return Futures.successful(result);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return Futures.failed(e);
|
|
|
|
|
}
|
2014-02-15 23:44:00 -05:00
|
|
|
}
|
2015-06-25 19:58:47 +02:00
|
|
|
//#sync-journal-plugin-api
|
2014-02-15 23:44:00 -05:00
|
|
|
|
|
|
|
|
@Override
|
2015-06-25 07:44:52 +02:00
|
|
|
public Future<Void> doAsyncDeleteMessagesTo(String persistenceId, long toSequenceNr) {
|
2014-02-15 23:44:00 -05:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-06-23 14:33:35 +02:00
|
|
|
public Future<Void> doAsyncReplayMessages(String persistenceId, long fromSequenceNr,
|
2014-02-15 23:44:00 -05:00
|
|
|
long toSequenceNr,
|
|
|
|
|
long max,
|
2015-06-23 21:01:36 +02:00
|
|
|
Consumer<PersistentRepr> replayCallback) {
|
2014-02-15 23:44:00 -05:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-06-23 14:33:35 +02:00
|
|
|
public Future<Long> doAsyncReadHighestSequenceNr(String persistenceId, long fromSequenceNr) {
|
2014-02-15 23:44:00 -05:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|