List of usage examples for org.apache.zookeeper WatchedEvent getType
public EventType getType()
From source file:com.ebay.jetstream.messaging.zookeeper.lp.Consumer.java
License:MIT License
@Override public void process(WatchedEvent event) { switch (event.getType()) { case NodeChildrenChanged: childrenChanged++;//from w ww .j ava 2 s . c o m setChildrenWatch(event.getPath()); break; case NodeCreated: nodecreated++; setChildrenWatch(event.getPath()); break; case NodeDataChanged: //System.out.println(" changed Node" + event.getPath()); datachanged++; getData(event.getPath()); setNodeWatch(event.getPath()); break; case NodeDeleted: break; case None: break; default: break; } }
From source file:com.ebay.jetstream.messaging.zookeeper.lp.ZKTester.java
License:MIT License
@Override public void process(WatchedEvent event) { switch (event.getType()) { case NodeChildrenChanged: break;//from w w w . j a va 2s .c o m case NodeCreated: break; case NodeDataChanged: try { // Stat stat = framework.checkExists().forPath(event.getPath()); // long curtime = System.currentTimeMillis(); // long delay = curtime - stat.getMtime(); // System.out.println("Notification delay : " + delay); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } listenercounter++; break; case NodeDeleted: break; case None: break; default: break; } }
From source file:com.edmunds.etm.agent.impl.RuleSetMonitor.java
License:Apache License
@Override public void process(WatchedEvent event) { String path = event.getPath(); if (path != null && path.equals(ruleSetNodePath)) { switch (event.getType()) { case NodeCreated: case NodeDataChanged: AsyncCallback.DataCallback cb = new AsyncCallback.DataCallback() { @Override// ww w.ja va 2 s . c o m public void processResult(int rc, String path, Object ctx, byte[] data, Stat stat) { onGetRuleSetData(Code.get(rc), path, data); } }; connection.getData(ruleSetNodePath, this, cb, null); case None: case NodeDeleted: case NodeChildrenChanged: default: // Ignore other event types } } }
From source file:com.edmunds.zookeeper.election.ZooKeeperElection.java
License:Apache License
private void processCurrentWatcher(ZooKeeperElectionContext ctx, WatchedEvent event) { final KeeperState connectionState = event.getState(); if (connectionState == KeeperState.SyncConnected) { // Has someone blown our node away ? if (event.getType() == EventType.NodeDeleted) { // Withdraw from this election and sign up again. if (ctx.isActive()) { withdrawAndEnroll(ctx, "Current Node Deleted"); }/*w w w . j a v a2 s . c o m*/ } } else { error("Connection lost - Primary watch: " + connectionState, Code.CONNECTIONLOSS, "/", ctx); withdrawInternal(ctx, "Current Node Connection Lost"); } }
From source file:com.edmunds.zookeeper.treewatcher.ZooKeeperTreeWatcher.java
License:Apache License
private void processEvent(WatchedEvent event, ZooKeeperTreeState state) { final String path = event.getPath(); final ZooKeeperTreeNode node = state.getNode(path); final Event.EventType eventType = event.getType(); switch (eventType) { case NodeCreated: if (rootPath.equals(path)) { scanRootNode();/*www.jav a2s. c om*/ } else { recoverableError(path, eventType, "Unexpected node Created"); } break; case NodeDataChanged: if (node != null) { state.setFlags(path, false, node.isChildListConsistent()); getData(path, null); } else { recoverableError(path, eventType, "Path is not tracked"); } break; case NodeChildrenChanged: if (node != null) { state.setFlags(path, node.isDataConsistent(), false); getChildren(path, null); } else { recoverableError(path, eventType, "Path is not tracked"); } break; case NodeDeleted: // Apply deletions immediately. if (node != null) { safeDelete(path); } break; default: unexpectedEventError(event); break; } }
From source file:com.ery.estorm.zk.ZooKeeperWatcher.java
License:Apache License
/** * Method called from ZooKeeper for events and connection status. * <p>// www.j ava 2 s. co m * Valid events are passed along to listeners. Connection status changes are * dealt with locally. */ @Override public void process(WatchedEvent event) { String path = event.getPath(); if (path != null || EventType.NodeDeleted == event.getType()) { try { ZKUtil.watchAndCheckExists(this, path); } catch (KeeperException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } LOG.debug(prefix("Received ZooKeeper Event, " + "type=" + event.getType() + ", " + "state=" + event.getState() + ", " + "path=" + path)); switch (event.getType()) { // If event type is NONE, this is a connection status change case None: { connectionEvent(event); break; } // Otherwise pass along to the listeners case NodeCreated: { for (ZooKeeperListener listener : listeners) { listener.nodeCreated(path); } break; } case NodeDeleted: { for (ZooKeeperListener listener : listeners) { listener.nodeDeleted(path); } break; } case NodeDataChanged: { for (ZooKeeperListener listener : listeners) { listener.nodeDataChanged(path); } break; } case NodeChildrenChanged: { for (ZooKeeperListener listener : listeners) { listener.nodeChildrenChanged(path); } break; } } }
From source file:com.example.directorio.ZooKeeperMannager.java
public String getData(String path2) throws InterruptedException, KeeperException, UnsupportedEncodingException { final String path = path2; Stat stat = znode_exists(path);//from w w w . j av a2 s .c o m byte[] b = null; if (stat != null) { b = zk.getData(path, new Watcher() { public void process(WatchedEvent we) { if (we.getType() == Event.EventType.None) { switch (we.getState()) { case Expired: zkConnection.getConnectedSignal().countDown(); break; } } else { try { byte[] bn = zk.getData(path, false, null); String data = new String(bn, "UTF-8"); System.out.println(data); zkConnection.getConnectedSignal().countDown(); } catch (Exception ex) { ex.printStackTrace(); } } } }, null); String data = new String(b, "UTF-8"); //System.out.println(data); zkConnection.getConnectedSignal().await(); } else { System.out.println("Node does not exists"); } return new String(b); }
From source file:com.facebook.zookeeper.election.TestZkLeaderElection.java
License:Apache License
@Test(groups = "fast") public void testEnter() throws Exception { // Verify no candidates MockWatcher mockWatcher = new MockWatcher(); List<String> candidates = zk1.getChildren(electionRoot, mockWatcher); Assert.assertTrue(candidates.isEmpty()); // Enter the candidate and run any callbacks zkLeaderElection1.enter();//from w w w. j a v a 2s . co m mockExecutor1.drain(); // Check that candidate is created candidates = zk1.getChildren(electionRoot, null); Assert.assertEquals(candidates.size(), 1); // Check that candidate is elected Assert.assertTrue(mockLeaderElectionCallback1.isElected()); mockLeaderElectionCallback1.resetElected(); Assert.assertEquals(zkLeaderElection1.getLeader(), candidates.get(0)); // Check data contents String data = VariablePayload.decode(zk1.getData(electionRoot + "/" + candidates.get(0), null, null)); Assert.assertEquals(data, testData1); // Check that external watch was notified of candidate creation Assert.assertEquals(mockWatcher.getEventQueue().size(), 1); WatchedEvent watchedEvent = mockWatcher.getEventQueue().remove(); Assert.assertEquals(watchedEvent.getType(), EventType.NodeChildrenChanged); Assert.assertEquals(watchedEvent.getPath(), electionRoot); }
From source file:com.facebook.zookeeper.election.TestZkLeaderElection.java
License:Apache License
@Test(groups = "fast") public void testWithdraw() throws Exception { zkLeaderElection1.enter();/*from w w w .j a v a 2 s . c om*/ mockExecutor1.drain(); // Verify candidate MockWatcher mockWatcher = new MockWatcher(); List<String> candidates = zk1.getChildren(electionRoot, mockWatcher); Assert.assertEquals(candidates.size(), 1); Assert.assertTrue(mockLeaderElectionCallback1.isElected()); mockLeaderElectionCallback1.resetElected(); zkLeaderElection1.withdraw(); mockExecutor1.drain(); candidates = zk1.getChildren(electionRoot, null); Assert.assertTrue(candidates.isEmpty()); Assert.assertEquals(zkLeaderElection1.getLeader(), null); // Manual withdraw should not trigger a "removed" callback Assert.assertFalse(mockLeaderElectionCallback1.isRemoved()); Assert.assertEquals(mockWatcher.getEventQueue().size(), 1); WatchedEvent watchedEvent = mockWatcher.getEventQueue().remove(); Assert.assertEquals(watchedEvent.getType(), EventType.NodeChildrenChanged); Assert.assertEquals(watchedEvent.getPath(), electionRoot); }
From source file:com.fjn.helper.frameworkex.apache.zookeeper.dispatcher.Dispatcher.java
License:Apache License
@Override public void process(WatchedEvent event) { event.getPath(); event.getState(); event.getType(); }