parent
e29e06f850
commit
abaa8f394e
30 changed files with 105 additions and 253 deletions
|
|
@ -8,17 +8,6 @@ package akka.persistence.query
|
|||
* [[akka.persistence.query.scaladsl.EventsByTagQuery]] query, or similar queries.
|
||||
*/
|
||||
final case class EventEnvelope(
|
||||
offset: Long,
|
||||
persistenceId: String,
|
||||
sequenceNr: Long,
|
||||
event: Any)
|
||||
|
||||
/**
|
||||
* Event wrapper adding meta data for the events in the result stream of
|
||||
* [[akka.persistence.query.scaladsl.EventsByTagQuery2]] query, or similar queries.
|
||||
*/
|
||||
// TODO: Rename it to EventEnvelope in Akka 2.5
|
||||
final case class EventEnvelope2(
|
||||
offset: Offset,
|
||||
persistenceId: String,
|
||||
sequenceNr: Long,
|
||||
|
|
|
|||
|
|
@ -17,11 +17,11 @@ object Offset {
|
|||
|
||||
trait Offset
|
||||
|
||||
final case class Sequence(val value: Long) extends Offset with Ordered[Sequence] {
|
||||
final case class Sequence(value: Long) extends Offset with Ordered[Sequence] {
|
||||
override def compare(that: Sequence): Int = value.compare(that.value)
|
||||
}
|
||||
|
||||
final case class TimeBasedUUID(val value: UUID) extends Offset with Ordered[TimeBasedUUID] {
|
||||
final case class TimeBasedUUID(value: UUID) extends Offset with Ordered[TimeBasedUUID] {
|
||||
if (value == null || value.version != 1) {
|
||||
throw new IllegalArgumentException("UUID " + value + " is not a time-based UUID")
|
||||
}
|
||||
|
|
@ -34,4 +34,4 @@ final case object NoOffset extends Offset {
|
|||
* Java API:
|
||||
*/
|
||||
def getInstance: Offset = this
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,13 +4,12 @@
|
|||
package akka.persistence.query.javadsl
|
||||
|
||||
import akka.NotUsed
|
||||
import akka.persistence.query.{ EventEnvelope, Offset }
|
||||
import akka.stream.javadsl.Source
|
||||
import akka.persistence.query.EventEnvelope
|
||||
|
||||
/**
|
||||
* A plugin may optionally support this query by implementing this interface.
|
||||
*/
|
||||
@deprecated("To be replaced by CurrentEventsByTagQuery2 from Akka 2.5", "2.4.11")
|
||||
trait CurrentEventsByTagQuery extends ReadJournal {
|
||||
|
||||
/**
|
||||
|
|
@ -18,7 +17,6 @@ trait CurrentEventsByTagQuery extends ReadJournal {
|
|||
* is completed immediately when it reaches the end of the "result set". Events that are
|
||||
* stored after the query is completed are not included in the event stream.
|
||||
*/
|
||||
def currentEventsByTag(tag: String, offset: Long): Source[EventEnvelope, NotUsed]
|
||||
|
||||
def currentEventsByTag(tag: String, offset: Offset): Source[EventEnvelope, NotUsed]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2015-2016 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package akka.persistence.query.javadsl
|
||||
|
||||
import akka.NotUsed
|
||||
import akka.persistence.query.{ EventEnvelope2, Offset }
|
||||
import akka.stream.javadsl.Source
|
||||
|
||||
/**
|
||||
* A plugin may optionally support this query by implementing this interface.
|
||||
*/
|
||||
// TODO: Rename it to CurrentEventsByTagQuery in Akka 2.5
|
||||
trait CurrentEventsByTagQuery2 extends ReadJournal {
|
||||
|
||||
/**
|
||||
* Same type of query as [[EventsByTagQuery#eventsByTag]] but the event stream
|
||||
* is completed immediately when it reaches the end of the "result set". Events that are
|
||||
* stored after the query is completed are not included in the event stream.
|
||||
*/
|
||||
def currentEventsByTag(tag: String, offset: Offset): Source[EventEnvelope2, NotUsed]
|
||||
}
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ import akka.stream.javadsl.Source
|
|||
trait CurrentPersistenceIdsQuery extends ReadJournal {
|
||||
|
||||
/**
|
||||
* Same type of query as [[AllPersistenceIdsQuery#allPersistenceIds]] but the stream
|
||||
* Same type of query as [[PersistenceIdsQuery#allPersistenceIds]] but the stream
|
||||
* is completed immediately when it reaches the end of the "result set". Persistent
|
||||
* actors that are created after the query is completed are not included in the stream.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4,13 +4,12 @@
|
|||
package akka.persistence.query.javadsl
|
||||
|
||||
import akka.NotUsed
|
||||
import akka.persistence.query.{ EventEnvelope, Offset }
|
||||
import akka.stream.javadsl.Source
|
||||
import akka.persistence.query.EventEnvelope
|
||||
|
||||
/**
|
||||
* A plugin may optionally support this query by implementing this interface.
|
||||
*/
|
||||
@deprecated("To be replaced by EventsByTagQuery2 from Akka 2.5", "2.4.11")
|
||||
trait EventsByTagQuery extends ReadJournal {
|
||||
|
||||
/**
|
||||
|
|
@ -36,6 +35,6 @@ trait EventsByTagQuery extends ReadJournal {
|
|||
* Corresponding query that is completed when it reaches the end of the currently
|
||||
* stored events is provided by [[CurrentEventsByTagQuery#currentEventsByTag]].
|
||||
*/
|
||||
def eventsByTag(tag: String, offset: Long): Source[EventEnvelope, NotUsed]
|
||||
def eventsByTag(tag: String, offset: Offset): Source[EventEnvelope, NotUsed]
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,41 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2015-2016 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package akka.persistence.query.javadsl
|
||||
|
||||
import akka.NotUsed
|
||||
import akka.persistence.query.{ EventEnvelope2, Offset }
|
||||
import akka.stream.javadsl.Source
|
||||
|
||||
/**
|
||||
* A plugin may optionally support this query by implementing this interface.
|
||||
*/
|
||||
// TODO: Rename it to EventsByTagQuery in Akka 2.5
|
||||
trait EventsByTagQuery2 extends ReadJournal {
|
||||
|
||||
/**
|
||||
* Query events that have a specific tag. A tag can for example correspond to an
|
||||
* aggregate root type (in DDD terminology).
|
||||
*
|
||||
* The consumer can keep track of its current position in the event stream by storing the
|
||||
* `offset` and restart the query from a given `offset` after a crash/restart.
|
||||
*
|
||||
* The exact meaning of the `offset` depends on the journal and must be documented by the
|
||||
* read journal plugin. It may be a sequential id number that uniquely identifies the
|
||||
* position of each event within the event stream. Distributed data stores cannot easily
|
||||
* support those semantics and they may use a weaker meaning. For example it may be a
|
||||
* timestamp (taken when the event was created or stored). Timestamps are not unique and
|
||||
* not strictly ordered, since clocks on different machines may not be synchronized.
|
||||
*
|
||||
* The returned event stream should be ordered by `offset` if possible, but this can also be
|
||||
* difficult to fulfill for a distributed data store. The order must be documented by the
|
||||
* read journal plugin.
|
||||
*
|
||||
* The stream is not completed when it reaches the end of the currently stored events,
|
||||
* but it continues to push new events when new events are persisted.
|
||||
* Corresponding query that is completed when it reaches the end of the currently
|
||||
* stored events is provided by [[CurrentEventsByTagQuery#currentEventsByTag]].
|
||||
*/
|
||||
def eventsByTag(tag: String, offset: Offset): Source[EventEnvelope2, NotUsed]
|
||||
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ import akka.stream.javadsl.Source
|
|||
/**
|
||||
* A plugin may optionally support this query by implementing this interface.
|
||||
*/
|
||||
trait AllPersistenceIdsQuery extends ReadJournal {
|
||||
trait PersistenceIdsQuery extends ReadJournal {
|
||||
|
||||
/**
|
||||
* Query all `PersistentActor` identifiers, i.e. as defined by the
|
||||
|
|
@ -20,6 +20,6 @@ trait AllPersistenceIdsQuery extends ReadJournal {
|
|||
* Corresponding query that is completed when it reaches the end of the currently
|
||||
* currently used `persistenceIds` is provided by [[CurrentPersistenceIdsQuery#currentPersistenceIds]].
|
||||
*/
|
||||
def allPersistenceIds(): Source[String, NotUsed]
|
||||
def persistenceIds(): Source[String, NotUsed]
|
||||
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ package akka.persistence.query.javadsl
|
|||
* The interface is very open so that different journals may implement specific queries.
|
||||
*
|
||||
* There are a few pre-defined queries that a query implementation may implement,
|
||||
* such as [[EventsByPersistenceIdQuery]], [[AllPersistenceIdsQuery]] and [[EventsByTagQuery]]
|
||||
* such as [[EventsByPersistenceIdQuery]], [[PersistenceIdsQuery]] and [[EventsByTagQuery]]
|
||||
* Implementation of these queries are optional and query (journal) plugins may define
|
||||
* their own specialized queries by implementing other methods.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
package akka.persistence.query.journal.leveldb.javadsl
|
||||
|
||||
import akka.NotUsed
|
||||
import akka.persistence.query.{ EventEnvelope, EventEnvelope2, Offset }
|
||||
import akka.persistence.query.{ EventEnvelope, EventEnvelope, Offset }
|
||||
import akka.persistence.query.javadsl._
|
||||
import akka.stream.javadsl.Source
|
||||
|
||||
|
|
@ -26,14 +26,14 @@ import akka.stream.javadsl.Source
|
|||
*/
|
||||
class LeveldbReadJournal(scaladslReadJournal: akka.persistence.query.journal.leveldb.scaladsl.LeveldbReadJournal)
|
||||
extends ReadJournal
|
||||
with AllPersistenceIdsQuery
|
||||
with PersistenceIdsQuery
|
||||
with CurrentPersistenceIdsQuery
|
||||
with EventsByPersistenceIdQuery
|
||||
with CurrentEventsByPersistenceIdQuery
|
||||
with EventsByTagQuery
|
||||
with EventsByTagQuery2
|
||||
with EventsByTagQuery
|
||||
with CurrentEventsByTagQuery
|
||||
with CurrentEventsByTagQuery2 {
|
||||
with CurrentEventsByTagQuery {
|
||||
|
||||
/**
|
||||
* `allPersistenceIds` is used for retrieving all `persistenceIds` of all
|
||||
|
|
@ -53,8 +53,8 @@ class LeveldbReadJournal(scaladslReadJournal: akka.persistence.query.journal.lev
|
|||
* The stream is completed with failure if there is a failure in executing the query in the
|
||||
* backend journal.
|
||||
*/
|
||||
override def allPersistenceIds(): Source[String, NotUsed] =
|
||||
scaladslReadJournal.allPersistenceIds().asJava
|
||||
override def persistenceIds(): Source[String, NotUsed] =
|
||||
scaladslReadJournal.persistenceIds().asJava
|
||||
|
||||
/**
|
||||
* Same type of query as [[#allPersistenceIds]] but the stream
|
||||
|
|
@ -138,7 +138,7 @@ class LeveldbReadJournal(scaladslReadJournal: akka.persistence.query.journal.lev
|
|||
* The stream is completed with failure if there is a failure in executing the query in the
|
||||
* backend journal.
|
||||
*/
|
||||
override def eventsByTag(tag: String, offset: Offset): Source[EventEnvelope2, NotUsed] =
|
||||
override def eventsByTag(tag: String, offset: Offset): Source[EventEnvelope, NotUsed] =
|
||||
scaladslReadJournal.eventsByTag(tag, offset).asJava
|
||||
|
||||
override def eventsByTag(tag: String, offset: Long): Source[EventEnvelope, NotUsed] =
|
||||
|
|
@ -149,7 +149,7 @@ class LeveldbReadJournal(scaladslReadJournal: akka.persistence.query.journal.lev
|
|||
* is completed immediately when it reaches the end of the "result set". Events that are
|
||||
* stored after the query is completed are not included in the event stream.
|
||||
*/
|
||||
override def currentEventsByTag(tag: String, offset: Offset): Source[EventEnvelope2, NotUsed] =
|
||||
override def currentEventsByTag(tag: String, offset: Offset): Source[EventEnvelope, NotUsed] =
|
||||
scaladslReadJournal.currentEventsByTag(tag, offset).asJava
|
||||
|
||||
override def currentEventsByTag(tag: String, offset: Long): Source[EventEnvelope, NotUsed] =
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import akka.NotUsed
|
|||
|
||||
import scala.concurrent.duration._
|
||||
import akka.actor.ExtendedActorSystem
|
||||
import akka.persistence.query.{ EventEnvelope, EventEnvelope2, Offset, Sequence }
|
||||
import akka.persistence.query.{ EventEnvelope, EventEnvelope, Offset, Sequence }
|
||||
import akka.persistence.query.journal.leveldb.AllPersistenceIdsPublisher
|
||||
import akka.persistence.query.journal.leveldb.EventsByPersistenceIdPublisher
|
||||
import akka.persistence.query.journal.leveldb.EventsByTagPublisher
|
||||
|
|
@ -35,14 +35,14 @@ import com.typesafe.config.Config
|
|||
* for the default [[LeveldbReadJournal#Identifier]]. See `reference.conf`.
|
||||
*/
|
||||
class LeveldbReadJournal(system: ExtendedActorSystem, config: Config) extends ReadJournal
|
||||
with AllPersistenceIdsQuery
|
||||
with PersistenceIdsQuery
|
||||
with CurrentPersistenceIdsQuery
|
||||
with EventsByPersistenceIdQuery
|
||||
with CurrentEventsByPersistenceIdQuery
|
||||
with EventsByTagQuery
|
||||
with EventsByTagQuery2
|
||||
with EventsByTagQuery
|
||||
with CurrentEventsByTagQuery
|
||||
with CurrentEventsByTagQuery2 {
|
||||
with CurrentEventsByTagQuery {
|
||||
|
||||
private val serialization = SerializationExtension(system)
|
||||
private val refreshInterval = Some(config.getDuration("refresh-interval", MILLISECONDS).millis)
|
||||
|
|
@ -51,7 +51,7 @@ class LeveldbReadJournal(system: ExtendedActorSystem, config: Config) extends Re
|
|||
|
||||
private val envelopetoEnvelope2 = Flow[EventEnvelope].map {
|
||||
case EventEnvelope(offset, persistenceId, sequenceNr, event) ⇒
|
||||
EventEnvelope2(Sequence(offset), persistenceId, sequenceNr, event)
|
||||
EventEnvelope(Sequence(offset), persistenceId, sequenceNr, event)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -72,7 +72,7 @@ class LeveldbReadJournal(system: ExtendedActorSystem, config: Config) extends Re
|
|||
* The stream is completed with failure if there is a failure in executing the query in the
|
||||
* backend journal.
|
||||
*/
|
||||
override def allPersistenceIds(): Source[String, NotUsed] = {
|
||||
override def persistenceIds(): Source[String, NotUsed] = {
|
||||
// no polling for this query, the write journal will push all changes, i.e.
|
||||
// no refreshInterval
|
||||
Source.actorPublisher[String](AllPersistenceIdsPublisher.props(liveQuery = true, maxBufSize, writeJournalPluginId))
|
||||
|
|
@ -171,7 +171,7 @@ class LeveldbReadJournal(system: ExtendedActorSystem, config: Config) extends Re
|
|||
* The stream is completed with failure if there is a failure in executing the query in the
|
||||
* backend journal.
|
||||
*/
|
||||
override def eventsByTag(tag: String, offset: Offset = Sequence(0L)): Source[EventEnvelope2, NotUsed] =
|
||||
override def eventsByTag(tag: String, offset: Offset = Sequence(0L)): Source[EventEnvelope, NotUsed] =
|
||||
offset match {
|
||||
case Sequence(offsetValue) ⇒
|
||||
eventsByTag(tag, offsetValue).via(envelopetoEnvelope2)
|
||||
|
|
@ -191,7 +191,7 @@ class LeveldbReadJournal(system: ExtendedActorSystem, config: Config) extends Re
|
|||
* is completed immediately when it reaches the end of the "result set". Events that are
|
||||
* stored after the query is completed are not included in the event stream.
|
||||
*/
|
||||
override def currentEventsByTag(tag: String, offset: Offset = Sequence(0L)): Source[EventEnvelope2, NotUsed] =
|
||||
override def currentEventsByTag(tag: String, offset: Offset = Sequence(0L)): Source[EventEnvelope, NotUsed] =
|
||||
offset match {
|
||||
case Sequence(offsetValue) ⇒
|
||||
currentEventsByTag(tag, offsetValue).via(envelopetoEnvelope2)
|
||||
|
|
|
|||
|
|
@ -4,13 +4,12 @@
|
|||
package akka.persistence.query.scaladsl
|
||||
|
||||
import akka.NotUsed
|
||||
import akka.persistence.query.{ EventEnvelope, Offset }
|
||||
import akka.stream.scaladsl.Source
|
||||
import akka.persistence.query.EventEnvelope
|
||||
|
||||
/**
|
||||
* A plugin may optionally support this query by implementing this trait.
|
||||
*/
|
||||
@deprecated("To be replaced by CurrentEventsByTagQuery2 from Akka 2.5", "2.4.11")
|
||||
trait CurrentEventsByTagQuery extends ReadJournal {
|
||||
|
||||
/**
|
||||
|
|
@ -18,7 +17,7 @@ trait CurrentEventsByTagQuery extends ReadJournal {
|
|||
* is completed immediately when it reaches the end of the "result set". Events that are
|
||||
* stored after the query is completed are not included in the event stream.
|
||||
*/
|
||||
def currentEventsByTag(tag: String, offset: Long): Source[EventEnvelope, NotUsed]
|
||||
def currentEventsByTag(tag: String, offset: Offset): Source[EventEnvelope, NotUsed]
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2015-2016 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package akka.persistence.query.scaladsl
|
||||
|
||||
import akka.NotUsed
|
||||
import akka.persistence.query.{ EventEnvelope2, Offset }
|
||||
import akka.stream.scaladsl.Source
|
||||
|
||||
/**
|
||||
* A plugin may optionally support this query by implementing this trait.
|
||||
*/
|
||||
// TODO: Rename it to CurrentEventsByTagQuery in Akka 2.5
|
||||
trait CurrentEventsByTagQuery2 extends ReadJournal {
|
||||
|
||||
/**
|
||||
* Same type of query as [[EventsByTagQuery#eventsByTag]] but the event stream
|
||||
* is completed immediately when it reaches the end of the "result set". Events that are
|
||||
* stored after the query is completed are not included in the event stream.
|
||||
*/
|
||||
def currentEventsByTag(tag: String, offset: Offset): Source[EventEnvelope2, NotUsed]
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ import akka.stream.scaladsl.Source
|
|||
trait CurrentPersistenceIdsQuery extends ReadJournal {
|
||||
|
||||
/**
|
||||
* Same type of query as [[AllPersistenceIdsQuery#allPersistenceIds]] but the stream
|
||||
* Same type of query as [[PersistenceIdsQuery#allPersistenceIds]] but the stream
|
||||
* is completed immediately when it reaches the end of the "result set". Persistent
|
||||
* actors that are created after the query is completed are not included in the stream.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4,13 +4,12 @@
|
|||
package akka.persistence.query.scaladsl
|
||||
|
||||
import akka.NotUsed
|
||||
import akka.persistence.query.{ EventEnvelope, Offset }
|
||||
import akka.stream.scaladsl.Source
|
||||
import akka.persistence.query.EventEnvelope
|
||||
|
||||
/**
|
||||
* A plugin may optionally support this query by implementing this trait.
|
||||
*/
|
||||
@deprecated("To be replaced by EventsByTagQuery2 from Akka 2.5", "2.4.11")
|
||||
trait EventsByTagQuery extends ReadJournal {
|
||||
|
||||
/**
|
||||
|
|
@ -36,7 +35,7 @@ trait EventsByTagQuery extends ReadJournal {
|
|||
* Corresponding query that is completed when it reaches the end of the currently
|
||||
* stored events is provided by [[CurrentEventsByTagQuery#currentEventsByTag]].
|
||||
*/
|
||||
def eventsByTag(tag: String, offset: Long): Source[EventEnvelope, NotUsed]
|
||||
def eventsByTag(tag: String, offset: Offset): Source[EventEnvelope, NotUsed]
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2015-2016 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package akka.persistence.query.scaladsl
|
||||
|
||||
import akka.NotUsed
|
||||
import akka.persistence.query.{ EventEnvelope2, Offset }
|
||||
import akka.stream.scaladsl.Source
|
||||
|
||||
/**
|
||||
* A plugin may optionally support this query by implementing this trait.
|
||||
*/
|
||||
// TODO: Rename it to EventsByTagQuery in Akka 2.5
|
||||
trait EventsByTagQuery2 extends ReadJournal {
|
||||
|
||||
/**
|
||||
* Query events that have a specific tag. A tag can for example correspond to an
|
||||
* aggregate root type (in DDD terminology).
|
||||
*
|
||||
* The consumer can keep track of its current position in the event stream by storing the
|
||||
* `offset` and restart the query from a given `offset` after a crash/restart.
|
||||
*
|
||||
* The exact meaning of the `offset` depends on the journal and must be documented by the
|
||||
* read journal plugin. It may be a sequential id number that uniquely identifies the
|
||||
* position of each event within the event stream. Distributed data stores cannot easily
|
||||
* support those semantics and they may use a weaker meaning. For example it may be a
|
||||
* timestamp (taken when the event was created or stored). Timestamps are not unique and
|
||||
* not strictly ordered, since clocks on different machines may not be synchronized.
|
||||
*
|
||||
* The returned event stream should be ordered by `offset` if possible, but this can also be
|
||||
* difficult to fulfill for a distributed data store. The order must be documented by the
|
||||
* read journal plugin.
|
||||
*
|
||||
* The stream is not completed when it reaches the end of the currently stored events,
|
||||
* but it continues to push new events when new events are persisted.
|
||||
* Corresponding query that is completed when it reaches the end of the currently
|
||||
* stored events is provided by [[CurrentEventsByTagQuery#currentEventsByTag]].
|
||||
*/
|
||||
def eventsByTag(tag: String, offset: Offset): Source[EventEnvelope2, NotUsed]
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -9,7 +9,7 @@ import akka.stream.scaladsl.Source
|
|||
/**
|
||||
* A plugin may optionally support this query by implementing this trait.
|
||||
*/
|
||||
trait AllPersistenceIdsQuery extends ReadJournal {
|
||||
trait PersistenceIdsQuery extends ReadJournal {
|
||||
|
||||
/**
|
||||
* Query all `PersistentActor` identifiers, i.e. as defined by the
|
||||
|
|
@ -20,6 +20,6 @@ trait AllPersistenceIdsQuery extends ReadJournal {
|
|||
* Corresponding query that is completed when it reaches the end of the currently
|
||||
* currently used `persistenceIds` is provided by [[CurrentPersistenceIdsQuery#currentPersistenceIds]].
|
||||
*/
|
||||
def allPersistenceIds(): Source[String, NotUsed]
|
||||
def persistenceIds(): Source[String, NotUsed]
|
||||
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ package akka.persistence.query.scaladsl
|
|||
* The interface is very open so that different journals may implement specific queries.
|
||||
*
|
||||
* There are a few pre-defined queries that a query implementation may implement,
|
||||
* such as [[EventsByPersistenceIdQuery]], [[AllPersistenceIdsQuery]] and [[EventsByTagQuery]]
|
||||
* such as [[EventsByPersistenceIdQuery]], [[PersistenceIdsQuery]] and [[EventsByTagQuery]]
|
||||
* Implementation of these queries are optional and query (journal) plugins may define
|
||||
* their own specialized queries by implementing other methods.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ package akka.persistence.query;
|
|||
import java.util.Iterator;
|
||||
|
||||
import akka.NotUsed;
|
||||
import akka.persistence.query.javadsl.AllPersistenceIdsQuery;
|
||||
import akka.persistence.query.javadsl.PersistenceIdsQuery;
|
||||
import akka.persistence.query.javadsl.ReadJournal;
|
||||
import akka.stream.javadsl.Source;
|
||||
|
||||
|
|
@ -15,12 +15,12 @@ import akka.stream.javadsl.Source;
|
|||
* Use for tests only!
|
||||
* Emits infinite stream of strings (representing queried for events).
|
||||
*/
|
||||
public class DummyJavaReadJournal implements ReadJournal, AllPersistenceIdsQuery {
|
||||
public class DummyJavaReadJournal implements ReadJournal, PersistenceIdsQuery {
|
||||
public static final String Identifier = "akka.persistence.query.journal.dummy-java";
|
||||
|
||||
|
||||
@Override
|
||||
public Source<String, NotUsed> allPersistenceIds() {
|
||||
public Source<String, NotUsed> persistenceIds() {
|
||||
return Source.fromIterator(() -> new Iterator<String>() {
|
||||
private int i = 0;
|
||||
@Override public boolean hasNext() { return true; }
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import akka.NotUsed;
|
|||
* Emits infinite stream of strings (representing queried for events).
|
||||
*/
|
||||
public class DummyJavaReadJournalForScala implements akka.persistence.query.scaladsl.ReadJournal,
|
||||
akka.persistence.query.scaladsl.AllPersistenceIdsQuery {
|
||||
akka.persistence.query.scaladsl.PersistenceIdsQuery {
|
||||
|
||||
public static final String Identifier = DummyJavaReadJournal.Identifier;
|
||||
|
||||
|
|
@ -22,8 +22,8 @@ public class DummyJavaReadJournalForScala implements akka.persistence.query.scal
|
|||
}
|
||||
|
||||
@Override
|
||||
public akka.stream.scaladsl.Source<String, NotUsed> allPersistenceIds() {
|
||||
return readJournal.allPersistenceIds().asScala();
|
||||
public akka.stream.scaladsl.Source<String, NotUsed> persistenceIds() {
|
||||
return readJournal.persistenceIds().asScala();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,6 @@ public class PersistenceQueryTest {
|
|||
public void shouldExposeJavaDSLFriendlyQueryJournal() throws Exception {
|
||||
final DummyJavaReadJournal readJournal = PersistenceQuery.get(system).getReadJournalFor(DummyJavaReadJournal.class,
|
||||
"noop-journal");
|
||||
final akka.stream.javadsl.Source<String, NotUsed> ids = readJournal.allPersistenceIds();
|
||||
final akka.stream.javadsl.Source<String, NotUsed> ids = readJournal.persistenceIds();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ import com.typesafe.config.{ Config, ConfigFactory }
|
|||
* Use for tests only!
|
||||
* Emits infinite stream of strings (representing queried for events).
|
||||
*/
|
||||
class DummyReadJournal extends scaladsl.ReadJournal with scaladsl.AllPersistenceIdsQuery {
|
||||
override def allPersistenceIds(): Source[String, NotUsed] =
|
||||
class DummyReadJournal extends scaladsl.ReadJournal with scaladsl.PersistenceIdsQuery {
|
||||
override def persistenceIds(): Source[String, NotUsed] =
|
||||
Source.fromIterator(() ⇒ Iterator.from(0)).map(_.toString)
|
||||
}
|
||||
|
||||
|
|
@ -21,9 +21,9 @@ object DummyReadJournal {
|
|||
final val Identifier = "akka.persistence.query.journal.dummy"
|
||||
}
|
||||
|
||||
class DummyReadJournalForJava(readJournal: DummyReadJournal) extends javadsl.ReadJournal with javadsl.AllPersistenceIdsQuery {
|
||||
override def allPersistenceIds(): akka.stream.javadsl.Source[String, NotUsed] =
|
||||
readJournal.allPersistenceIds().asJava
|
||||
class DummyReadJournalForJava(readJournal: DummyReadJournal) extends javadsl.ReadJournal with javadsl.PersistenceIdsQuery {
|
||||
override def persistenceIds(): akka.stream.javadsl.Source[String, NotUsed] =
|
||||
readJournal.persistenceIds().asJava
|
||||
}
|
||||
|
||||
object DummyReadJournalProvider {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import scala.concurrent.duration._
|
|||
|
||||
import akka.persistence.query.PersistenceQuery
|
||||
import akka.persistence.query.journal.leveldb.scaladsl.LeveldbReadJournal
|
||||
import akka.persistence.query.scaladsl.AllPersistenceIdsQuery
|
||||
import akka.persistence.query.scaladsl.PersistenceIdsQuery
|
||||
import akka.stream.ActorMaterializer
|
||||
import akka.stream.testkit.scaladsl.TestSink
|
||||
import akka.testkit.AkkaSpec
|
||||
|
|
@ -32,7 +32,7 @@ class AllPersistenceIdsSpec extends AkkaSpec(AllPersistenceIdsSpec.config)
|
|||
"Leveldb query AllPersistenceIds" must {
|
||||
|
||||
"implement standard AllPersistenceIdsQuery" in {
|
||||
queries.isInstanceOf[AllPersistenceIdsQuery] should ===(true)
|
||||
queries.isInstanceOf[PersistenceIdsQuery] should ===(true)
|
||||
}
|
||||
|
||||
"find existing persistenceIds" in {
|
||||
|
|
@ -57,7 +57,7 @@ class AllPersistenceIdsSpec extends AkkaSpec(AllPersistenceIdsSpec.config)
|
|||
system.actorOf(TestActor.props("d")) ! "d1"
|
||||
expectMsg("d1-done")
|
||||
|
||||
val src = queries.allPersistenceIds()
|
||||
val src = queries.persistenceIds()
|
||||
val probe = src.runWith(TestSink.probe[String])
|
||||
probe.within(10.seconds) {
|
||||
probe.request(5)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import scala.concurrent.duration._
|
|||
import akka.actor.ActorRef
|
||||
import akka.persistence.query.PersistenceQuery
|
||||
import akka.persistence.query.journal.leveldb.scaladsl.LeveldbReadJournal
|
||||
import akka.persistence.query.scaladsl.EventsByTagQuery2
|
||||
import akka.persistence.query.scaladsl.EventsByTagQuery
|
||||
import akka.stream.ActorMaterializer
|
||||
import akka.stream.testkit.scaladsl.TestSink
|
||||
import akka.testkit.AkkaSpec
|
||||
|
|
@ -49,7 +49,7 @@ class EventsByPersistenceIdSpec extends AkkaSpec(EventsByPersistenceIdSpec.confi
|
|||
"Leveldb query EventsByPersistenceId" must {
|
||||
|
||||
"implement standard EventsByTagQuery" in {
|
||||
queries.isInstanceOf[EventsByTagQuery2] should ===(true)
|
||||
queries.isInstanceOf[EventsByTagQuery] should ===(true)
|
||||
}
|
||||
|
||||
"find existing events" in {
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ package akka.persistence.query.journal.leveldb
|
|||
import scala.concurrent.duration._
|
||||
import akka.persistence.journal.Tagged
|
||||
import akka.persistence.journal.WriteEventAdapter
|
||||
import akka.persistence.query.{ EventEnvelope, EventEnvelope2, PersistenceQuery, Sequence }
|
||||
import akka.persistence.query.{ EventEnvelope, EventEnvelope, PersistenceQuery, Sequence }
|
||||
import akka.persistence.query.journal.leveldb.scaladsl.LeveldbReadJournal
|
||||
import akka.persistence.query.scaladsl.EventsByTagQuery2
|
||||
import akka.persistence.query.scaladsl.EventsByTagQuery
|
||||
import akka.stream.ActorMaterializer
|
||||
import akka.stream.testkit.scaladsl.TestSink
|
||||
import akka.testkit.AkkaSpec
|
||||
|
|
@ -55,7 +55,7 @@ class EventsByTagSpec extends AkkaSpec(EventsByTagSpec.config)
|
|||
|
||||
"Leveldb query EventsByTag" must {
|
||||
"implement standard EventsByTagQuery" in {
|
||||
queries.isInstanceOf[EventsByTagQuery2] should ===(true)
|
||||
queries.isInstanceOf[EventsByTagQuery] should ===(true)
|
||||
}
|
||||
|
||||
"find existing events" in {
|
||||
|
|
@ -75,17 +75,17 @@ class EventsByTagSpec extends AkkaSpec(EventsByTagSpec.config)
|
|||
val greenSrc = queries.currentEventsByTag(tag = "green", offset = Sequence(0L))
|
||||
greenSrc.runWith(TestSink.probe[Any])
|
||||
.request(2)
|
||||
.expectNext(EventEnvelope2(Sequence(1L), "a", 2L, "a green apple"))
|
||||
.expectNext(EventEnvelope2(Sequence(2L), "a", 3L, "a green banana"))
|
||||
.expectNext(EventEnvelope(Sequence(1L), "a", 2L, "a green apple"))
|
||||
.expectNext(EventEnvelope(Sequence(2L), "a", 3L, "a green banana"))
|
||||
.expectNoMsg(500.millis)
|
||||
.request(2)
|
||||
.expectNext(EventEnvelope2(Sequence(3L), "b", 2L, "a green leaf"))
|
||||
.expectNext(EventEnvelope(Sequence(3L), "b", 2L, "a green leaf"))
|
||||
.expectComplete()
|
||||
|
||||
val blackSrc = queries.currentEventsByTag(tag = "black", offset = Sequence(0L))
|
||||
blackSrc.runWith(TestSink.probe[Any])
|
||||
.request(5)
|
||||
.expectNext(EventEnvelope2(Sequence(1L), "b", 1L, "a black car"))
|
||||
.expectNext(EventEnvelope(Sequence(1L), "b", 1L, "a black car"))
|
||||
.expectComplete()
|
||||
}
|
||||
|
||||
|
|
@ -95,8 +95,8 @@ class EventsByTagSpec extends AkkaSpec(EventsByTagSpec.config)
|
|||
val greenSrc = queries.currentEventsByTag(tag = "green", offset = Sequence(0L))
|
||||
val probe = greenSrc.runWith(TestSink.probe[Any])
|
||||
.request(2)
|
||||
.expectNext(EventEnvelope2(Sequence(1L), "a", 2L, "a green apple"))
|
||||
.expectNext(EventEnvelope2(Sequence(2L), "a", 3L, "a green banana"))
|
||||
.expectNext(EventEnvelope(Sequence(1L), "a", 2L, "a green apple"))
|
||||
.expectNext(EventEnvelope(Sequence(2L), "a", 3L, "a green banana"))
|
||||
.expectNoMsg(100.millis)
|
||||
|
||||
c ! "a green cucumber"
|
||||
|
|
@ -105,7 +105,7 @@ class EventsByTagSpec extends AkkaSpec(EventsByTagSpec.config)
|
|||
probe
|
||||
.expectNoMsg(100.millis)
|
||||
.request(5)
|
||||
.expectNext(EventEnvelope2(Sequence(3L), "b", 2L, "a green leaf"))
|
||||
.expectNext(EventEnvelope(Sequence(3L), "b", 2L, "a green leaf"))
|
||||
.expectComplete() // green cucumber not seen
|
||||
}
|
||||
|
||||
|
|
@ -113,9 +113,9 @@ class EventsByTagSpec extends AkkaSpec(EventsByTagSpec.config)
|
|||
val greenSrc = queries.currentEventsByTag(tag = "green", offset = Sequence(2L))
|
||||
val probe = greenSrc.runWith(TestSink.probe[Any])
|
||||
.request(10)
|
||||
.expectNext(EventEnvelope2(Sequence(2L), "a", 3L, "a green banana"))
|
||||
.expectNext(EventEnvelope2(Sequence(3L), "b", 2L, "a green leaf"))
|
||||
.expectNext(EventEnvelope2(Sequence(4L), "c", 1L, "a green cucumber"))
|
||||
.expectNext(EventEnvelope(Sequence(2L), "a", 3L, "a green banana"))
|
||||
.expectNext(EventEnvelope(Sequence(3L), "b", 2L, "a green leaf"))
|
||||
.expectNext(EventEnvelope(Sequence(4L), "c", 1L, "a green cucumber"))
|
||||
.expectComplete()
|
||||
}
|
||||
}
|
||||
|
|
@ -127,7 +127,7 @@ class EventsByTagSpec extends AkkaSpec(EventsByTagSpec.config)
|
|||
val blackSrc = queries.eventsByTag(tag = "black", offset = Sequence(0L))
|
||||
val probe = blackSrc.runWith(TestSink.probe[Any])
|
||||
.request(2)
|
||||
.expectNext(EventEnvelope2(Sequence(1L), "b", 1L, "a black car"))
|
||||
.expectNext(EventEnvelope(Sequence(1L), "b", 1L, "a black car"))
|
||||
.expectNoMsg(100.millis)
|
||||
|
||||
d ! "a black dog"
|
||||
|
|
@ -136,19 +136,19 @@ class EventsByTagSpec extends AkkaSpec(EventsByTagSpec.config)
|
|||
expectMsg(s"a black night-done")
|
||||
|
||||
probe
|
||||
.expectNext(EventEnvelope2(Sequence(2L), "d", 1L, "a black dog"))
|
||||
.expectNext(EventEnvelope(Sequence(2L), "d", 1L, "a black dog"))
|
||||
.expectNoMsg(100.millis)
|
||||
.request(10)
|
||||
.expectNext(EventEnvelope2(Sequence(3L), "d", 2L, "a black night"))
|
||||
.expectNext(EventEnvelope(Sequence(3L), "d", 2L, "a black night"))
|
||||
}
|
||||
|
||||
"find events from offset" in {
|
||||
val greenSrc = queries.eventsByTag(tag = "green", offset = Sequence(2L))
|
||||
val probe = greenSrc.runWith(TestSink.probe[Any])
|
||||
.request(10)
|
||||
.expectNext(EventEnvelope2(Sequence(2L), "a", 3L, "a green banana"))
|
||||
.expectNext(EventEnvelope2(Sequence(3L), "b", 2L, "a green leaf"))
|
||||
.expectNext(EventEnvelope2(Sequence(4L), "c", 1L, "a green cucumber"))
|
||||
.expectNext(EventEnvelope(Sequence(2L), "a", 3L, "a green banana"))
|
||||
.expectNext(EventEnvelope(Sequence(3L), "b", 2L, "a green leaf"))
|
||||
.expectNext(EventEnvelope(Sequence(4L), "c", 1L, "a green cucumber"))
|
||||
.expectNoMsg(100.millis)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue