From 15f15415ee3a73d29ff6124ad38e381636156402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Andr=C3=A9n?= Date: Thu, 4 Jun 2020 17:00:45 +0200 Subject: [PATCH 1/2] Provide an init for Sharded Daemon Process without settings but with stop message #29081 --- .../internal/ShardedDaemonProcessImpl.scala | 17 +++++++++++++++-- .../typed/javadsl/ShardedDaemonProcess.scala | 14 ++++++++++++++ .../typed/scaladsl/ShardedDaemonProcess.scala | 10 ++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/akka-cluster-sharding-typed/src/main/scala/akka/cluster/sharding/typed/internal/ShardedDaemonProcessImpl.scala b/akka-cluster-sharding-typed/src/main/scala/akka/cluster/sharding/typed/internal/ShardedDaemonProcessImpl.scala index 01233edf86..a5c12d66f1 100644 --- a/akka-cluster-sharding-typed/src/main/scala/akka/cluster/sharding/typed/internal/ShardedDaemonProcessImpl.scala +++ b/akka-cluster-sharding-typed/src/main/scala/akka/cluster/sharding/typed/internal/ShardedDaemonProcessImpl.scala @@ -93,9 +93,12 @@ private[akka] final class ShardedDaemonProcessImpl(system: ActorSystem[_]) import ShardedDaemonProcessImpl._ def init[T](name: String, numberOfInstances: Int, behaviorFactory: Int => Behavior[T])( - implicit classTag: ClassTag[T]): Unit = { + implicit classTag: ClassTag[T]): Unit = init(name, numberOfInstances, behaviorFactory, ShardedDaemonProcessSettings(system), None)(classTag) - } + + override def init[T](name: String, numberOfInstances: Int, behaviorFactory: Int => Behavior[T], stopMessage: T)( + implicit classTag: ClassTag[T]): Unit = + init(name, numberOfInstances, behaviorFactory, ShardedDaemonProcessSettings(system), Some(stopMessage))(classTag) def init[T]( name: String, @@ -153,6 +156,7 @@ private[akka] final class ShardedDaemonProcessImpl(system: ActorSystem[_]) } } + // Java API def init[T]( messageClass: Class[T], name: String, @@ -160,6 +164,15 @@ private[akka] final class ShardedDaemonProcessImpl(system: ActorSystem[_]) behaviorFactory: function.Function[Integer, Behavior[T]]): Unit = init(name, numberOfInstances, n => behaviorFactory(n))(ClassTag(messageClass)) + override def init[T]( + messageClass: Class[T], + name: String, + numberOfInstances: Int, + behaviorFactory: function.Function[Int, Behavior[T]], + stopMessage: T): Unit = + init(name, numberOfInstances, n => behaviorFactory(n), ShardedDaemonProcessSettings(system), Some(stopMessage))( + ClassTag(messageClass)) + def init[T]( messageClass: Class[T], name: String, diff --git a/akka-cluster-sharding-typed/src/main/scala/akka/cluster/sharding/typed/javadsl/ShardedDaemonProcess.scala b/akka-cluster-sharding-typed/src/main/scala/akka/cluster/sharding/typed/javadsl/ShardedDaemonProcess.scala index fbef1bba26..cfead91abf 100644 --- a/akka-cluster-sharding-typed/src/main/scala/akka/cluster/sharding/typed/javadsl/ShardedDaemonProcess.scala +++ b/akka-cluster-sharding-typed/src/main/scala/akka/cluster/sharding/typed/javadsl/ShardedDaemonProcess.scala @@ -45,6 +45,20 @@ abstract class ShardedDaemonProcess { numberOfInstances: Int, behaviorFactory: function.Function[Integer, Behavior[T]]): Unit + /** + * Start a specific number of actors that is then kept alive in the cluster. + * + * @param behaviorFactory Given a unique id of `0` until `numberOfInstance` create the behavior for that actor. + * @param stopMessage sent to the actors when they need to stop because of a rebalance across the nodes of the cluster + * or cluster shutdown. + */ + def init[T]( + messageClass: Class[T], + name: String, + numberOfInstances: Int, + behaviorFactory: function.Function[Int, Behavior[T]], + stopMessage: T): Unit + /** * Start a specific number of actors, each with a unique numeric id in the set, that is then kept alive in the cluster. * @param behaviorFactory Given a unique id of `0` until `numberOfInstance` create the behavior for that actor. diff --git a/akka-cluster-sharding-typed/src/main/scala/akka/cluster/sharding/typed/scaladsl/ShardedDaemonProcess.scala b/akka-cluster-sharding-typed/src/main/scala/akka/cluster/sharding/typed/scaladsl/ShardedDaemonProcess.scala index 9e655f7c1b..1fde851f2e 100644 --- a/akka-cluster-sharding-typed/src/main/scala/akka/cluster/sharding/typed/scaladsl/ShardedDaemonProcess.scala +++ b/akka-cluster-sharding-typed/src/main/scala/akka/cluster/sharding/typed/scaladsl/ShardedDaemonProcess.scala @@ -45,6 +45,16 @@ trait ShardedDaemonProcess extends Extension { javadslSelf: javadsl.ShardedDaemo def init[T](name: String, numberOfInstances: Int, behaviorFactory: Int => Behavior[T])( implicit classTag: ClassTag[T]): Unit + /** + * Start a specific number of actors that is then kept alive in the cluster. + * + * @param behaviorFactory Given a unique id of `0` until `numberOfInstance` create the behavior for that actor. + * @param stopMessage sent to the actors when they need to stop because of a rebalance across the nodes of the cluster + * or cluster shutdown. + */ + def init[T](name: String, numberOfInstances: Int, behaviorFactory: Int => Behavior[T], stopMessage: T)( + implicit classTag: ClassTag[T]): Unit + /** * Start a specific number of actors, each with a unique numeric id in the set, that is then kept alive in the cluster. * @param behaviorFactory Given a unique id of `0` until `numberOfInstance` create the behavior for that actor. From 8c1d1832ca30fc8ae2b44ad145c2a8efbd75dd7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Andr=C3=A9n?= Date: Thu, 4 Jun 2020 17:49:10 +0200 Subject: [PATCH 2/2] =?UTF-8?q?All=20I=20want=20to=20do,=20is=20make=20MiM?= =?UTF-8?q?a=20happy=20=F0=9F=8E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../daemon-process-init-overloads.excludes | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 akka-cluster-sharding-typed/src/main/mima-filters/2.6.5.backwards.excludes/daemon-process-init-overloads.excludes diff --git a/akka-cluster-sharding-typed/src/main/mima-filters/2.6.5.backwards.excludes/daemon-process-init-overloads.excludes b/akka-cluster-sharding-typed/src/main/mima-filters/2.6.5.backwards.excludes/daemon-process-init-overloads.excludes new file mode 100644 index 0000000000..5b607dd7f1 --- /dev/null +++ b/akka-cluster-sharding-typed/src/main/mima-filters/2.6.5.backwards.excludes/daemon-process-init-overloads.excludes @@ -0,0 +1,3 @@ +# Non-settings stop message overload for Sharded Daemon Process #29081 +ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.cluster.sharding.typed.scaladsl.ShardedDaemonProcess.init") +ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.cluster.sharding.typed.javadsl.ShardedDaemonProcess.init") \ No newline at end of file