JpaTokenStore which moved to
jakarta.@Deprecated public class JpaTokenStore extends Object implements TokenStore
TokenEntry
entities.| Modifier and Type | Class and Description |
|---|---|
static class |
JpaTokenStore.Builder
Deprecated.
Builder class to instantiate a
JpaTokenStore. |
| Modifier | Constructor and Description |
|---|---|
protected |
JpaTokenStore(JpaTokenStore.Builder builder)
Deprecated.
Instantiate a
JpaTokenStore based on the fields contained in the JpaTokenStore.Builder. |
| Modifier and Type | Method and Description |
|---|---|
static JpaTokenStore.Builder |
builder()
Deprecated.
Instantiate a Builder to be able to create a
JpaTokenStore. |
void |
deleteToken(String processorName,
int segment)
Deprecated.
Deletes the token for the processor with given
processorName and segment. |
void |
extendClaim(String processorName,
int segment)
Deprecated.
Extends the claim on the current token held by the this node for the given
processorName and
segment. |
List<Segment> |
fetchAvailableSegments(String processorName)
Deprecated.
Returns a List of known available
segments for a given processorName. |
int[] |
fetchSegments(String processorName)
Deprecated.
Returns an array of known
segments for a given processorName. |
TrackingToken |
fetchToken(String processorName,
int segment)
Deprecated.
|
TrackingToken |
fetchToken(String processorName,
Segment segment)
Deprecated.
|
void |
initializeSegment(TrackingToken token,
String processorName,
int segment)
Deprecated.
Initializes a segment with given
segment for the processor with given processorName to contain
the given token. |
void |
initializeTokenSegments(String processorName,
int segmentCount)
Deprecated.
Initializes the given
segmentCount number of segments for the given processorName to track its
tokens. |
void |
initializeTokenSegments(String processorName,
int segmentCount,
TrackingToken initialToken)
Deprecated.
Initializes the given
segmentCount number of segments for the given processorName to track its
tokens. |
protected TokenEntry |
loadToken(String processorName,
int segment,
javax.persistence.EntityManager entityManager)
Deprecated.
Loads an existing
TokenEntry or creates a new one using the given entityManager for given
processorName and segment. |
protected TokenEntry |
loadToken(String processorName,
Segment segment,
javax.persistence.EntityManager entityManager)
Deprecated.
Tries loading an existing token owned by a processor with given
processorName and segment. |
void |
releaseClaim(String processorName,
int segment)
Deprecated.
Release a claim of the token for given
processorName and segment. |
boolean |
requiresExplicitSegmentInitialization()
Deprecated.
Indicates whether this TokenStore instance requires segments to be explicitly initialized, before any tokens
can be claimed for that segment.
|
Optional<String> |
retrieveStorageIdentifier()
Deprecated.
Returns a unique identifier that uniquely identifies the storage location of the tokens in this store.
|
Serializer |
serializer()
Deprecated.
Returns the serializer used by the Token Store to serialize tokens.
|
void |
storeToken(TrackingToken token,
String processorName,
int segment)
Deprecated.
Stores the given
token in the store. |
protected JpaTokenStore(JpaTokenStore.Builder builder)
JpaTokenStore based on the fields contained in the JpaTokenStore.Builder.
Will assert that the EntityManager, Serializer, claimTimeout and nodeId are not
null, and will throw an AxonConfigurationException if any of them is null.
builder - the JpaTokenStore.Builder used to instantiate a JpaTokenStore instancepublic static JpaTokenStore.Builder builder()
JpaTokenStore.
The claimTimeout to a 10 seconds duration, and nodeId is defaulted to the name of the managed
bean for the runtime system of the Java virtual machine. The EntityManagerProvider and Serializer
are a hard requirements and as such should be provided.
JpaTokenStorepublic void initializeTokenSegments(@Nonnull String processorName, int segmentCount) throws UnableToClaimTokenException
TokenStoresegmentCount number of segments for the given processorName to track its
tokens. This method should only be invoked when no tokens have been stored for the given processor, yet.
This method will initialize the tokens, but not claim them. It will create the segments ranging from 0
until segmentCount - 1.
The exact behavior when this method is called while tokens were already present, is undefined in case the token already present is not owned by the initializing process.
initializeTokenSegments in interface TokenStoreprocessorName - The name of the processor to initialize segments forsegmentCount - The number of segments to initializeUnableToClaimTokenException - when a segment has already been createdpublic void initializeTokenSegments(@Nonnull String processorName, int segmentCount, @Nullable TrackingToken initialToken) throws UnableToClaimTokenException
TokenStoresegmentCount number of segments for the given processorName to track its
tokens. This method should only be invoked when no tokens have been stored for the given processor, yet.
This method will store initialToken for all segments as starting point for processor, but not claim them.
It will create the segments ranging from 0 until segmentCount - 1.
The exact behavior when this method is called while tokens were already present, is undefined in case the token already present is not owned by the initializing process.
initializeTokenSegments in interface TokenStoreprocessorName - The name of the processor to initialize segments forsegmentCount - The number of segments to initializeinitialToken - The initial token which is used as a starting point for processorUnableToClaimTokenException - when a segment has already been createdpublic void storeToken(@Nullable TrackingToken token, @Nonnull String processorName, int segment)
TokenStoretoken in the store. The token marks the current position of the process with given
processorName and segment. The given token may be null.
Any claims made by the current process have their timestamp updated.
This method should throw an UnableToClaimTokenException when the given segment has not been
initialized with a Token (albeit null) yet. In that case, a segment must have been explicitly initialized.
A TokenStore implementation's ability to do so is exposed by the TokenStore.requiresExplicitSegmentInitialization()
method. If that method returns false, this method may implicitly initialize a token and return that token upon
invocation.
storeToken in interface TokenStoretoken - The token to store for a given process and segment. May be null.processorName - The name of the process for which to store the tokensegment - The index of the segment for which to store the tokenpublic void releaseClaim(@Nonnull String processorName, int segment)
TokenStoreprocessorName and segment. If no such claim existed,
nothing happens.
The caller must ensure not to use any streams opened based on the token for which the claim is released.
releaseClaim in interface TokenStoreprocessorName - The name of the process owning the token (e.g. a TrackingEventProcessor name)segment - the segment for which a token was obtainedpublic void initializeSegment(@Nullable TrackingToken token, @Nonnull String processorName, int segment) throws UnableToInitializeTokenException
TokenStoresegment for the processor with given processorName to contain
the given token.
This method fails if a Token already exists for the given processor and segment, even if that token has been claimed by the active instance.
This method will not claim the initialized segment. Use TokenStore.fetchToken(String, int) to retrieve and claim
the token.
initializeSegment in interface TokenStoretoken - The token to initialize the segment withprocessorName - The name of the processor to create the segment forsegment - The identifier of the segment to initializeUnableToInitializeTokenException - if a Token already existspublic boolean requiresExplicitSegmentInitialization()
TokenStorerequiresExplicitSegmentInitialization in interface TokenStoretrue if this instance requires tokens to be explicitly initialized, otherwise false.TokenStore.initializeTokenSegments(String, int),
TokenStore.initializeTokenSegments(String, int, TrackingToken),
TokenStore.initializeSegment(TrackingToken, String, int)public void deleteToken(@Nonnull String processorName, int segment) throws UnableToClaimTokenException
TokenStoreprocessorName and segment. The token must
be owned by the current node, to be able to delete it.
Implementations should implement this method only when TokenStore.requiresExplicitSegmentInitialization() is overridden to
return true. Deleting tokens using implementations that do not require explicit token initialization is
unsafe, as a claim will automatically recreate the deleted token instance, which may result in concurrency
issues.
deleteToken in interface TokenStoreprocessorName - The name of the processor to remove the token forsegment - The segment to deleteUnableToClaimTokenException - if the token is not currently claimed by this nodepublic TrackingToken fetchToken(@Nonnull String processorName, int segment)
TokenStoretoken for the given processorName and segment.
Returns null if the stored token for the given process and segment is
null.
This method should throw an UnableToClaimTokenException when the given segment has not been
initialized with a Token (albeit null) yet. In that case, a segment must have been explicitly initialized.
A TokenStore implementation's ability to do so is exposed by the TokenStore.requiresExplicitSegmentInitialization()
method. If that method returns false, this method may implicitly initialize a token and return that token upon
invocation.
The token will be claimed by the current process (JVM instance), preventing access by other instances. To release
the claim, use TokenStore.releaseClaim(String, int)
fetchToken in interface TokenStoreprocessorName - The process name for which to fetch the tokensegment - The segment index for which to fetch the tokennull if the store holds no token for given process and segmentpublic TrackingToken fetchToken(@Nonnull String processorName, @Nonnull Segment segment) throws UnableToClaimTokenException
TokenStoretoken for the given processorName and segment. Returns null if the stored token for
the given process and segment is null.
This method should throw an UnableToClaimTokenException when the given segment has not been initialized with a Token (albeit null) yet. In that case, a segment must have been explicitly initialized. A TokenStore implementation's ability to do so is exposed by the TokenStore.requiresExplicitSegmentInitialization() method. If that method returns false, this method may implicitly initialize a token and return that token upon
invocation.
The token will be claimed by the current process (JVM instance), preventing access by other instances. To release the claim, use TokenStore.releaseClaim(String, int)
fetchToken in interface TokenStoreprocessorName - The process name for which to fetch the tokensegment - The segment for which to fetch the tokennull if the store holds no token for given process and segmentUnableToClaimTokenException - if there is a token for given processorName and segment, but they are claimed by another process, or
if the segment has been split or merged concurrentlypublic void extendClaim(@Nonnull String processorName, int segment) throws UnableToClaimTokenException
TokenStoreprocessorName and
segment.extendClaim in interface TokenStoreprocessorName - The process name for which to fetch the tokensegment - The segment index for which to fetch the tokenUnableToClaimTokenException - if there is no token for given processorName and segment, or
if it has been claimed by another process.public int[] fetchSegments(@Nonnull String processorName)
TokenStoresegments for a given processorName.
The segments returned are segments for which a token has been stored previously. When the TokenStore is
empty, an empty array is returned.
fetchSegments in interface TokenStoreprocessorName - The process name for which to fetch the segmentspublic List<Segment> fetchAvailableSegments(@Nonnull String processorName)
TokenStoresegments for a given processorName. A segment is considered available if it is not claimed by any
other event processor.
The segments returned are segments for which a token has been stored previously and have not been claimed by another processor. When the TokenStore is empty, an empty list is returned.
By default, if this method is not implemented, we will return all segments instead, whether they are available or not.
fetchAvailableSegments in interface TokenStoreprocessorName - the processor's name for which to fetch the segmentsprocessorNameprotected TokenEntry loadToken(String processorName, int segment, javax.persistence.EntityManager entityManager)
TokenEntry or creates a new one using the given entityManager for given
processorName and segment.processorName - the name of the event processorsegment - the segment of the event processorentityManager - the entity manager instance to use for the queryUnableToClaimTokenException - if there is a token for given processorName and segment, but
it is claimed by another process.protected TokenEntry loadToken(String processorName, Segment segment, javax.persistence.EntityManager entityManager)
processorName and segment. If
such a token entry exists an attempt will be made to claim the token. If that succeeds the token will be
returned. If the token is already owned by another node an UnableToClaimTokenException will be thrown.
If no such token exists yet, a new token entry will be inserted with a null token, owned by this node,
and this method returns null.
If a token has been claimed, the segment will be validated by checking the database for the split and
merge candidate segments. If a concurrent split or merge operation has been detected, the calim will be released
and an UnableToClaimTokenException will be thrown.}
processorName - the name of the processor to load or insert a token entry forsegment - the segment of the processor to load or insert a token entry forentityManager - the entity manager instance to use for the querynull if a new entry was insertedUnableToClaimTokenException - if the token cannot be claimed because another node currently owns the token
or if the segment has been split or merged concurrentlypublic Optional<String> retrieveStorageIdentifier()
TokenStore
Note that this method may require the implementation to consult its underlying storage. Therefore, a Transaction
should be active when this method is called, similarly to invocations like TokenStore.fetchToken(String, int),
TokenStore.fetchSegments(String), etc. When no Transaction is active, the behavior is undefined.
retrieveStorageIdentifier in interface TokenStorepublic Serializer serializer()
Copyright © 2010–2023. All rights reserved.