remove PersistentBehaviors.persistentEntity

This commit is contained in:
Patrik Nordwall 2018-02-02 14:17:19 +01:00
parent 4330e4446e
commit f995a7d009
3 changed files with 11 additions and 22 deletions

View file

@ -241,6 +241,7 @@ final class ClusterShardingSettings(
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.
* It's checking if the `role` and `dataCenter` are matching.
*/

View file

@ -44,14 +44,14 @@ object ClusterShardingPersistenceSpec {
import PersistentBehaviors._
val persistentActor: Behavior[Command] =
PersistentBehaviors.persistentEntity[Command, String, String](
persistenceIdFromActorName = name "Test-" + name,
def persistentActor(entityId: String): Behavior[Command] =
PersistentBehaviors.immutable[Command, String, String](
entityId,
initialState = "",
commandHandler = (_, state, cmd) cmd match {
case Add(s) Effect.persist(s)
case Get(replyTo)
replyTo ! state
replyTo ! s"$entityId:$state"
Effect.none
case StopPlz Effect.stop
},
@ -72,7 +72,7 @@ class ClusterShardingPersistenceSpec extends TestKit("ClusterShardingPersistence
Cluster(system).manager ! Join(Cluster(system).selfMember.address)
"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)
val p = TestProbe[String]()
@ -82,7 +82,7 @@ class ClusterShardingPersistenceSpec extends TestKit("ClusterShardingPersistence
ref ! Add("b")
ref ! Add("c")
ref ! Get(p.ref)
p.expectMessage("a|b|c")
p.expectMessage("123:a|b|c")
}
}
}

View file

@ -19,25 +19,13 @@ object PersistentBehaviors {
persistenceId: String,
initialState: State,
commandHandler: CommandHandler[Command, Event, State],
eventHandler: (State, Event) State): PersistentBehavior[Command, Event, State] =
persistentEntity(_ 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,
eventHandler: (State, Event) State): PersistentBehavior[Command, Event, State] = {
// FIXME remove `persistenceIdFromActorName: String ⇒ String` from PersistentBehavior
new PersistentBehavior(_ persistenceId, initialState, commandHandler, eventHandler,
recoveryCompleted = (_, _) (),
tagger = _ Set.empty,
snapshotOn = (_, _, _) false)
}
/**
* Factories for effects - how a persistent actor reacts on a command