Class TransformToken


  • public class TransformToken
    extends Object
    Provides a token used in property conversion. The token is used to limit the number of processes that try to create a property node and transform the legacy property format to the 2.1 encoded properties. Processes do not queue for a token (using a sequential node) - processes should look for the token to exist, and if present wait and then periodically re-check for the property node to be created by the process that created / has the token.

    Features

    • Uses ephemeral node that will be removed if transform process terminates without completing
    • Watcher not necessary - the existence of the node and uuid in data sufficient to detect changes.
    • Method Detail

      • createToken

        public static TransformToken createToken​(@NonNull String path,
                                                 ZooReaderWriter zrw)
        Create a lock node in ZooKeeper using an ephemeral node. Will not throw and exception except on an interrupt. If the lock node is created, the returned lock will be locked. If another lock already exists, the lock is unlocked and the caller can decide to either wait for the resource to be created by the thread that created the lock, or try calling to lock to succeed
        Parameters:
        path - the parent node of the legacy properties and the associated property children nodes.
        zrw - a ZooReaderWriter
        Returns:
        an TransformLock instance.
        Throws:
        IllegalStateException - is the lock creation fails due to an underlying ZooKeeper exception.
      • getTokenOwnership

        public boolean getTokenOwnership()
        Create and try to establish ownership (hold the token). Token ownership can be tested with haveTokenOwnership
        Returns:
        true if able to get ownership, false otherwise.
      • haveTokenOwnership

        public boolean haveTokenOwnership()
        Return the token ownership status
        Returns:
        true if this instance has ownership of the token, false otherwise.
      • validateToken

        public boolean validateToken()
        Verify ownership is still valid while holding the token.
        Returns:
        true if token is still owned, false otherwise
      • releaseToken

        public void releaseToken()
        If the token was created by this instance, the uuid of this instance and the uuid stored in the ZooKeeper data will match.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object