• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
ZooKeeper | Curator Framework: Create a facade on an existing CuratorFramework instance [usingNamespace]
  1. Notes
  2. Example

  1. Notes:
    The code bellow let you create a facade of the current CuratorFramework instance that uses a specific namespace.
    The namespace is a relative path to the root path of the current CuratorFramework instance (default "/").

    The namespace can be "null", which means that the path will be the same as the root path of the current CuratorFramework instance (default "/").

    The namespcae should not start or end with "/"

    For example, if your namespace is "abc/abc1", then the relative path will be "/abc/abc1" and you will access only zNodes under this path.

    In order for the code bellow to work:
    ► Make sure to update the "CONNECT_STRING" variable with your information.
  2. Example
    Here's an example of how to create a facade of a CuratorFramework instance that uses a specific namespace:
    final String CONNECT_STRING = "localhost:2181";
    
    final int SESSION_TIMEOUT_MS = Integer.valueOf(60 * 1000);
    final int CONNECTION_TIMEOUT_MS = Integer.valueOf(15 * 1000);
    final RetryPolicy RETRY_POLICY = new RetryOneTime(1000);
    
    // -- CuratorFrameworkFactory::newClient
    final CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(CONNECT_STRING, SESSION_TIMEOUT_MS, CONNECTION_TIMEOUT_MS, RETRY_POLICY);
    
    // -- CuratorFramework::start
    curatorFramework.start();
    
    // -- CuratorFramework::usingNamespace
    // Returns a facade of the current CuratorFramework instance that uses the specified namespace.
    final String nameSpace = "abc/abc1";
    final CuratorFramework curatorFrameworkUsingNamespace = curatorFramework.usingNamespace(nameSpace);
    
    // do something here ...
    
    // -- CuratorFramework::close
    curatorFramework.close();
© 2025  mtitek