zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cameron McKenzie <cammcken...@apache.org>
Subject Re: curator pathcache
Date Wed, 09 Mar 2016 02:38:25 GMT
Is there data in ZK at whatever location is defined by your PATH constant?

Has a connection to ZK been successfully established?

On Wed, Mar 9, 2016 at 12:27 PM, s influxdb <elastic.l.k@gmail.com> wrote:

> I am trying to run the path cahce and keep java NPE
>
> Running curator 2.9.0 libraries against a zookeeper 3.4.6 cluster
> Even
>
> The samples are taken from the curator examples .
>
>
>
>   public void run () throws Exception
>        {
>              try {
>
>                 pcache = new PathChildrenCache(client, PATH, true);
>              pcache.start();
>
>                 addListener(cache);
>
>            //    list(pcache);
>
>                pcache.close();
>             }
>              finally {
>                 CloseableUtils.closeQuietly(cache);
>              }
>         }
>
>
>       private static void addListener(PathChildrenCache cache)
>       {
>           // a PathChildrenCacheListener is optional. Here, it's used just
> to log changes
>           PathChildrenCacheListener listener = new
> PathChildrenCacheListener()
>           {
>               @Override
>               public void childEvent(CuratorFramework client,
> PathChildrenCacheEvent event) throws Exception
>               {
>                   switch ( event.getType() )
>                   {
>                       case CHILD_ADDED:
>                       {
>                           System.out.println("Node added: " +
> ZKPaths.getNodeFromPath(event.getData().getPath()));
>                           break;
>                       }
>
>                       case CHILD_UPDATED:
>                       {
>                           System.out.println("Node changed: " +
> ZKPaths.getNodeFromPath(event.getData().getPath()));
>                           break;
>                       }
>
>                       case CHILD_REMOVED:
>                       {
>                           System.out.println("Node removed: " +
> ZKPaths.getNodeFromPath(event.getData().getPath()));
>                           break;
>                       }
>                   }
>               }
>           };
>           cache.getListenable().addListener(listener);
>       }
>
>
> Here running a list returns empty size all the time
>
>       private static void list(PathChildrenCache cache)
>         {
>
>             if ( cache.getCurrentData().size() == 0 )
>             {
>                 System.out.println("* empty *");
>             }
>             else
>             {
>                 for ( ChildData data : cache.getCurrentData() )
>                 {
>                     System.out.println(data.getPath() + " = " + new
> String(data.getData()));
>                 }
>             }
>         }
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message