java.lang.Object
org.axonframework.messaging.eventhandling.processing.streaming.token.store.jdbc.JdbcTokenEntry

public class JdbcTokenEntry extends Object
Jdbc class of an entry containing a serialized tracking token belonging to a given process. For use with Jakarta/Hibernate 6 use TokenEntry instead.
Since:
3.0.0
Author:
Rene de Waele, 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

    • JdbcTokenEntry

      public JdbcTokenEntry(@Nullable TrackingToken token, @Nonnull Converter converter)
      Initializes a new token entry for given token, process and segment. The given converter can be used to serialize the token before it is stored.
      Parameters:
      token - The tracking token to store.
      converter - The converter to use when storing a serialized token.
    • JdbcTokenEntry

      public JdbcTokenEntry(byte[] token, String tokenType, String timestamp, String owner, @Nonnull String processorName, @Nonnull Segment segment)
      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.
      processorName - The processor name.
      segment - The token segment.
    • JdbcTokenEntry

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

    • getToken

      public TrackingToken getToken(@Nonnull Converter converter)
      Returns the token, deserializing it with given converter.
      Parameters:
      converter - The converter to deserialize the token with.
      Returns:
      The deserialized token stored in 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.
    • 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.
    • 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.
    • getTokenData

      public byte[] getTokenData()
      Retrieves serialized value of the token.
      Returns:
      Returns token value as bytes.
    • getTokenType

      public String getTokenType()
      Retrieves token type.
      Returns:
      Returns token type.
    • 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.
    • updateToken

      public final void updateToken(@Nullable TrackingToken token, @Nonnull Converter converter)
      Update the token data to the given token, using given converter to serialize it to bytes[].
      Parameters:
      token - The token representing the state to update to.
      converter - The converter to update token to.