T
- The serialized data type of the token@MappedSuperclass public abstract class AbstractTokenEntry<T> extends Object
Modifier and Type | Field and Description |
---|---|
static Clock |
clock
The clock used to persist timestamps in this entry.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractTokenEntry()
Default constructor required for JPA
|
protected |
AbstractTokenEntry(TrackingToken token,
Serializer serializer,
Class<T> contentType)
Initializes a new token entry for given
token , process and segment . |
protected |
AbstractTokenEntry(T token,
String tokenType,
String timestamp,
String owner)
Initializes a token entry from existing data.
|
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. |
abstract String |
getProcessorName()
Returns the name of the process to which this token belongs.
|
abstract int |
getSegment()
Returns the segment index of the process to which this token belongs.
|
SerializedObject<T> |
getSerializedToken()
Returns the serialized token.
|
TrackingToken |
getToken(Serializer serializer)
Returns the token, deserializing it with given
serializer |
protected SerializedType |
getTokenType()
Returns the
SerializedType of the serialized token. |
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.
|
abstract void |
updateToken(TrackingToken token,
Serializer serializer)
Update this entry with the given
token , serializing it using given serializer . |
protected void |
updateToken(TrackingToken token,
Serializer serializer,
Class<T> contentType)
Update the token data to the given
token , using given serializer to serialize it to the given
contentType . |
public static Clock clock
protected AbstractTokenEntry(TrackingToken token, Serializer serializer, Class<T> contentType)
token
, process
and segment
. The given serializer
can be used to serialize the token before it is stored.token
- The tracking token to storeserializer
- The serializer to use when storing a serialized tokencontentType
- The content type after serializationprotected AbstractTokenEntry(T token, String tokenType, String timestamp, String owner)
token
- the serialized tokentokenType
- the serialized type of the tokentimestamp
- the timestamp of the tokenowner
- the owner of the tokenprotected AbstractTokenEntry()
public SerializedObject<T> getSerializedToken()
public TrackingToken getToken(Serializer serializer)
serializer
serializer
- The serialize to deserialize the token withprotected SerializedType getTokenType()
SerializedType
of the serialized token.public Instant timestamp()
public String timestampAsString()
public abstract void updateToken(TrackingToken token, Serializer serializer)
token
, serializing it using given serializer
.token
- The token to update the entry withserializer
- The serializer to serialize data withpublic abstract String getProcessorName()
public abstract int getSegment()
public 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 getOwner()
null
if the token isn't
claimed.protected final void updateToken(TrackingToken token, Serializer serializer, Class<T> contentType)
token
, using given serializer
to serialize it to the given
contentType
.token
- The token representing the state to update toserializer
- The serializer to update token tocontentType
- The type of data to represent the serialized data inCopyright © 2010–2017. All rights reserved.