Beispiel #1
0
        private void InitListener()
        {
            var cache = new PathChildrenCache(client, "/live_nodes", true);

            cache.start();
            cache.getListenable().addListener(new LiveNodesListener());
        }
 /// <exception cref="System.IO.IOException"/>
 public override void StartThreads()
 {
     if (!isExternalClient)
     {
         try
         {
             zkClient.Start();
         }
         catch (Exception e)
         {
             throw new IOException("Could not start Curator Framework", e);
         }
     }
     else
     {
         // If namespace parents are implicitly created, they won't have ACLs.
         // So, let's explicitly create them.
         CuratorFramework nullNsFw = zkClient.UsingNamespace(null);
         EnsurePath       ensureNs = nullNsFw.NewNamespaceAwareEnsurePath("/" + zkClient.GetNamespace
                                                                              ());
         try
         {
             ensureNs.Ensure(nullNsFw.GetZookeeperClient());
         }
         catch (Exception e)
         {
             throw new IOException("Could not create namespace", e);
         }
     }
     listenerThreadPool = Executors.NewSingleThreadExecutor();
     try
     {
         delTokSeqCounter = new SharedCount(zkClient, ZkDtsmSeqnumRoot, 0);
         if (delTokSeqCounter != null)
         {
             delTokSeqCounter.Start();
         }
     }
     catch (Exception e)
     {
         throw new IOException("Could not start Sequence Counter", e);
     }
     try
     {
         keyIdSeqCounter = new SharedCount(zkClient, ZkDtsmKeyidRoot, 0);
         if (keyIdSeqCounter != null)
         {
             keyIdSeqCounter.Start();
         }
     }
     catch (Exception e)
     {
         throw new IOException("Could not start KeyId Counter", e);
     }
     try
     {
         CreatePersistentNode(ZkDtsmMasterKeyRoot);
         CreatePersistentNode(ZkDtsmTokensRoot);
     }
     catch (Exception)
     {
         throw new RuntimeException("Could not create ZK paths");
     }
     try
     {
         keyCache = new PathChildrenCache(zkClient, ZkDtsmMasterKeyRoot, true);
         if (keyCache != null)
         {
             keyCache.Start(PathChildrenCache.StartMode.BuildInitialCache);
             keyCache.GetListenable().AddListener(new _PathChildrenCacheListener_340(this), listenerThreadPool
                                                  );
         }
     }
     catch (Exception e)
     {
         throw new IOException("Could not start PathChildrenCache for keys", e);
     }
     try
     {
         tokenCache = new PathChildrenCache(zkClient, ZkDtsmTokensRoot, true);
         if (tokenCache != null)
         {
             tokenCache.Start(PathChildrenCache.StartMode.BuildInitialCache);
             tokenCache.GetListenable().AddListener(new _PathChildrenCacheListener_368(this),
                                                    listenerThreadPool);
         }
     }
     catch (Exception e)
     {
         throw new IOException("Could not start PathChildrenCache for tokens", e);
     }
     base.StartThreads();
 }