2014-02-15 23:44:00 -05:00
|
|
|
/**
|
2017-01-04 17:37:10 +01:00
|
|
|
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.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;
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
|
|
|
|
import com.typesafe.config.Config;
|
|
|
|
|
import com.typesafe.config.ConfigFactory;
|
|
|
|
|
import java.io.File;
|
2015-06-25 19:58:47 +02:00
|
|
|
import java.util.ArrayList;
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
import java.util.List;
|
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;
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
import org.iq80.leveldb.util.FileUtils;
|
2015-06-17 01:23:18 +02:00
|
|
|
import java.util.Optional;
|
2014-12-08 11:02:14 +01:00
|
|
|
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
import akka.persistence.japi.journal.JavaJournalSpec;
|
|
|
|
|
import akka.persistence.japi.snapshot.JavaSnapshotStoreSpec;
|
|
|
|
|
|
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";
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
ActorSelection selection = getContext().actorSelection(path);
|
2014-02-15 23:44:00 -05:00
|
|
|
selection.tell(new Identify(1), self());
|
|
|
|
|
}
|
|
|
|
|
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
@Override
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
return receiveBuilder()
|
|
|
|
|
.match(ActorIdentity.class, ai -> {
|
2014-03-20 12:05:32 +01:00
|
|
|
if (ai.correlationId().equals(1)) {
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
Optional<ActorRef> store = ai.getActorRef();
|
|
|
|
|
if (store.isPresent()) {
|
|
|
|
|
SharedLeveldbJournal.setStore(store.get(), getContext().system());
|
|
|
|
|
} else {
|
|
|
|
|
throw new RuntimeException("Couldn't identify store");
|
2014-02-15 23:44:00 -05:00
|
|
|
}
|
2014-03-20 12:05:32 +01:00
|
|
|
}
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +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;
|
|
|
|
|
}
|
|
|
|
|
}
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01: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\""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public CapabilityFlag supportsRejectingNonSerializableObjects() {
|
|
|
|
|
return CapabilityFlag.off();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//#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 CapabilityFlag supportsRejectingNonSerializableObjects() {
|
|
|
|
|
return CapabilityFlag.on();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
};
|
|
|
|
|
|
2014-02-15 23:44:00 -05:00
|
|
|
}
|