Class PersistenceId

java.lang.Object
org.apache.pekko.persistence.typed.PersistenceId

public final class PersistenceId extends Object
Unique identifier in the backend data store (journal and snapshot store) of the persistent actor.
  • Constructor Details

    • PersistenceId

      public PersistenceId()
  • Method Details

    • DefaultSeparator

      public static String DefaultSeparator()
      Default separator character used for concatenating a typeHint with entityId to construct unique persistenceId.
    • apply

      public static PersistenceId apply(String entityTypeHint, String entityId)
      Constructs a PersistenceId from the given entityTypeHint and entityId by concatenating them with | separator.

      Cluster Sharding is often used together with EventSourcedBehavior for the entities. The PersistenceId of the EventSourcedBehavior can typically be constructed with:

      
       PersistenceId(entityContext.entityTypeKey.name, entityContext.entityId)
       

      That format of the PersistenceId is not mandatory and only provided as a convenience of a "standardized" format.

      Another separator can be defined by using the apply that takes a separator parameter.

      Throws:
      IllegalArgumentException - if the entityTypeHint or entityId contains |
    • apply

      public static PersistenceId apply(String entityTypeHint, String entityId, String separator)
      Constructs a PersistenceId from the given entityTypeHint and entityId by concatenating them with the separator.

      Cluster Sharding is often used together with EventSourcedBehavior for the entities. The PersistenceId of the EventSourcedBehavior can typically be constructed with:

      
       PersistenceId(entityContext.entityTypeKey.name, entityContext.entityId)
       

      That format of the PersistenceId is not mandatory and only provided as a convenience of a "standardized" format.

      The default separator | is used by the apply that doesn't take a separator parameter.

      Throws:
      IllegalArgumentException - if the entityTypeHint or entityId contains separator
    • of

      public static PersistenceId of(String entityTypeHint, String entityId)
      Constructs a PersistenceId from the given entityTypeHint and entityId by concatenating them with | separator.

      Cluster Sharding is often used together with EventSourcedBehavior for the entities. The PersistenceId of the EventSourcedBehavior can typically be constructed with:

      
       PersistenceId.of(entityContext.getEntityTypeKey().name(), entityContext.getEntityId())
       

      That format of the PersistenceId is not mandatory and only provided as a convenience of a "standardized" format.

      Another separator can be defined by using the PersistenceId.of that takes a separator parameter.

      Throws:
      IllegalArgumentException - if the entityTypeHint or entityId contains |
    • of

      public static PersistenceId of(String entityTypeHint, String entityId, String separator)
      Constructs a PersistenceId from the given entityTypeHint and entityId by concatenating them with the separator.

      Cluster Sharding is often used together with EventSourcedBehavior for the entities. The PersistenceId of the EventSourcedBehavior can typically be constructed with:

      
       PersistenceId.of(entityContext.getEntityTypeKey().name(), entityContext.getEntityId())
       

      That format of the PersistenceId is not mandatory and only provided as a convenience of a "standardized" format.

      The default separator | is used by the apply that doesn't take a separator parameter.

      Throws:
      IllegalArgumentException - if the entityTypeHint or entityId contains separator
    • ofUniqueId

      public static PersistenceId ofUniqueId(String id)
      Constructs a PersistenceId with id as the full unique identifier.
    • extractEntityType

      public static String extractEntityType(String id)
      Extract the entityTypeHint from a persistence id String with the default separator |. If the separator | is not found it return the empty String ("").
    • extractEntityId

      public static String extractEntityId(String id)
      Extract the entityId from a persistence id String with the default separator |. If the separator | is not found it return the id.
    • unapply

      public static scala.Option<scala.Tuple2<String,String>> unapply(PersistenceId persistenceId)
    • id

      public String id()
    • entityTypeHint

      public String entityTypeHint()
    • entityId

      public String entityId()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object