-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PersistentEntity to glue together Sharding and PersistentBehavior better
* Makes the combination more visable * You don't have to worry about the persistenceId, only EntityTypeKey and entityId * The glue is stronger in the javadsl because of two reasons * Couldn't realisticly create a PersistentEntity class extending PersistenBehavior (which contains all the optional parameters and functions) since that would duplicate too much. * The ActorContext would be needed in the ShardedEntityContext parameter and because of the additional M type parameters the type inference breaks down when using the factory. Would require specifying the type of the ShardedEntityContex[M] parameter. That problem doesn't seem to exist in Java. renamed: s/ShardedEntityContext/EntityContext/ s/ShardedEntity/Entity/
- Loading branch information
Showing
19 changed files
with
670 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...-sharding-typed/src/main/scala/akka/cluster/sharding/typed/javadsl/PersistentEntity.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright (C) 2018 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package akka.cluster.sharding.typed.javadsl | ||
|
||
import java.util.Optional | ||
|
||
import scala.compat.java8.OptionConverters._ | ||
|
||
import akka.actor.typed.BackoffSupervisorStrategy | ||
import akka.actor.typed.Behavior | ||
import akka.persistence.typed.PersistenceId | ||
import akka.persistence.typed.javadsl.PersistentBehavior | ||
|
||
/** | ||
* Any [[Behavior]] can be used as a sharded entity actor, but the combination of sharding and persistent | ||
* actors is very common and therefore this `PersistentEntity` class is provided as convenience. | ||
* | ||
* It is a [[PersistentBehavior]] and is implemented in the same way. It selects the `persistenceId` | ||
* automatically from the [[EntityTypeKey]] and `entityId` constructor parameters by using | ||
* [[EntityTypeKey.persistenceIdFrom]]. | ||
*/ | ||
abstract class PersistentEntity[Command, Event, State >: Null] private ( | ||
val entityTypeKey: EntityTypeKey[Command], | ||
persistenceId: PersistenceId, supervisorStrategy: Optional[BackoffSupervisorStrategy]) | ||
extends PersistentBehavior[Command, Event, State](persistenceId, supervisorStrategy) { | ||
|
||
def this(entityTypeKey: EntityTypeKey[Command], entityId: String) = { | ||
this(entityTypeKey, persistenceId = entityTypeKey.persistenceIdFrom(entityId), Optional.empty[BackoffSupervisorStrategy]) | ||
} | ||
|
||
def this(entityTypeKey: EntityTypeKey[Command], entityId: String, backoffSupervisorStrategy: BackoffSupervisorStrategy) = { | ||
this(entityTypeKey, persistenceId = entityTypeKey.persistenceIdFrom(entityId), Optional.ofNullable(backoffSupervisorStrategy)) | ||
} | ||
|
||
} |
Oops, something went wrong.