Package org.apache.zookeeper

Examples of org.apache.zookeeper.ZooKeeper$ZKWatchManager


         assertEquals(0,((MetricGetters)collector).getDiscardedMessageCount());
         assertEquals(0,((MetricGetters)collector).getMessageFailedCount());

         // ok ... so now we have stuff going all the way through. let's kick
         // the middle Mp's zookeeper cluster and see what happens.
         ZooKeeper origZk = zookeeperCluster.zkref.get();
         long sessionid = origZk.getSessionId();
         ZooKeeper killer = new ZooKeeper(System.getProperty("zk_connect"),5000, new Watcher() { @Override public void process(WatchedEvent arg0) { } }, sessionid, null);
         killer.close(); // tricks the server into expiring the other session

//         // we should be getting failures now ...
//         // but it's possible that it can reconnect prior to actually seeing an error so if this
//         //   fails frequently we need to remove this test.
//         assertTrue(poll(baseTimeoutMillis, app, new Condition()
View Full Code Here


         assertEquals(0,((MetricGetters)collector).getDiscardedMessageCount());
         assertEquals(0,((MetricGetters)collector).getMessageFailedCount());

         // ok ... so now we have stuff going all the way through. let's kick
         // the middle Mp's zookeeper cluster and see what happens.
         ZooKeeper origZk = zookeeperCluster.zkref.get();
         origZk.close(); // this should kill it.
        
         // but just to be sure actually stop the node.
         mpnode.stop();

         // we should be getting failures now ... and then recover.
View Full Code Here

         session = new ZookeeperSession("127.0.0.1:" + port,5000) {
           
            @Override
            protected ZooKeeper makeZooKeeperClient(String connectString, int sessionTimeout) throws IOException
            {
               return new ZooKeeper(connectString,sessionTimeout,new ZkWatcher())
               {
                  @Override
                  public List<String> getChildren(String path, Watcher watcher) throws KeeperException
                  {
                     throw (appropriateException = new KeeperException(Code.DATAINCONSISTENCY)
View Full Code Here

      while (!done)
      {
         long sessionid = origZk.getSessionId();
         byte[] pw = origZk.getSessionPasswd();
         KWatcher kwatcher = new KWatcher();
         ZooKeeper killer = new ZooKeeper("127.0.0.1:" + port,5000, kwatcher, sessionid, pw);
         kwatcher.connection.set(killer);

         // wait until we get a close
         boolean calledBack = TestUtils.poll(5000, kwatcher, new Condition<KWatcher>()
               {
            @Override
            public boolean conditionMet(KWatcher o) throws Throwable
            {
               return o.closed.get();
            }
               });

         if (!calledBack)
            killer.close();

         final AtomicBoolean isExpired = new AtomicBoolean(false);
         ZooKeeper check = new ZooKeeper("127.0.0.1:" + port,5000, new Watcher()
         {
            @Override
            public void process(WatchedEvent event)
            {
               if (event.getState() == Watcher.Event.KeeperState.Expired)
                  isExpired.set(true);
            }
         }, sessionid, pw);
        
         done = TestUtils.poll(5000, isExpired, new Condition<AtomicBoolean>() { public boolean conditionMet(AtomicBoolean o) { return o.get(); } });
        
         check.close();
      }
   }
View Full Code Here

      AtomicBoolean closed = new AtomicBoolean(false);
     
      @Override
      public void process(final WatchedEvent event)
      {
         final ZooKeeper tcon = connection.get();
         if (tcon != null && event.getState() == Watcher.Event.KeeperState.SyncConnected)
         {
            try { tcon.close(); closed.set(true); } catch (InterruptedException ie) {}
         }
      }
View Full Code Here

            @Override public boolean conditionMet(TestWatcher o){  return !o.called.get(); }
         }));

         session.getSubdirs(clusterId.asPath(), callback);
        
         ZooKeeper origZk = session.zkref.get();
         ZookeeperTestServer.forceSessionExpiration(origZk);
        
         // wait for the callback
         assertTrue(TestUtils.poll(baseTimeoutMillis, callback, new Condition<TestWatcher>() {
            @Override public boolean conditionMet(TestWatcher o){  return o.called.get(); }
View Full Code Here

            }
           
         }));

         logger.trace("Killing zookeeper");
         ZooKeeper origZk = session.zkref.get();
         ZookeeperTestServer.forceSessionExpiration(origZk);
         logger.trace("Killed zookeeper");
        
         // wait for the current session to go invalid
         assertTrue(poll(baseTimeoutMillis, origZk, new Condition<ZooKeeper>()
View Full Code Here

        int retryDelay = 10;

        while (true) {
            try {
                logger.warn("connecting to {}", connectString);
                zk = new ZooKeeper(connectString, 5000, new StateWatcher());
                try {
                    zk.create(base, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
                } catch (KeeperException.NodeExistsException e) {
                    // ignore
                }
View Full Code Here

    String slave2 = "slave2";
    String slave3 = "slave3";
    String config1 = "config1";
   
    TestZookeeper tz = new TestZookeeper();
    ZooKeeper zk = new ZooKeeper(servers,3000,tz);
    tz.zk = zk;
   
    //每次启动时都先检查是否有根目录
    createGroupNodesIfNotExist(zk,groupId);
   
    updateOrCreateNode(zk,getGroupMasterZKPath(groupId)+"/"+master1,"master1value".getBytes("UTF-8"));
    updateOrCreateNode(zk,getGroupMasterZKPath(groupId)+"/"+master2,"master2value".getBytes("UTF-8"));
    updateOrCreateNode(zk,getGroupSlaveZKPath(groupId)+"/"+slave1,"slave1value".getBytes("UTF-8"));
    updateOrCreateNode(zk,getGroupSlaveZKPath(groupId)+"/"+slave2,"slave2value".getBytes("UTF-8"));
    updateOrCreateNode(zk,getGroupSlaveZKPath(groupId)+"/"+slave3,"slave3value".getBytes("UTF-8"));
    updateOrCreateNode(zk,getGroupConfigZKPath(groupId)+"/"+config1,"config1value".getBytes("UTF-8"));
   
    List<String> groups = zk.getChildren(AnalysisConstants.ZK_ROOT, false);
   
    List<String> master = zk.getChildren(getGroupMasterZKPath(groups.get(0)), false);
       
    List<String> slave = zk.getChildren(getGroupSlaveZKPath(groups.get(0)), false);
   
    List<String> config = zk.getChildren(getGroupConfigZKPath(groups.get(0)), false);
   
    System.out.println(new String(zk.getData(getGroupConfigZKPath(groups.get(0)) + "/" + config.get(0), false,null),"utf-8"));
   
    Thread.sleep(200000);

  }
View Full Code Here

    public TSOState buildState()
    throws LoggerException {
        try{
            CountDownLatch latch = new CountDownLatch(1);
           
            this.zk = new ZooKeeper(config.getZkServers(),
                                            Integer.parseInt(System.getProperty("SESSIONTIMEOUT", Integer.toString(10000))),
                                            new LoggerWatcher(latch));
           
            latch.await();
        } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.apache.zookeeper.ZooKeeper$ZKWatchManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.