Class TokenEntry
java.lang.Object
org.axonframework.messaging.eventhandling.processing.streaming.token.store.jpa.TokenEntry
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classPrimary key for token entries used by JPA. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefault constructor for JPA.TokenEntry(String processorName, Segment segment, TrackingToken token, Converter converter) Initializes a new token entry for giventoken,processorNameandsegment. -
Method Summary
Modifier and TypeMethodDescriptionbooleanclaim(String owner, TemporalAmount claimTimeout) Attempt to claim ownership of this token.static StringComputes a token timestamp.getOwner()Returns the identifier of the process (JVM) having a claim on this token, ornullif the token isn't claimed.Returns the name of theStreamingEventProcessorto which this token belongs.Returns the segment of this token.Returns the token, deserializing it with givenserializerbooleanmayClaim(String owner, TemporalAmount claimTimeout) Check if givenownermay claim this token.booleanreleaseClaim(String owner) Release any claim of ownership currently active on this Token, if owned by the givenowner.Returns the storage timestamp of this token entry.Returns the storage timestamp of this token entry as a String.voidupdateToken(TrackingToken token, Converter converter) Updates a token, using the provided token and serializer to update the serialized token and token type.
-
Field Details
-
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 giventoken,processorNameandsegment. The givenconverteris 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
Computes a token timestamp.- Returns:
- A token timestamp.
-
getToken
Returns the token, deserializing it with givenserializer- Parameters:
converter- The converter to deserialize the token with.- Returns:
- The deserialized token stored in this entry.
-
claim
Attempt to claim ownership of this token. When successful, this method returnstrue, otherwisefalse. 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:
trueif the claim succeeded, otherwise false.
-
mayClaim
Check if givenownermay 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:
trueif the claim may be made,falseotherwise.
-
releaseClaim
Release any claim of ownership currently active on this Token, if owned by the givenowner.- Parameters:
owner- The name of the current node, which was registered as the owner.- Returns:
trueof the claim was successfully released, orfalseif the token has been claimed by another owner.
-
timestampAsString
Returns the storage timestamp of this token entry as a String.- Returns:
- The storage timestamp as string.
-
timestamp
Returns the storage timestamp of this token entry.- Returns:
- The storage timestamp.
-
updateToken
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 staticClock.- Parameters:
token- The new token that needs to be persisted.converter- The converter that will be used to serialize the token.
-
getOwner
Returns the identifier of the process (JVM) having a claim on this token, ornullif the token isn't claimed.- Returns:
- The process (JVM) that claimed this token.
-
getProcessorName
Returns the name of theStreamingEventProcessorto which this token belongs.- Returns:
- The name of the
StreamingEventProcessorto which this token belongs.
-
getSegment
Returns the segment of this token.- Returns:
- The segment of this token.
-