Class AbstractTokenEntry<T>

java.lang.Object
org.axonframework.eventhandling.tokenstore.AbstractTokenEntry<T>
Type Parameters:
T - The serialized data type of the token
Direct Known Subclasses:
GenericTokenEntry

@MappedSuperclass public abstract class AbstractTokenEntry<T> extends Object
Abstract base class of a JPA entry containing a serialized tracking token belonging to a given process. For use with Jakarta/Hibernate 6 use TokenEntry instead.
Author:
Rene de Waele
  • Field Details

    • clock

      public static Clock clock
      The clock used to persist timestamps in this entry. Defaults to UTC system time.
  • Constructor Details

    • AbstractTokenEntry

      protected AbstractTokenEntry(TrackingToken token, Serializer serializer, Class<T> contentType)
      Initializes a new token entry for given token, process and segment. The given serializer can be used to serialize the token before it is stored.
      Parameters:
      token - The tracking token to store
      serializer - The serializer to use when storing a serialized token
      contentType - The content type after serialization
    • AbstractTokenEntry

      protected AbstractTokenEntry(T token, String tokenType, String timestamp, String owner)
      Initializes a token entry from existing data.
      Parameters:
      token - the serialized token
      tokenType - the serialized type of the token
      timestamp - the timestamp of the token
      owner - the owner of the token
    • AbstractTokenEntry

      protected AbstractTokenEntry()
      Default constructor required for JPA
  • Method Details

    • getSerializedToken

      public SerializedObject<T> getSerializedToken()
      Returns the serialized token.
      Returns:
      the serialized token stored in this entry
    • getToken

      public TrackingToken getToken(Serializer serializer)
      Returns the token, deserializing it with given serializer
      Parameters:
      serializer - The serialize to deserialize the token with
      Returns:
      the deserialized token stored in this entry
    • getTokenType

      public SerializedType getTokenType()
      Returns the SerializedType of the serialized token, or null if no token is stored by this entry.
      Returns:
      the serialized type of the token, or null if no token is stored by this entry
    • timestamp

      public Instant timestamp()
      Returns the storage timestamp of this token entry.
      Returns:
      The storage timestamp
    • timestampAsString

      public String timestampAsString()
      Returns the storage timestamp of this token entry as a String.
      Returns:
      The storage timestamp as string
    • updateToken

      public abstract void updateToken(TrackingToken token, Serializer serializer)
      Update this entry with the given token, serializing it using given serializer.
      Parameters:
      token - The token to update the entry with
      serializer - The serializer to serialize data with
    • getProcessorName

      public abstract String getProcessorName()
      Returns the name of the process to which this token belongs.
      Returns:
      the process name
    • getSegment

      public abstract int getSegment()
      Returns the segment index of the process to which this token belongs.
      Returns:
      the segment index
    • claim

      public boolean claim(String owner, TemporalAmount claimTimeout)
      Attempt to claim ownership of this token. When successful, this method returns true, otherwise false. When a claim fails, this token should not be used, as it is already being used in another process.

      If a claim exists, but it is older than given claimTimeout, the claim may be 'stolen'.

      Parameters:
      owner - The name of the current node, to register as owner. This name must be unique for multiple instances of the same logical processor
      claimTimeout - The time after which a claim may be 'stolen' from its current owner
      Returns:
      true if the claim succeeded, otherwise false
    • mayClaim

      public boolean mayClaim(String owner, TemporalAmount claimTimeout)
      Check if given owner may claim this token.
      Parameters:
      owner - The name of the current node, to register as owner. This name must be unique for multiple instances of the same logical processor
      claimTimeout - The time after which a claim may be 'stolen' from its current owner
      Returns:
      true if the claim may be made, false otherwise
    • releaseClaim

      public boolean releaseClaim(String owner)
      Release any claim of ownership currently active on this Token, if owned by the given owner.
      Parameters:
      owner - The name of the current node, which was registered as the owner
      Returns:
      true of the claim was successfully released, or false if the token has been claimed by another owner.
    • getOwner

      public String getOwner()
      Returns the identifier of the process (JVM) having a claim on this token, or null if the token isn't claimed.
      Returns:
      the process (JVM) that claimed this token
    • updateToken

      protected final void updateToken(TrackingToken token, Serializer serializer, Class<T> contentType)
      Update the token data to the given token, using given serializer to serialize it to the given contentType.
      Parameters:
      token - The token representing the state to update to
      serializer - The serializer to update token to
      contentType - The type of data to represent the serialized data in