public enum EphemeralType extends Enum<EphemeralType>
Abstraction that interprets the ephemeralOwner
field of a ZNode. Originally,
the ephemeralOwner noted that a ZNode is ephemeral and which session created the node.
Through an optional system property (zookeeper.extendedTypesEnabled
) "extended"
features such as TTL Nodes can be enabled. Special bits of the ephemeralOwner are used to
denote which feature is enabled and the remaining bits of the ephemeralOwner are feature
specific.
When the system property zookeeper.extendedTypesEnabled
is true, extended types
are enabled. An extended ephemeralOwner is defined as an ephemeralOwner whose high 8 bits are
set (0xff00000000000000L
). The two bytes that follow the high 8 bits are
used to denote which extended feature the ephemeralOwner represents. The remaining 5 bytes are
used by the feature for whatever purpose is needed
Currently, the only extended feature is TTL Nodes. It is denoted by the extended feature value of 0.
i.e. for TTL Nodes, the ephemeralOwner has the high byte set to 0xff and the next 2 bytes are 0 followed
by 5 bytes that represent the TTL value in milliseconds. So, an ephemeralOwner with a TTL value of 1
millisecond is: 0xff00000000000001
.
To add new extended features: a) Add a new name to the enum, b) define a constant EXTENDED_BIT_xxxx that's next
in line (after TTLs, that would be 0x0001
), c) add a mapping to the extendedFeatureMap via the static
initializer
NOTE: "Container" nodes technically are extended types but as it was implemented before this feature they are
denoted specially. An ephemeral owner with only the high bit set (0x8000000000000000L
) is by definition
a container node (irrespective of whether or not extended types are enabled).
Enum Constant and Description |
---|
CONTAINER
Container node
|
NORMAL
Standard, pre-3.5.x EPHEMERAL
|
TTL
TTL node
|
VOID
Not ephemeral
|
Modifier and Type | Field and Description |
---|---|
static long |
CONTAINER_EPHEMERAL_OWNER |
static long |
MAX_EXTENDED_SERVER_ID |
Modifier and Type | Method and Description |
---|---|
static boolean |
extendedEphemeralTypesEnabled()
Return true if extended ephemeral types are enabled
|
static EphemeralType |
get(long ephemeralOwner)
Convert a ZNode ephemeral owner to an ephemeral type.
|
long |
getValue(long ephemeralOwner)
For types that support it, return the extended value from an extended ephemeral owner
|
long |
maxValue()
For types that support it, the maximum extended value
|
long |
toEphemeralOwner(long value)
For types that support it, convert a value to an extended ephemeral owner
|
static void |
validateServerId(long serverId)
Make sure the given server ID is compatible with the current extended ephemeral setting
|
static void |
validateTTL(CreateMode mode,
long ttl)
Utility to validate a create mode and a ttl
|
static EphemeralType |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static EphemeralType[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final EphemeralType VOID
public static final EphemeralType NORMAL
public static final EphemeralType CONTAINER
public static final EphemeralType TTL
public static final long CONTAINER_EPHEMERAL_OWNER
public static final long MAX_EXTENDED_SERVER_ID
public static EphemeralType[] values()
for (EphemeralType c : EphemeralType.values()) System.out.println(c);
public static EphemeralType valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic long maxValue()
public long toEphemeralOwner(long value)
public long getValue(long ephemeralOwner)
public static boolean extendedEphemeralTypesEnabled()
public static EphemeralType get(long ephemeralOwner)
ephemeralOwner
- the ZNode's ephemeral ownerpublic static void validateServerId(long serverId)
serverId
- Server IDRuntimeException
- extendedTypesEnabled is true but Server ID is too largepublic static void validateTTL(CreateMode mode, long ttl)
mode
- create modettl
- ttlIllegalArgumentException
- if the ttl is not valid for the modeCopyright © 2008–2021 The Apache Software Foundation. All rights reserved.