Merge branch 'master' into fix-receive-timeout
This commit is contained in:
commit
500f0c2ddc
10 changed files with 51 additions and 51 deletions
|
|
@ -15,46 +15,46 @@ import akka.util.OptionVal
|
|||
* Used with [[EventHandlerBuilder]] to setup the behavior of a [[PersistentBehavior]]
|
||||
*/
|
||||
@FunctionalInterface
|
||||
trait EventHandler[Event, State] {
|
||||
trait EventHandler[State, Event] {
|
||||
def apply(state: State, event: Event): State
|
||||
}
|
||||
|
||||
object EventHandlerBuilder {
|
||||
def builder[Event, State >: Null](): EventHandlerBuilder[Event, State] =
|
||||
new EventHandlerBuilder[Event, State]()
|
||||
def builder[State >: Null, Event](): EventHandlerBuilder[State, Event] =
|
||||
new EventHandlerBuilder[State, Event]()
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
*/
|
||||
@InternalApi private final case class EventHandlerCase[Event, State](
|
||||
eventPredicate: Event ⇒ Boolean,
|
||||
@InternalApi private final case class EventHandlerCase[State, Event](
|
||||
statePredicate: State ⇒ Boolean,
|
||||
eventPredicate: Event ⇒ Boolean,
|
||||
handler: BiFunction[State, Event, State])
|
||||
}
|
||||
|
||||
final class EventHandlerBuilder[Event, State >: Null]() {
|
||||
final class EventHandlerBuilder[State >: Null, Event]() {
|
||||
import EventHandlerBuilder.EventHandlerCase
|
||||
|
||||
private var cases: List[EventHandlerCase[Event, State]] = Nil
|
||||
private var cases: List[EventHandlerCase[State, Event]] = Nil
|
||||
|
||||
private def addCase(predicate: Event ⇒ Boolean, handler: BiFunction[State, Event, State]): Unit = {
|
||||
cases = EventHandlerCase[Event, State](predicate, _ ⇒ true, handler) :: cases
|
||||
private def addCase(eventPredicate: Event ⇒ Boolean, handler: BiFunction[State, Event, State]): Unit = {
|
||||
cases = EventHandlerCase[State, Event](_ ⇒ true, eventPredicate, handler) :: cases
|
||||
}
|
||||
|
||||
/**
|
||||
* Match any event which is an instance of `E` or a subtype of `E`
|
||||
*/
|
||||
def matchEvent[E <: Event](eventClass: Class[E], biFunction: BiFunction[State, E, State]): EventHandlerBuilder[Event, State] = {
|
||||
def matchEvent[E <: Event](eventClass: Class[E], biFunction: BiFunction[State, E, State]): EventHandlerBuilder[State, Event] = {
|
||||
addCase(e ⇒ eventClass.isAssignableFrom(e.getClass), biFunction.asInstanceOf[BiFunction[State, Event, State]])
|
||||
this
|
||||
}
|
||||
|
||||
def matchEvent[E <: Event, S <: State](eventClass: Class[E], stateClass: Class[S],
|
||||
biFunction: BiFunction[S, E, State]): EventHandlerBuilder[Event, State] = {
|
||||
biFunction: BiFunction[S, E, State]): EventHandlerBuilder[State, Event] = {
|
||||
|
||||
cases = EventHandlerCase[Event, State](
|
||||
eventPredicate = e ⇒ eventClass.isAssignableFrom(e.getClass),
|
||||
cases = EventHandlerCase[State, Event](
|
||||
statePredicate = s ⇒ stateClass.isAssignableFrom(s.getClass),
|
||||
eventPredicate = e ⇒ eventClass.isAssignableFrom(e.getClass),
|
||||
biFunction.asInstanceOf[BiFunction[State, Event, State]]) :: cases
|
||||
this
|
||||
}
|
||||
|
|
@ -64,7 +64,7 @@ final class EventHandlerBuilder[Event, State >: Null]() {
|
|||
*
|
||||
* Builds and returns the handler since this will not let through any states to subsequent match statements
|
||||
*/
|
||||
def matchAny(biFunction: BiFunction[State, Event, State]): EventHandler[Event, State] = {
|
||||
def matchAny(biFunction: BiFunction[State, Event, State]): EventHandler[State, Event] = {
|
||||
addCase(_ ⇒ true, biFunction.asInstanceOf[BiFunction[State, Event, State]])
|
||||
build()
|
||||
}
|
||||
|
|
@ -73,8 +73,8 @@ final class EventHandlerBuilder[Event, State >: Null]() {
|
|||
* Compose this builder with another builder. The handlers in this builder will be tried first followed
|
||||
* by the handlers in `other`.
|
||||
*/
|
||||
def orElse(other: EventHandlerBuilder[Event, State]): EventHandlerBuilder[Event, State] = {
|
||||
val newBuilder = new EventHandlerBuilder[Event, State]
|
||||
def orElse(other: EventHandlerBuilder[State, Event]): EventHandlerBuilder[State, Event] = {
|
||||
val newBuilder = new EventHandlerBuilder[State, Event]
|
||||
// problem with overloaded constructor with `cases` as parameter
|
||||
newBuilder.cases = other.cases ::: cases
|
||||
newBuilder
|
||||
|
|
@ -86,10 +86,10 @@ final class EventHandlerBuilder[Event, State >: Null]() {
|
|||
*
|
||||
* The builder is reset to empty after build has been called.
|
||||
*/
|
||||
def build(): EventHandler[Event, State] = {
|
||||
def build(): EventHandler[State, Event] = {
|
||||
val builtCases = cases.reverse.toArray
|
||||
|
||||
new EventHandler[Event, State] {
|
||||
new EventHandler[State, Event] {
|
||||
def apply(state: State, event: Event): State = {
|
||||
var result: OptionVal[State] = OptionVal.None
|
||||
var idx = 0
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ abstract class PersistentBehavior[Command, Event, State >: Null] private (val pe
|
|||
* For that reason it is strongly discouraged to perform side-effects in this handler;
|
||||
* Side effects should be executed in `andThen` or `recoveryCompleted` blocks.
|
||||
*/
|
||||
protected def eventHandler(): EventHandler[Event, State]
|
||||
protected def eventHandler(): EventHandler[State, Event]
|
||||
|
||||
/**
|
||||
* @param stateClass The handlers defined by this builder are used when the state is an instance of the `stateClass`
|
||||
|
|
@ -85,8 +85,8 @@ abstract class PersistentBehavior[Command, Event, State >: Null] private (val pe
|
|||
/**
|
||||
* @return A new, mutable, event handler builder
|
||||
*/
|
||||
protected final def eventHandlerBuilder(): EventHandlerBuilder[Event, State] =
|
||||
EventHandlerBuilder.builder[Event, State]()
|
||||
protected final def eventHandlerBuilder(): EventHandlerBuilder[State, Event] =
|
||||
EventHandlerBuilder.builder[State, Event]()
|
||||
|
||||
/**
|
||||
* The `callback` function is called to notify the actor that the recovery process
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ public class PersistentActorCompileOnlyTest {
|
|||
|
||||
//#event-handler
|
||||
@Override
|
||||
public EventHandler<SimpleEvent, SimpleState> eventHandler() {
|
||||
public EventHandler<SimpleState, SimpleEvent> eventHandler() {
|
||||
return (state, event) -> state.addEvent(event);
|
||||
}
|
||||
//#event-handler
|
||||
|
|
@ -164,7 +164,7 @@ public class PersistentActorCompileOnlyTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public EventHandler<MyEvent, ExampleState> eventHandler() {
|
||||
public EventHandler<ExampleState, MyEvent> eventHandler() {
|
||||
return eventHandlerBuilder()
|
||||
.matchEvent(Evt.class, (state, event) -> {
|
||||
state.events.add(event.data);
|
||||
|
|
@ -278,7 +278,7 @@ public class PersistentActorCompileOnlyTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public EventHandler<Event, EventsInFlight> eventHandler() {
|
||||
public EventHandler<EventsInFlight, Event> eventHandler() {
|
||||
return eventHandlerBuilder()
|
||||
.matchEvent(IntentRecord.class, (state, event) -> {
|
||||
int nextCorrelationId = event.correlationId;
|
||||
|
|
|
|||
|
|
@ -285,7 +285,7 @@ public class PersistentActorJavaDslTest extends JUnitSuite {
|
|||
}
|
||||
|
||||
@Override
|
||||
public EventHandler<Incremented, State> eventHandler() {
|
||||
public EventHandler<State, Incremented> eventHandler() {
|
||||
return eventHandlerBuilder()
|
||||
.matchEvent(Incremented.class, (state, event) -> {
|
||||
List<Integer> newHistory = new ArrayList<>(state.history);
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class BasicPersistentBehaviorsTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public EventHandler<Event, State> eventHandler() {
|
||||
public EventHandler<State, Event> eventHandler() {
|
||||
return (state, event) -> {
|
||||
throw new RuntimeException("TODO: process the event return the next state");
|
||||
};
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ public class InDepthPersistentBehaviorTest {
|
|||
|
||||
//#event-handler
|
||||
@Override
|
||||
public EventHandler<BlogEvent, BlogState> eventHandler() {
|
||||
public EventHandler<BlogState, BlogEvent> eventHandler() {
|
||||
return eventHandlerBuilder()
|
||||
.matchEvent(PostAdded.class, (state, event) ->
|
||||
new DraftState(event.content, false))
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ public class MovieWatchList extends PersistentBehavior<MovieWatchList.Command, M
|
|||
}
|
||||
|
||||
@Override
|
||||
public EventHandler<Event, MovieList> eventHandler() {
|
||||
public EventHandler<MovieList, Event> eventHandler() {
|
||||
return eventHandlerBuilder()
|
||||
.matchEvent(MovieAdded.class, (state, event) -> state.add(event.movieId))
|
||||
.matchEvent(MovieRemoved.class, (state, event) -> state.remove(event.movieId))
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ public class OptionalBlogState {
|
|||
}
|
||||
|
||||
@Override
|
||||
public EventHandler<BlogEvent, Optional<BlogState>> eventHandler() {
|
||||
public EventHandler<Optional<BlogState>, BlogEvent> eventHandler() {
|
||||
return eventHandlerBuilder()
|
||||
.matchEvent(PostAdded.class, (state, event) ->
|
||||
Optional.of(new BlogState(event.content, false)))
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ object Dependencies {
|
|||
lazy val scalaCheckVersion = settingKey[String]("The version of ScalaCheck to use.")
|
||||
lazy val java8CompatVersion = settingKey[String]("The version of scala-java8-compat to use.")
|
||||
val junitVersion = "4.12"
|
||||
val sslConfigVersion = "0.2.3"
|
||||
val sslConfigVersion = "0.2.4"
|
||||
val slf4jVersion = "1.7.25"
|
||||
val scalaXmlVersion = "1.0.6"
|
||||
val aeronVersion = "1.9.1"
|
||||
val aeronVersion = "1.9.3"
|
||||
|
||||
val Versions = Seq(
|
||||
crossScalaVersions := Seq("2.11.12", "2.12.6"),
|
||||
|
|
@ -26,10 +26,10 @@ object Dependencies {
|
|||
scalaStmVersion := sys.props.get("akka.build.scalaStmVersion").getOrElse("0.8"),
|
||||
scalaCheckVersion := sys.props.get("akka.build.scalaCheckVersion").getOrElse(
|
||||
CrossVersion.partialVersion(scalaVersion.value) match {
|
||||
case Some((2, n)) if n >= 12 ⇒ "1.13.5" // does not work for 2.11
|
||||
case Some((2, n)) if n >= 12 ⇒ "1.14.0" // does not work for 2.11
|
||||
case _ ⇒ "1.13.2"
|
||||
}),
|
||||
scalaTestVersion := "3.0.4",
|
||||
scalaTestVersion := "3.0.5",
|
||||
java8CompatVersion := {
|
||||
CrossVersion.partialVersion(scalaVersion.value) match {
|
||||
case Some((2, n)) if n >= 13 ⇒ "0.9.0"
|
||||
|
|
@ -59,7 +59,7 @@ object Dependencies {
|
|||
|
||||
val sigar = "org.fusesource" % "sigar" % "1.6.4" // ApacheV2
|
||||
|
||||
val jctools = "org.jctools" % "jctools-core" % "2.1.1" // ApacheV2
|
||||
val jctools = "org.jctools" % "jctools-core" % "2.1.2" // ApacheV2
|
||||
|
||||
// reactive streams
|
||||
val reactiveStreams = "org.reactivestreams" % "reactive-streams" % "1.0.2" // CC0
|
||||
|
|
@ -67,7 +67,7 @@ object Dependencies {
|
|||
// ssl-config
|
||||
val sslConfigCore = "com.typesafe" %% "ssl-config-core" % sslConfigVersion // ApacheV2
|
||||
|
||||
val lmdb = "org.lmdbjava" % "lmdbjava" % "0.6.0" // ApacheV2, OpenLDAP Public License
|
||||
val lmdb = "org.lmdbjava" % "lmdbjava" % "0.6.1" // ApacheV2, OpenLDAP Public License
|
||||
|
||||
val junit = "junit" % "junit" % junitVersion // Common Public License 1.0
|
||||
|
||||
|
|
@ -77,17 +77,17 @@ object Dependencies {
|
|||
val aeronDriver = "io.aeron" % "aeron-driver" % aeronVersion // ApacheV2
|
||||
val aeronClient = "io.aeron" % "aeron-client" % aeronVersion // ApacheV2
|
||||
object Docs {
|
||||
val sprayJson = "io.spray" %% "spray-json" % "1.3.3" % "test"
|
||||
val gson = "com.google.code.gson" % "gson" % "2.8.2" % "test"
|
||||
val sprayJson = "io.spray" %% "spray-json" % "1.3.4" % "test"
|
||||
val gson = "com.google.code.gson" % "gson" % "2.8.5" % "test"
|
||||
}
|
||||
|
||||
object Test {
|
||||
val commonsMath = "org.apache.commons" % "commons-math" % "2.2" % "test" // ApacheV2
|
||||
val commonsIo = "commons-io" % "commons-io" % "2.5" % "test" // ApacheV2
|
||||
val commonsCodec = "commons-codec" % "commons-codec" % "1.10" % "test" // ApacheV2
|
||||
val commonsIo = "commons-io" % "commons-io" % "2.6" % "test" // ApacheV2
|
||||
val commonsCodec = "commons-codec" % "commons-codec" % "1.11" % "test" // ApacheV2
|
||||
val junit = "junit" % "junit" % junitVersion % "test" // Common Public License 1.0
|
||||
val logback = "ch.qos.logback" % "logback-classic" % "1.2.3" % "test" // EPL 1.0 / LGPL 2.1
|
||||
val mockito = "org.mockito" % "mockito-core" % "2.7.16" % "test" // MIT
|
||||
val mockito = "org.mockito" % "mockito-core" % "2.19.1" % "test" // MIT
|
||||
// changing the scalatest dependency must be reflected in akka-docs/rst/dev/multi-jvm-testing.rst
|
||||
val scalatest = Def.setting { "org.scalatest" %% "scalatest" % scalaTestVersion.value % "test" } // ApacheV2
|
||||
val scalacheck = Def.setting { "org.scalacheck" %% "scalacheck" % scalaCheckVersion.value % "test" } // New BSD
|
||||
|
|
|
|||
|
|
@ -1,27 +1,27 @@
|
|||
// need this to resolve http://jcenter.bintray.com/org/jenkins-ci/jenkins/1.26/
|
||||
// which is used by plugin "org.kohsuke" % "github-api" % "1.68"
|
||||
resolvers += "Bintray Jcenter" at "https://jcenter.bintray.com/"
|
||||
libraryDependencies += "org.kohsuke" % "github-api" % "1.68"
|
||||
libraryDependencies += "org.kohsuke" % "github-api" % "1.93"
|
||||
|
||||
// these comment markers are for including code into the docs
|
||||
//#sbt-multi-jvm
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-multi-jvm" % "0.4.0")
|
||||
//#sbt-multi-jvm
|
||||
|
||||
addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.1")
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.3")
|
||||
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.2.0")
|
||||
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0-M1")
|
||||
addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.1")
|
||||
addSbtPlugin("com.thoughtworks.sbt-api-mappings" % "sbt-api-mappings" % "2.0.1")
|
||||
addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.2")
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.4")
|
||||
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.3.0")
|
||||
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1")
|
||||
addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.2")
|
||||
addSbtPlugin("com.thoughtworks.sbt-api-mappings" % "sbt-api-mappings" % "2.1.0")
|
||||
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.4")
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.2.2-RC2")
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.5")
|
||||
addSbtPlugin("io.spray" % "sbt-boilerplate" % "0.6.1")
|
||||
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.3.1")
|
||||
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.3.4")
|
||||
addSbtPlugin("com.lightbend.akka" % "sbt-paradox-akka" % "0.9")
|
||||
addSbtPlugin("com.lightbend" % "sbt-whitesource" % "0.1.12")
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.9.3")
|
||||
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.0") // for advanced PR validation features
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0")
|
||||
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.1") // for advanced PR validation features
|
||||
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.0.0") // for maintenance of copyright file header
|
||||
|
||||
// used for @unidoc directive
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue