Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename PersistentBehaviors.receive to PersistentBehavior.apply #25696

Merged
merged 1 commit into from
Oct 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import akka.actor.typed.Props
import akka.cluster.sharding.typed.ClusterShardingSettings
import akka.cluster.typed.Cluster
import akka.cluster.typed.Join
import akka.persistence.typed.scaladsl.{ Effect, PersistentBehaviors }
import akka.persistence.typed.scaladsl.{ Effect, PersistentBehavior }
import akka.actor.testkit.typed.scaladsl.TestProbe
import com.typesafe.config.ConfigFactory
import org.scalatest.{ WordSpec, WordSpecLike }
Expand Down Expand Up @@ -44,7 +44,7 @@ object ClusterShardingPersistenceSpec {
final case object StopPlz extends Command

def persistentActor(entityId: String): Behavior[Command] =
PersistentBehaviors.receive[Command, String, String](
PersistentBehavior[Command, String, String](
entityId,
emptyState = "",
commandHandler = (state, cmd) ⇒ cmd match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package akka.cluster.typed

import akka.actor.testkit.typed.scaladsl.ScalaTestWithActorTestKit
import akka.actor.typed.{ ActorRef, Behavior, Props }
import akka.persistence.typed.scaladsl.{ Effect, PersistentBehaviors }
import akka.persistence.typed.scaladsl.{ Effect, PersistentBehavior }
import akka.actor.testkit.typed.scaladsl.TestProbe
import com.typesafe.config.ConfigFactory
import org.scalatest.WordSpecLike
Expand Down Expand Up @@ -36,7 +36,7 @@ object ClusterSingletonPersistenceSpec {
private final case object StopPlz extends Command

val persistentActor: Behavior[Command] =
PersistentBehaviors.receive[Command, String, String](
PersistentBehavior[Command, String, String](
persistenceId = "TheSingleton",
emptyState = "",
commandHandler = (state, cmd) ⇒ cmd match {
Expand Down
26 changes: 13 additions & 13 deletions akka-docs/src/main/paradox/typed/persistence.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ This module is currently marked as @ref:[may change](../common/may-change.md) in
Let's start with a simple example. The minimum required for a `PersistentBehavior` is:

Scala
: @@snip [BasicPersistentBehaviorsCompileOnly.scala](/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentBehaviorsCompileOnly.scala) { #structure }
: @@snip [BasicPersistentBehaviorCompileOnly.scala](/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentBehaviorCompileOnly.scala) { #structure }

Java
: @@snip [BasicPersistentBehaviorsTest.java](/akka-persistence-typed/src/test/java/jdocs/akka/persistence/typed/BasicPersistentBehaviorsTest.java) { #structure }
: @@snip [BasicPersistentBehaviorTest.java](/akka-persistence-typed/src/test/java/jdocs/akka/persistence/typed/BasicPersistentBehaviorTest.java) { #structure }

The first important thing to notice is the `Behavior` of a persistent actor is typed to the type of the `Command`
because this is the type of message a persistent actor should receive. In Akka Typed this is now enforced by the type system.
Expand Down Expand Up @@ -212,7 +212,7 @@ Scala
Java
: @@snip [InDepthPersistentBehaviorTest.java](/akka-persistence-typed/src/test/java/jdocs/akka/persistence/typed/InDepthPersistentBehaviorTest.java) { #event-handler }

And finally the behavior is created @scala[from the `PersistentBehaviors.receive`]:
And finally the behavior is created @scala[from the `PersistentBehavior.apply`]:

Scala
: @@snip [InDepthPersistentBehaviorSpec.scala](/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/InDepthPersistentBehaviorSpec.scala) { #behavior }
Expand All @@ -238,10 +238,10 @@ Most of them time this will be done with the `thenRun` method on the `Effect` ab
factor out common `SideEffect`s. For example:

Scala
: @@snip [BasicPersistentBehaviorsCompileOnly.scala](/akka-persistence-typed/src/test/scala/akka/persistence/typed/scaladsl/PersistentActorCompileOnlyTest.scala) { #commonChainedEffects }
: @@snip [BasicPersistentBehaviorCompileOnly.scala](/akka-persistence-typed/src/test/scala/akka/persistence/typed/scaladsl/PersistentActorCompileOnlyTest.scala) { #commonChainedEffects }

Java
: @@snip [BasicPersistentBehaviorsCompileOnly.scala](/akka-persistence-typed/src/test/java/akka/persistence/typed/javadsl/PersistentActorCompileOnlyTest.java) { #commonChainedEffects }
: @@snip [BasicPersistentBehaviorCompileOnly.scala](/akka-persistence-typed/src/test/java/akka/persistence/typed/javadsl/PersistentActorCompileOnlyTest.java) { #commonChainedEffects }

### Side effects ordering and guarantees

Expand All @@ -261,10 +261,10 @@ It is strongly discouraged to perform side effects in `applyEvent`,
so side effects should be performed once recovery has completed @scala[in the `onRecoveryCompleted` callback.] @java[by overriding `onRecoveryCompleted`]

Scala
: @@snip [BasicPersistentBehaviorsCompileOnly.scala](/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentBehaviorsCompileOnly.scala) { #recovery }
: @@snip [BasicPersistentBehaviorCompileOnly.scala](/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentBehaviorCompileOnly.scala) { #recovery }

Java
: @@snip [BasicPersistentBehaviorsTest.java](/akka-persistence-typed/src/test/java/jdocs/akka/persistence/typed/BasicPersistentBehaviorsTest.java) { #recovery }
: @@snip [BasicPersistentBehaviorTest.java](/akka-persistence-typed/src/test/java/jdocs/akka/persistence/typed/BasicPersistentBehaviorTest.java) { #recovery }

The `onRecoveryCompleted` takes @scala[an `ActorContext` and] the current `State`,
and doesn't return anything.
Expand All @@ -274,10 +274,10 @@ and doesn't return anything.
Persistence typed allows you to use event tags without using @ref[`EventAdapter`](../persistence.md#event-adapters):

Scala
: @@snip [BasicPersistentActorCompileOnly.scala](/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentBehaviorsCompileOnly.scala) { #tagging }
: @@snip [BasicPersistentActorCompileOnly.scala](/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentBehaviorCompileOnly.scala) { #tagging }

Java
: @@snip [BasicPersistentBehaviorsTest.java](/akka-persistence-typed/src/test/java/jdocs/akka/persistence/typed/BasicPersistentBehaviorsTest.java) { #tagging }
: @@snip [BasicPersistentBehaviorTest.java](/akka-persistence-typed/src/test/java/jdocs/akka/persistence/typed/BasicPersistentBehaviorTest.java) { #tagging }

## Event adapters

Expand Down Expand Up @@ -307,10 +307,10 @@ other behaviors such as `Behaviors.setup` in order to access the `ActorContext`
to access the actor logging upon taking snapshots for debug purpose.

Scala
: @@snip [BasicPersistentActorCompileOnly.scala](/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentBehaviorsCompileOnly.scala) { #wrapPersistentBehavior }
: @@snip [BasicPersistentActorCompileOnly.scala](/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentBehaviorCompileOnly.scala) { #wrapPersistentBehavior }

Java
: @@snip [BasicPersistentBehaviorsTest.java](/akka-persistence-typed/src/test/java/jdocs/akka/persistence/typed/BasicPersistentBehaviorsTest.java) { #wrapPersistentBehavior }
: @@snip [BasicPersistentBehaviorTest.java](/akka-persistence-typed/src/test/java/jdocs/akka/persistence/typed/BasicPersistentBehaviorTest.java) { #wrapPersistentBehavior }


## Journal failures
Expand All @@ -321,10 +321,10 @@ any `BackoffSupervisorStrategy`. It is not possible to use the normal supervisio


Scala
: @@snip [BasicPersistentBehaviorsSpec.scala](/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentBehaviorsCompileOnly.scala) { #supervision }
: @@snip [BasicPersistentBehaviorSpec.scala](/akka-persistence-typed/src/test/scala/docs/akka/persistence/typed/BasicPersistentBehaviorCompileOnly.scala) { #supervision }

Java
: @@snip [BasicPersistentBehaviorsTest.java](/akka-persistence-typed/src/test/java/jdocs/akka/persistence/typed/BasicPersistentBehaviorsTest.java) { #supervision }
: @@snip [BasicPersistentBehaviorTest.java](/akka-persistence-typed/src/test/java/jdocs/akka/persistence/typed/BasicPersistentBehaviorTest.java) { #supervision }

## Journal rejections

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import akka.persistence._
import akka.persistence.typed.EventAdapter
import akka.persistence.typed.internal.EventsourcedBehavior.MDC
import akka.persistence.typed.internal.EventsourcedBehavior.{ InternalProtocol, WriterIdentity }
import akka.persistence.typed.scaladsl.PersistentBehaviors
import akka.persistence.typed.scaladsl.PersistentBehavior
import akka.util.Collections.EmptyImmutableSeq
import akka.util.OptionVal
import scala.util.Try
Expand All @@ -31,8 +31,8 @@ private[persistence] final class EventsourcedSetup[C, E, S](
val context: ActorContext[InternalProtocol],
val persistenceId: String,
val emptyState: S,
val commandHandler: PersistentBehaviors.CommandHandler[C, E, S],
val eventHandler: PersistentBehaviors.EventHandler[S, E],
val commandHandler: PersistentBehavior.CommandHandler[C, E, S],
val eventHandler: PersistentBehavior.EventHandler[S, E],
val writerIdentity: WriterIdentity,
val recoveryCompleted: S ⇒ Unit,
val onSnapshot: (SnapshotMetadata, Try[Done]) ⇒ Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ private[akka] object PersistentBehaviorImpl {
private[akka] final case class PersistentBehaviorImpl[Command, Event, State](
persistenceId: String,
emptyState: State,
commandHandler: PersistentBehaviors.CommandHandler[Command, Event, State],
eventHandler: PersistentBehaviors.EventHandler[State, Event],
journalPluginId: Option[String] = None,
snapshotPluginId: Option[String] = None,
recoveryCompleted: State ⇒ Unit = ConstantFun.scalaAnyToUnit,
tagger: Event ⇒ Set[String] = (_: Event) ⇒ Set.empty[String],
eventAdapter: EventAdapter[Event, Any] = NoOpEventAdapter.instance[Event],
snapshotWhen: (State, Event, Long) ⇒ Boolean = ConstantFun.scalaAnyThreeToFalse,
recovery: Recovery = Recovery(),
supervisionStrategy: SupervisorStrategy = SupervisorStrategy.stop,
onSnapshot: (SnapshotMetadata, Try[Done]) ⇒ Unit = ConstantFun.scalaAnyTwoToUnit
commandHandler: PersistentBehavior.CommandHandler[Command, Event, State],
eventHandler: PersistentBehavior.EventHandler[State, Event],
journalPluginId: Option[String] = None,
snapshotPluginId: Option[String] = None,
recoveryCompleted: State ⇒ Unit = ConstantFun.scalaAnyToUnit,
tagger: Event ⇒ Set[String] = (_: Event) ⇒ Set.empty[String],
eventAdapter: EventAdapter[Event, Any] = NoOpEventAdapter.instance[Event],
snapshotWhen: (State, Event, Long) ⇒ Boolean = ConstantFun.scalaAnyThreeToFalse,
recovery: Recovery = Recovery(),
supervisionStrategy: SupervisorStrategy = SupervisorStrategy.stop,
onSnapshot: (SnapshotMetadata, Try[Done]) ⇒ Unit = ConstantFun.scalaAnyTwoToUnit
) extends PersistentBehavior[Command, Event, State] with EventsourcedStashReferenceManagement {

override def apply(context: typed.ActorContext[Command]): Behavior[Command] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ abstract class PersistentBehavior[Command, Event, State >: Null] private (val pe
else tags.asScala.toSet
}

val behavior = scaladsl.PersistentBehaviors.receive[Command, Event, State](
val behavior = scaladsl.PersistentBehavior[Command, Event, State](
persistenceId,
emptyState,
(state, cmd) ⇒ commandHandler()(state, cmd).asInstanceOf[EffectImpl[Event, State]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import akka.persistence.typed.internal._

import scala.util.Try

object PersistentBehaviors {
object PersistentBehavior {

/**
* Type alias for the command handler function for reacting on events having been persisted.
Expand All @@ -37,7 +37,7 @@ object PersistentBehaviors {
/**
* Create a `Behavior` for a persistent actor.
*/
def receive[Command, Event, State](
def apply[Command, Event, State](
persistenceId: String,
emptyState: State,
commandHandler: (State, Command) ⇒ Effect[Event, State],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.Collections;
import java.util.Set;

public class BasicPersistentBehaviorsTest {
public class BasicPersistentBehaviorTest {

//#structure
public interface Command {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package akka.persistence.typed

import akka.actor.typed.scaladsl.Behaviors
import akka.actor.typed.scaladsl.adapter.TypedActorSystemOps
import akka.persistence.typed.scaladsl.PersistentBehaviors.CommandHandler
import akka.persistence.typed.scaladsl.{ Effect, PersistentBehavior, PersistentBehaviors }
import akka.persistence.typed.scaladsl.PersistentBehavior.CommandHandler
import akka.persistence.typed.scaladsl.{ Effect, PersistentBehavior }
import akka.testkit.TestLatch
import akka.actor.testkit.typed.scaladsl.TestProbe

Expand All @@ -26,7 +26,7 @@ object ManyRecoveriesSpec {
name: String,
probe: TestProbe[String],
latch: Option[TestLatch]): PersistentBehavior[Cmd, Evt, String] =
PersistentBehaviors.receive[Cmd, Evt, String](
PersistentBehavior[Cmd, Evt, String](
persistenceId = name,
emptyState = "",
commandHandler = CommandHandler.command {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import akka.actor.typed.scaladsl.adapter.{ TypedActorRefOps, TypedActorSystemOps
import akka.actor.typed.{ ActorRef, Behavior }
import akka.persistence.Persistence
import akka.persistence.RecoveryPermitter.{ RecoveryPermitGranted, RequestRecoveryPermit, ReturnRecoveryPermit }
import akka.persistence.typed.scaladsl.PersistentBehaviors.CommandHandler
import akka.persistence.typed.scaladsl.{ Effect, PersistentBehaviors }
import akka.persistence.typed.scaladsl.PersistentBehavior.CommandHandler
import akka.persistence.typed.scaladsl.{ Effect, PersistentBehavior }
import akka.testkit.EventFilter

import scala.concurrent.duration._
Expand Down Expand Up @@ -43,7 +43,7 @@ object RecoveryPermitterSpec {
commandProbe: TestProbe[Any],
eventProbe: TestProbe[Any],
throwOnRecovery: Boolean = false): Behavior[Command] =
PersistentBehaviors.receive[Command, Event, State](
PersistentBehavior[Command, Event, State](
persistenceId = name,
emptyState = EmptyState,
commandHandler = CommandHandler.command {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.util.UUID
import akka.actor.testkit.typed.scaladsl.ScalaTestWithActorTestKit
import akka.actor.typed.scaladsl.adapter.{ TypedActorRefOps, TypedActorSystemOps }
import akka.event.Logging
import akka.persistence.typed.scaladsl.PersistentBehaviors.CommandHandler
import akka.persistence.typed.scaladsl.PersistentBehavior.CommandHandler
import akka.actor.testkit.typed.scaladsl.TestProbe
import org.scalatest.WordSpecLike

Expand All @@ -26,7 +26,7 @@ object OptionalSnapshotStoreSpec {
def persistentBehavior(
probe: TestProbe[State],
name: String = UUID.randomUUID().toString) =
PersistentBehaviors.receive[Command, Event, State](
PersistentBehavior[Command, Event, State](
persistenceId = name,
emptyState = State(),
commandHandler = CommandHandler.command {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.util.UUID

import akka.actor.typed.scaladsl.Behaviors
import akka.actor.typed.{ ActorRef, SupervisorStrategy }
import akka.persistence.typed.scaladsl.PersistentBehaviors.CommandHandler
import akka.persistence.typed.scaladsl.PersistentBehavior.CommandHandler
import akka.actor.testkit.typed.TE
import akka.actor.testkit.typed.scaladsl.TestProbe
import com.typesafe.config.ConfigFactory
Expand Down Expand Up @@ -61,7 +61,7 @@ object PerformanceSpec {
def behavior(name: String, probe: TestProbe[Command])(other: (Command, Parameters) ⇒ Effect[String, String]) = {
Behaviors.supervise({
val parameters = Parameters()
PersistentBehaviors.receive[Command, String, String](
PersistentBehavior[Command, String, String](
persistenceId = name,
"",
commandHandler = CommandHandler.command {
Expand Down
Loading