Package org.apache.cassandra.dht
Class Token
- java.lang.Object
-
- org.apache.cassandra.dht.Token
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<Token>
,RingPosition<Token>
- Direct Known Subclasses:
ByteOrderedPartitioner.BytesToken
,LocalPartitioner.LocalToken
,Murmur3Partitioner.LongToken
,OrderPreservingPartitioner.StringToken
,RandomPartitioner.BigIntegerToken
public abstract class Token extends java.lang.Object implements RingPosition<Token>, java.io.Serializable
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Token.KeyBound
static class
Token.TokenFactory
static class
Token.TokenSerializer
-
Field Summary
Fields Modifier and Type Field Description static Token.TokenSerializer
serializer
-
Constructor Summary
Constructors Constructor Description Token()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract ByteSource
asComparableBytes(ByteComparable.Version version)
Produce a weakly prefix-free byte-comparable representation of the token, i.e.abstract long
getHeapSize()
long
getLongValue()
This method exists so that callers can access the primitivelong
value for thisToken
, if one exits.abstract IPartitioner
getPartitioner()
Token
getToken()
abstract java.lang.Object
getTokenValue()
boolean
isMinimum()
Token.KeyBound
maxKeyBound()
Token.KeyBound
minKeyBound()
Token
minValue()
abstract Token
nextValidToken()
Returns the next possible token in the token space, one that compares greater than this and such that there is no other token that sits between this token and it in the token order.abstract double
size(Token next)
Returns a measure for the token space covered between this token and next.
-
-
-
Field Detail
-
serializer
public static final Token.TokenSerializer serializer
-
-
Method Detail
-
getPartitioner
public abstract IPartitioner getPartitioner()
- Specified by:
getPartitioner
in interfaceRingPosition<Token>
-
getHeapSize
public abstract long getHeapSize()
-
getTokenValue
public abstract java.lang.Object getTokenValue()
-
getLongValue
public long getLongValue()
This method exists so that callers can access the primitivelong
value for thisToken
, if one exits. It is especially useful when the auto-boxing induced by a call togetTokenValue()
would be unacceptable for reasons of performance.- Returns:
- the primitive
long
value of this token, if one exists - Throws:
java.lang.UnsupportedOperationException
- if thisToken
is not backed by a primitivelong
value
-
asComparableBytes
public abstract ByteSource asComparableBytes(ByteComparable.Version version)
Produce a weakly prefix-free byte-comparable representation of the token, i.e. such a sequence of bytes that any pair x, y of valid tokens of this type and any bytes b1, b2 between 0x10 and 0xEF, (+ stands for concatenation) compare(x, y) == compareLexicographicallyUnsigned(asByteComparable(x)+b1, asByteComparable(y)+b2) (i.e. the values compare like the original type, and an added 0x10-0xEF byte at the end does not change that) and: asByteComparable(x)+b1 is not a prefix of asByteComparable(y) (weakly prefix free) (i.e. a valid representation of a value may be a prefix of another valid representation of a value only if the following byte in the latter is smaller than 0x10 or larger than 0xEF). These properties are trivially true if the encoding compares correctly and is prefix free, but also permits a little more freedom that enables somewhat more efficient encoding of arbitrary-length byte-comparable blobs.
-
size
public abstract double size(Token next)
Returns a measure for the token space covered between this token and next. Used by the token allocation algorithm (see CASSANDRA-7032).
-
nextValidToken
public abstract Token nextValidToken()
Returns the next possible token in the token space, one that compares greater than this and such that there is no other token that sits between this token and it in the token order. This is not possible for all token types, esp. for comparison-based tokens such as the LocalPartioner used for classic secondary indexes. Used to avoid clashes between nodes in separate datacentres trying to use the same token via the token allocation algorithm, as well as in constructing token ranges for sstables.
-
getToken
public Token getToken()
- Specified by:
getToken
in interfaceRingPosition<Token>
-
minValue
public Token minValue()
- Specified by:
minValue
in interfaceRingPosition<Token>
-
isMinimum
public boolean isMinimum()
- Specified by:
isMinimum
in interfaceRingPosition<Token>
-
minKeyBound
public Token.KeyBound minKeyBound()
-
maxKeyBound
public Token.KeyBound maxKeyBound()
-
-