@Entity @Entity public class TokenEntry extends Object
Modifier and Type | Class and Description |
---|---|
static class |
TokenEntry.PK
Primary key for token entries used by JPA
|
Modifier and Type | Field and Description |
---|---|
static Clock |
clock
The clock used to persist timestamps in this entry.
|
Modifier | Constructor and Description |
---|---|
protected |
TokenEntry()
Default constructor for JPA
|
|
TokenEntry(String processorName,
int segment,
TrackingToken token,
Serializer serializer)
Initializes a new token entry for given
token , processorName and segment . |
Modifier and Type | Method and Description |
---|---|
boolean |
claim(String owner,
TemporalAmount claimTimeout)
Attempt to claim ownership of this token.
|
String |
getOwner()
Returns the identifier of the process (JVM) having a claim on this token, or
null if the token isn't
claimed. |
String |
getProcessorName() |
int |
getSegment() |
SerializedObject<byte[]> |
getSerializedToken()
Returns the serialized token.
|
TrackingToken |
getToken(Serializer serializer)
Returns the token, deserializing it with given
serializer |
SerializedType |
getTokenType()
Returns the
SerializedType of the serialized token, or null if no token is stored by this entry. |
boolean |
mayClaim(String owner,
TemporalAmount claimTimeout)
Check if given
owner may claim this token. |
boolean |
releaseClaim(String owner)
Release any claim of ownership currently active on this Token, if owned by the given
owner . |
Instant |
timestamp()
Returns the storage timestamp of this token entry.
|
String |
timestampAsString()
Returns the storage timestamp of this token entry as a String.
|
void |
updateToken(TrackingToken token,
Serializer serializer)
Updates a token, using the provided token and serializer to update the serialized token and token type.
|
public static Clock clock
public TokenEntry(String processorName, int segment, TrackingToken token, Serializer serializer)
token
, processorName
and segment
. The given
serializer
can be used to serialize the token before it is stored.token
- The tracking token to storeprocessorName
- The name of the processor to store this token forsegment
- The segment index of the processorserializer
- The serializer to use when storing a serialized tokenprotected TokenEntry()
public SerializedObject<byte[]> getSerializedToken()
public TrackingToken getToken(Serializer serializer)
serializer
serializer
- The serialize to deserialize the token withpublic SerializedType getTokenType()
SerializedType
of the serialized token, or null
if no token is stored by this entry.null
if no token is stored by this entrypublic boolean claim(String owner, TemporalAmount claimTimeout)
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'.
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 ownertrue
if the claim succeeded, otherwise falsepublic boolean mayClaim(String owner, TemporalAmount claimTimeout)
owner
may claim this token.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 ownertrue
if the claim may be made, false
otherwisepublic boolean releaseClaim(String owner)
owner
.owner
- The name of the current node, which was registered as the ownertrue
of the claim was successfully released, or false
if the token has been claimed by
another owner.public String timestampAsString()
public Instant timestamp()
public void updateToken(TrackingToken token, Serializer serializer)
Clock
.token
- The new token that needs to be persistedserializer
- The serializer that will be used to serialize the tokenpublic String getOwner()
null
if the token isn't
claimed.public String getProcessorName()
public int getSegment()
Copyright © 2010–2024. All rights reserved.