remove PersistentBehaviors.persistentEntity
This commit is contained in:
parent
4330e4446e
commit
f995a7d009
3 changed files with 11 additions and 22 deletions
|
|
@ -241,6 +241,7 @@ final class ClusterShardingSettings(
|
||||||
s"valid values are '${StateStoreModeDData.name}' or '${StateStoreModePersistence.name}'")
|
s"valid values are '${StateStoreModeDData.name}' or '${StateStoreModePersistence.name}'")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* INTERNAL API
|
||||||
* If true, this node should run the shard region, otherwise just a shard proxy should started on this node.
|
* If true, this node should run the shard region, otherwise just a shard proxy should started on this node.
|
||||||
* It's checking if the `role` and `dataCenter` are matching.
|
* It's checking if the `role` and `dataCenter` are matching.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -44,14 +44,14 @@ object ClusterShardingPersistenceSpec {
|
||||||
|
|
||||||
import PersistentBehaviors._
|
import PersistentBehaviors._
|
||||||
|
|
||||||
val persistentActor: Behavior[Command] =
|
def persistentActor(entityId: String): Behavior[Command] =
|
||||||
PersistentBehaviors.persistentEntity[Command, String, String](
|
PersistentBehaviors.immutable[Command, String, String](
|
||||||
persistenceIdFromActorName = name ⇒ "Test-" + name,
|
entityId,
|
||||||
initialState = "",
|
initialState = "",
|
||||||
commandHandler = (_, state, cmd) ⇒ cmd match {
|
commandHandler = (_, state, cmd) ⇒ cmd match {
|
||||||
case Add(s) ⇒ Effect.persist(s)
|
case Add(s) ⇒ Effect.persist(s)
|
||||||
case Get(replyTo) ⇒
|
case Get(replyTo) ⇒
|
||||||
replyTo ! state
|
replyTo ! s"$entityId:$state"
|
||||||
Effect.none
|
Effect.none
|
||||||
case StopPlz ⇒ Effect.stop
|
case StopPlz ⇒ Effect.stop
|
||||||
},
|
},
|
||||||
|
|
@ -72,7 +72,7 @@ class ClusterShardingPersistenceSpec extends TestKit("ClusterShardingPersistence
|
||||||
Cluster(system).manager ! Join(Cluster(system).selfMember.address)
|
Cluster(system).manager ! Join(Cluster(system).selfMember.address)
|
||||||
|
|
||||||
"start persistent actor" in {
|
"start persistent actor" in {
|
||||||
ClusterSharding(system).spawn[Command](_ ⇒ persistentActor, Props.empty, typeKey,
|
ClusterSharding(system).spawn[Command](persistentActor, Props.empty, typeKey,
|
||||||
ClusterShardingSettings(system), maxNumberOfShards = 100, handOffStopMessage = StopPlz)
|
ClusterShardingSettings(system), maxNumberOfShards = 100, handOffStopMessage = StopPlz)
|
||||||
|
|
||||||
val p = TestProbe[String]()
|
val p = TestProbe[String]()
|
||||||
|
|
@ -82,7 +82,7 @@ class ClusterShardingPersistenceSpec extends TestKit("ClusterShardingPersistence
|
||||||
ref ! Add("b")
|
ref ! Add("b")
|
||||||
ref ! Add("c")
|
ref ! Add("c")
|
||||||
ref ! Get(p.ref)
|
ref ! Get(p.ref)
|
||||||
p.expectMessage("a|b|c")
|
p.expectMessage("123:a|b|c")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,25 +19,13 @@ object PersistentBehaviors {
|
||||||
persistenceId: String,
|
persistenceId: String,
|
||||||
initialState: State,
|
initialState: State,
|
||||||
commandHandler: CommandHandler[Command, Event, State],
|
commandHandler: CommandHandler[Command, Event, State],
|
||||||
eventHandler: (State, Event) ⇒ State): PersistentBehavior[Command, Event, State] =
|
eventHandler: (State, Event) ⇒ State): PersistentBehavior[Command, Event, State] = {
|
||||||
persistentEntity(_ ⇒ persistenceId, initialState, commandHandler, eventHandler)
|
// FIXME remove `persistenceIdFromActorName: String ⇒ String` from PersistentBehavior
|
||||||
|
new PersistentBehavior(_ ⇒ persistenceId, initialState, commandHandler, eventHandler,
|
||||||
/**
|
|
||||||
* Create a `Behavior` for a persistent actor in Cluster Sharding, when the persistenceId is not known
|
|
||||||
* until the actor is started and typically based on the entityId, which
|
|
||||||
* is the actor name.
|
|
||||||
*
|
|
||||||
* TODO This will not be needed when it can be wrapped in `Actor.deferred`.
|
|
||||||
*/
|
|
||||||
def persistentEntity[Command, Event, State](
|
|
||||||
persistenceIdFromActorName: String ⇒ String,
|
|
||||||
initialState: State,
|
|
||||||
commandHandler: CommandHandler[Command, Event, State],
|
|
||||||
eventHandler: (State, Event) ⇒ State): PersistentBehavior[Command, Event, State] =
|
|
||||||
new PersistentBehavior(persistenceIdFromActorName, initialState, commandHandler, eventHandler,
|
|
||||||
recoveryCompleted = (_, _) ⇒ (),
|
recoveryCompleted = (_, _) ⇒ (),
|
||||||
tagger = _ ⇒ Set.empty,
|
tagger = _ ⇒ Set.empty,
|
||||||
snapshotOn = (_, _, _) ⇒ false)
|
snapshotOn = (_, _, _) ⇒ false)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factories for effects - how a persistent actor reacts on a command
|
* Factories for effects - how a persistent actor reacts on a command
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue