java.lang.Object
org.axonframework.eventhandling.tokenstore.jpa.TokenEntry

@Entity @Entity public class TokenEntry extends Object
Implementation of a token entry compatible with JPA that stores its serialized token as a byte array.
Author:
Rene de Waele, Allard Buijze
  • Field Details

    • clock

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

    • TokenEntry

      public TokenEntry(String processorName, int segment, TrackingToken token, Serializer serializer)
      Initializes a new token entry for given token, processorName and segment. The given serializer can be used to serialize the token before it is stored.
      Parameters:
      processorName - The name of the processor to store this token for
      segment - The segment index of the processor
      token - The tracking token to store
      serializer - The serializer to use when storing a serialized token
    • TokenEntry

      protected TokenEntry()
      Default constructor for JPA
  • Method Details

    • getSerializedToken

      public SerializedObject<byte[]> 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
    • 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.
    • timestampAsString

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

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

      public void updateToken(TrackingToken token, Serializer serializer)
      Updates a token, using the provided token and serializer to update the serialized token and token type. It will also update the timestamp to the current time, using the inhirited static Clock.
      Parameters:
      token - The new token that needs to be persisted
      serializer - The serializer that will be used to serialize the token
    • 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
    • getProcessorName

      public String getProcessorName()
    • getSegment

      public int getSegment()