List of usage examples for org.apache.zookeeper WatchedEvent getState
public KeeperState getState()
From source file:edu.uci.ics.asterix.event.service.ZooKeeperService.java
License:Apache License
public void process(WatchedEvent wEvent) { switch (wEvent.getState()) { case SyncConnected: msgQ.add("connected"); break;/* www .jav a2s . c o m*/ } }
From source file:fr.ens.biologie.genomique.eoulsan.util.locker.ZooKeeperLocker.java
License:LGPL
@Override public void process(final WatchedEvent event) { if (event.getState() == KeeperState.SyncConnected) { this.response = true; }/*from w ww . j a v a 2s.co m*/ }
From source file:gr.ntua.h2rdf.client.Executor.java
License:Open Source License
public void process(WatchedEvent event) { //System.out.println("message"); String path = event.getPath(); if (event.getType() == Event.EventType.None) { // We are are being told that the state of the // connection has changed switch (event.getState()) { case SyncConnected: // In this particular example we don't need to do anything // here - watches are automatically re-registered with // server and any watches triggered while the client was // disconnected will be delivered (in order of course) break; case Expired: try { zk.close();//w w w .ja v a 2 s . c o m zk = new ZooKeeper(conf.getAddress(), 3000, this); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; } } else { if (path.equals(filename) && (event.getType() == Event.EventType.NodeCreated)) { // It's all over System.out.println("Finished "); try { dead = true; Stat stat = null; outfile = Bytes.toString(zk.getData(filename, false, stat)); //System.out.println(outfile +"dfsdfsd"); zk.delete(filename, 0); synchronized (this) { notifyAll(); } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (KeeperException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } /*if (event.getType() == Event.EventType.None) { // We are are being told that the state of the // connection has changed switch (event.getState()) { case SyncConnected: // In this particular example we don't need to do anything // here - watches are automatically re-registered with // server and any watches triggered while the client was // disconnected will be delivered (in order of course) break; case Expired: // It's all over dead=true; synchronized (this) { notifyAll(); } break; } } else { if (path != null && path.equals(filename)) { // Something has changed on the node, let's find out zk.exists(filename, true, this, null); } }*/ }
From source file:gr.ntua.h2rdf.client.ExecutorOpenRdf.java
License:Open Source License
public void process(WatchedEvent event) { //System.out.println("message"); String path = event.getPath(); if (event.getType() == Event.EventType.None) { // We are are being told that the state of the // connection has changed switch (event.getState()) { case SyncConnected: // In this particular example we don't need to do anything // here - watches are automatically re-registered with // server and any watches triggered while the client was // disconnected will be delivered (in order of course) break; case Expired: try { zk.close();// w ww. j a va2 s . c o m zk = new ZooKeeper(conf.getAddress(), 3000, this); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; } } else { if (path.equals(filename) && (event.getType() == Event.EventType.NodeCreated)) { // It's all over //System.out.println("Finished "); try { dead = true; Stat stat = null; outfile = Bytes.toString(zk.getData(filename, false, stat)); //System.out.println(outfile +"dfsdfsd"); zk.delete(filename, 0); synchronized (this) { notifyAll(); } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (KeeperException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } /*if (event.getType() == Event.EventType.None) { // We are are being told that the state of the // connection has changed switch (event.getState()) { case SyncConnected: // In this particular example we don't need to do anything // here - watches are automatically re-registered with // server and any watches triggered while the client was // disconnected will be delivered (in order of course) break; case Expired: // It's all over dead=true; synchronized (this) { notifyAll(); } break; } } else { if (path != null && path.equals(filename)) { // Something has changed on the node, let's find out zk.exists(filename, true, this, null); } }*/ }
From source file:gr.ntua.h2rdf.concurrent.SyncPrimitive.java
License:Open Source License
synchronized public void process(WatchedEvent event) { synchronized (mutex) { //System.out.println("Process: " + event.getType()); mutex.notify();//from w w w . j a va 2 s .co m } if (event.getType() == Event.EventType.None) { // We are are being told that the state of the // connection has changed switch (event.getState()) { case SyncConnected: // In this particular example we don't need to do anything // here - watches are automatically re-registered with // server and any watches triggered while the client was // disconnected will be delivered (in order of course) break; case Expired: try { zk.close(); zk = new ZooKeeper(address, 3000, this); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; } } }
From source file:herddb.client.ZookeeperClientSideMetadataProvider.java
License:Apache License
public ZookeeperClientSideMetadataProvider(String zkAddress, int zkSessionTimeout, String basePath) { this(basePath, () -> { try {//from ww w.j ava 2 s. c o m CountDownLatch waitForConnection = new CountDownLatch(1); ZooKeeper zk = new ZooKeeper(zkAddress, zkSessionTimeout, new Watcher() { @Override @SuppressFBWarnings(value = "SF_SWITCH_NO_DEFAULT") public void process(WatchedEvent event) { LOG.log(Level.SEVERE, "zk client event " + event); switch (event.getState()) { case SyncConnected: case ConnectedReadOnly: waitForConnection.countDown(); break; } } }); boolean waitResult = waitForConnection.await(zkSessionTimeout * 2L, TimeUnit.SECONDS); return zk; } catch (Exception err) { LOG.log(Level.SEVERE, "zk client error " + err, err); return null; } }); this.ownZooKeeper = true; }
From source file:herddb.cluster.ZookeeperMetadataStorageManager.java
License:Apache License
private synchronized void restartZooKeeper() throws IOException, InterruptedException { ZooKeeper old = zooKeeper;//from w w w.j a va 2 s . co m if (old != null) { old.close(); } CountDownLatch firstConnectionLatch = new CountDownLatch(1); ZooKeeper zk = new ZooKeeper(zkAddress, zkSessionTimeout, new Watcher() { @Override public void process(WatchedEvent event) { switch (event.getState()) { case SyncConnected: case SaslAuthenticated: firstConnectionLatch.countDown(); notifyMetadataChanged(); break; default: // ignore break; } } }); if (!firstConnectionLatch.await(zkSessionTimeout, TimeUnit.SECONDS)) { zk.close(); throw new IOException( "Could not connect to zookeeper at " + zkAddress + " within " + zkSessionTimeout + " ms"); } this.zooKeeper = zk; LOGGER.info("Connected to ZK " + zk); }
From source file:herddb.cluster.ZookeeperMetadataStorageManagerTest.java
License:Apache License
private void expireZkSession(long sessionId, byte[] passwd) throws InterruptedException, IOException { CountDownLatch waitConnection = new CountDownLatch(1); try (ZooKeeper zooKeeper = new ZooKeeper(testEnv.getAddress(), testEnv.getTimeout(), new Watcher() { @Override// w w w . j a v a2 s . com public void process(WatchedEvent event) { switch (event.getState()) { case SyncConnected: waitConnection.countDown(); break; } } }, sessionId, passwd)) { assertTrue(waitConnection.await(1, TimeUnit.MINUTES)); } }
From source file:hws.util.ZkDataMonitor.java
License:Apache License
public ZkClient(String serverAddr, int sessionTimeout) throws IOException, InterruptedException { final CountDownLatch connectedSignal = new CountDownLatch(1); this.zk = new ZooKeeper(serverAddr, sessionTimeout, new Watcher() { @Override/* ww w . j av a2s. com*/ public void process(WatchedEvent event) { if (event.getState() == Watcher.Event.KeeperState.SyncConnected) { connectedSignal.countDown(); } } }); connectedSignal.await(); }
From source file:io.confluent.admin.utils.ZookeeperConnectionWatcher.java
License:Apache License
@Override public void process(WatchedEvent event) { if (event.getType() == Event.EventType.None) { switch (event.getState()) { case SyncConnected: // If SASL is enabled, we want to wait for the SaslAuthenticated event. if (!isSASLEnabled) { connectSignal.countDown(); }/*w ww . j av a 2 s .c om*/ break; case Expired: failureMessage = "Session expired."; isSuccessful = false; connectSignal.countDown(); break; case Disconnected: failureMessage = "Disconnected from the server."; isSuccessful = false; connectSignal.countDown(); break; case AuthFailed: failureMessage = "Authentication failed."; isSuccessful = false; connectSignal.countDown(); break; case SaslAuthenticated: connectSignal.countDown(); break; } } }