I am currently in the process of writing my own plugin for the Akka
SyncWriteJournal
API to implement the connection with HSQLDB
.
The problem is that I do no understand the requirements for the method doAsyncReplayMessages
. It states that it needs to return a future and that all the messages should be called by replayCallback
.
Let's say that I have a query which returns a list of messages: List<Message> messages
. Can anyone provide a minimal example (with explanation) of how to use replayCallback
, and Future
to implement the method correctly by using that list? How would replayCallback
and Future
work together and what should be returned by the method doAsyncReplayMessages
?
Thanks!
-Edit-
With the help of some comments I've whipped up an implementation which is not complete but incorporates the idea proposed:
public Future<Void> doAsyncReplayMessages(final String persistenceId, long fromSequenceNr, long toSequenceNr, long max,
final Procedure<PersistentRepr> replayCallback) {
final ExecutionContext ec = context().system().dispatcher();
final Future<Void> future = Futures.future(new Callable<Void>() {
@Override
public Void call() throws Exception {
final List<Message> messages = getMessages();
for (int i = 0; i < feedbackList.size(); i++) {
replayCallback.apply(
new PersistentImpl(messages.get(i), i, persistenceId, false, null, null));
}
return null;
}
}, ec);
return future;
}
As you might see it missed a few key concepts I'm still missing. The PersistentImpl needs one argument Seq<String> confirm
which is null
still. And perhaps more importantly I'm return null
since the future expects Void
as return type and I'm not sure how implement that. It currently throws a NPE:
[ERROR] [08/28/2014 12:31:19.582] [akkaSystem-akka.actor.default-dispatcher-7] [akka://akkaSystem/system/journal] null
java.lang.NullPointerException
at akka.persistence.journal.japi.AsyncRecovery.asyncReadHighestSequenceNr(AsyncRecovery.scala:26)
at akka.persistence.journal.SyncWriteJournal$$anonfun$receive$1.applyOrElse(SyncWriteJournal.scala:53)
at akka.actor.Actor$class.aroundReceive(Actor.scala:465)
at akka.persistence.journal.japi.SyncWriteJournal.aroundReceive(SyncWriteJournal.scala:16)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:516)
at akka.actor.ActorCell.invoke(ActorCell.scala:487)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:238)
at akka.dispatch.Mailbox.run(Mailbox.scala:220)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)