java.lang.Object
org.axonframework.messaging.eventhandling.processing.streaming.token.store.jpa.TokenEntry

@Entity public class TokenEntry extends Object
Implementation of a token entry compatible with JPA that stores its serialized token as a byte array.
Since:
3.0.0
Author:
Rene de Waele, Allard Buijze, Simon Zambrovski
  • 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(@Nonnull String processorName, @Nonnull Segment segment, @Nullable TrackingToken token, @Nonnull Converter converter)
      Initializes a new token entry for given token, processorName and segment. The given converter is used to serialize the token before it is stored.
      Parameters:
      processorName - The name of the processor to store this token for.
      segment - The segment of the processor.
      token - The tracking token to store.
      converter - The converter to use when storing a serialized token.
    • TokenEntry

      protected TokenEntry()
      Default constructor for JPA.
  • Method Details

    • computeTokenTimestamp

      public static String computeTokenTimestamp()
      Computes a token timestamp.
      Returns:
      A token timestamp.
    • getToken

      public TrackingToken getToken(@Nonnull Converter converter)
      Returns the token, deserializing it with given serializer
      Parameters:
      converter - The converter to deserialize the token with.
      Returns:
      The deserialized token stored in 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(@Nullable TrackingToken token, @Nonnull Converter converter)
      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 inherited static Clock.
      Parameters:
      token - The new token that needs to be persisted.
      converter - The converter 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()
      Returns the name of the StreamingEventProcessor to which this token belongs.
      Returns:
      The name of the StreamingEventProcessor to which this token belongs.
    • getSegment

      public Segment getSegment()
      Returns the segment of this token.
      Returns:
      The segment of this token.