Enum Class EphemeralType
- All Implemented Interfaces:
Serializable
,Comparable<EphemeralType>
,Constable
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).
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum Constants -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final long
static final long
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Return true if extended ephemeral types are enabledstatic 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 ownerlong
maxValue()
For types that support it, the maximum extended valuelong
toEphemeralOwner
(long value) For types that support it, convert a value to an extended ephemeral ownerstatic void
validateServerId
(long serverId) Make sure the given server ID is compatible with the current extended ephemeral settingstatic void
validateTTL
(CreateMode mode, long ttl) Utility to validate a create mode and a ttlstatic EphemeralType
Returns the enum constant of this class with the specified name.static EphemeralType[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
VOID
Not ephemeral -
NORMAL
Standard, pre-3.5.x EPHEMERAL -
CONTAINER
Container node -
TTL
TTL node
-
-
Field Details
-
CONTAINER_EPHEMERAL_OWNER
public static final long CONTAINER_EPHEMERAL_OWNER- See Also:
-
MAX_EXTENDED_SERVER_ID
public static final long MAX_EXTENDED_SERVER_ID- See Also:
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
maxValue
public long maxValue()For types that support it, the maximum extended value- Returns:
- 0 or max
-
toEphemeralOwner
public long toEphemeralOwner(long value) For types that support it, convert a value to an extended ephemeral owner- Returns:
- 0 or extended ephemeral owner
-
getValue
public long getValue(long ephemeralOwner) For types that support it, return the extended value from an extended ephemeral owner- Returns:
- 0 or extended value
-
extendedEphemeralTypesEnabled
public static boolean extendedEphemeralTypesEnabled()Return true if extended ephemeral types are enabled- Returns:
- true/false
-
get
Convert a ZNode ephemeral owner to an ephemeral type. If extended types are not enabled, VOID or NORMAL is always returned- Parameters:
ephemeralOwner
- the ZNode's ephemeral owner- Returns:
- type
-
validateServerId
public static void validateServerId(long serverId) Make sure the given server ID is compatible with the current extended ephemeral setting- Parameters:
serverId
- Server ID- Throws:
RuntimeException
- extendedTypesEnabled is true but Server ID is too large
-
validateTTL
Utility to validate a create mode and a ttl- Parameters:
mode
- create modettl
- ttl- Throws:
IllegalArgumentException
- if the ttl is not valid for the mode
-