Class TokenEntry
java.lang.Object
org.axonframework.eventhandling.tokenstore.jpa.TokenEntry
Implementation of a token entry compatible with JPA that stores its serialized token as a byte array.
- Author:
- Rene de Waele, Allard Buijze
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classPrimary key for token entries used by JPA -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefault constructor for JPATokenEntry(String processorName, int segment, TrackingToken token, Serializer serializer) Initializes a new token entry for giventoken,processorNameandsegment. -
Method Summary
Modifier and TypeMethodDescriptionbooleanclaim(String owner, TemporalAmount claimTimeout) Attempt to claim ownership of this token.getOwner()Returns the identifier of the process (JVM) having a claim on this token, ornullif the token isn't claimed.intSerializedObject<byte[]> Returns the serialized token.getToken(Serializer serializer) Returns the token, deserializing it with givenserializerReturns theSerializedTypeof the serialized token, ornullif no token is stored by this entry.booleanmayClaim(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, Serializer serializer) 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
Initializes a new token entry for giventoken,processorNameandsegment. The givenserializercan be used to serialize the token before it is stored.- Parameters:
processorName- The name of the processor to store this token forsegment- The segment index of the processortoken- The tracking token to storeserializer- The serializer to use when storing a serialized token
-
TokenEntry
protected TokenEntry()Default constructor for JPA
-
-
Method Details
-
getSerializedToken
Returns the serialized token.- Returns:
- the serialized token stored in this entry
-
getToken
Returns the token, deserializing it with givenserializer- Parameters:
serializer- The serialize to deserialize the token with- Returns:
- the deserialized token stored in this entry
-
getTokenType
Returns theSerializedTypeof the serialized token, ornullif no token is stored by this entry.- Returns:
- the serialized type of the token, or
nullif no token is stored by 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 processorclaimTimeout- 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 processorclaimTimeout- 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 inhirited staticClock.- Parameters:
token- The new token that needs to be persistedserializer- The serializer 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
-
getSegment
public int getSegment()
-