public class JpaTokenStore extends Object implements TokenStore
TokenEntry
 entities.| Constructor and Description | 
|---|
JpaTokenStore(EntityManagerProvider entityManagerProvider,
             Serializer serializer)
Initializes a token store with given  
entityManagerProvider and serializer. | 
JpaTokenStore(EntityManagerProvider entityManagerProvider,
             Serializer serializer,
             TemporalAmount claimTimeout,
             String nodeId)
Initialize the JpaTokenStore with given resources. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
void | 
extendClaim(String processorName,
           int segment)
Extends the claim on the current token held by the this node for the given  
processorName and
 segment. | 
int[] | 
fetchSegments(String processorName)
Returns an array of known  
segments for a given processorName. | 
TrackingToken | 
fetchToken(String processorName,
          int segment)
 | 
void | 
initializeTokenSegments(String processorName,
                       int segmentCount)
Initializes the given  
segmentCount number of segments for the given processorName to track its
 tokens. | 
protected TokenEntry | 
loadOrCreateToken(String processorName,
                 int segment,
                 javax.persistence.EntityManager entityManager)
Loads an existing  
TokenEntry or creates a new one using the given entityManager for given processorName and segment. | 
void | 
releaseClaim(String processorName,
            int segment)
Release a claim of the token for given  
processorName and segment. | 
void | 
storeToken(TrackingToken token,
          String processorName,
          int segment)
Stores the given  
token in the store. | 
public JpaTokenStore(EntityManagerProvider entityManagerProvider, Serializer serializer)
entityManagerProvider and serializer.entityManagerProvider - The provider of the entity managerserializer - The serializer used to serialize tokenspublic JpaTokenStore(EntityManagerProvider entityManagerProvider, Serializer serializer, TemporalAmount claimTimeout, String nodeId)
claimTimeout is used to 'steal' any claim
 that has not been updated since that amount of time.entityManagerProvider - provides the EntityManager to access the underlying databaseserializer - The serializer to serialize tokens withclaimTimeout - The timeout after which this process will force a claimnodeId - The identifier to identify ownership of the tokenspublic void initializeTokenSegments(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 no 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 storeToken(TrackingToken token, 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.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(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 TrackingToken fetchToken(String processorName, int segment)
TokenStoretoken for the given processorName and segment.
 Returns null if the store holds no token or if the stored token for the given process and segment is
 null.
 
 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 void extendClaim(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(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 segmentsprotected TokenEntry loadOrCreateToken(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.Copyright © 2010–2018. All rights reserved.