List of usage examples for org.apache.zookeeper Watcher Watcher
Watcher
From source file:org.apache.blur.manager.clusterstatus.ZookeeperClusterStatus.java
License:Apache License
public ZookeeperClusterStatus(String connectionStr, BlurConfiguration configuration, Configuration config) throws IOException { this(new ZooKeeper(connectionStr, 30000, new Watcher() { @Override/*from w w w . ja va 2 s .c om*/ public void process(WatchedEvent event) { } }), configuration, config); }
From source file:org.apache.blur.manager.clusterstatus.ZookeeperClusterStatusTest.java
License:Apache License
@Before public void setup() throws KeeperException, InterruptedException, IOException { zooKeeper1 = new ZooKeeperClient(miniCluster.getZkConnectionString(), 30000, new Watcher() { @Override//from w ww . ja va 2 s . c o m public void process(WatchedEvent event) { } }); BlurUtil.setupZookeeper(zooKeeper1, DEFAULT); zooKeeper2 = new ZooKeeperClient(miniCluster.getZkConnectionString(), 30000, new Watcher() { @Override public void process(WatchedEvent event) { } }); BlurUtil.setupZookeeper(zooKeeper1, DEFAULT); BlurUtil.setupZookeeper(zooKeeper2, DEFAULT); clusterStatus1 = new ZookeeperClusterStatus(zooKeeper1); clusterStatus2 = new ZookeeperClusterStatus(zooKeeper2); }
From source file:org.apache.blur.manager.indexserver.MasterBasedDistributedLayoutFactoryTest.java
License:Apache License
@Before public void setup() throws IOException, KeeperException, InterruptedException { _zooKeeper = new ZooKeeperClient(miniCluster.getZkConnectionString(), 50000, new Watcher() { @Override//from w ww .j a va 2 s . c o m public void process(WatchedEvent event) { } }); rmr(_zooKeeper, "/blur"); }
From source file:org.apache.blur.manager.indexserver.SafeModeTest.java
License:Apache License
@Before public void setup() throws IOException { zk = new ZooKeeperClient(miniCluster.getZkConnectionString(), 20000, new Watcher() { @Override// w w w . j a v a 2 s. c om public void process(WatchedEvent event) { } }); }
From source file:org.apache.blur.manager.indexserver.SafeModeTest.java
License:Apache License
@Test public void testExtraNodeStartup() throws IOException, InterruptedException, KeeperException { ZooKeeper zk = new ZooKeeper(miniCluster.getZkConnectionString(), 20000, new Watcher() { @Override//from www . j a va 2 s .co m public void process(WatchedEvent event) { } }); SafeMode setupSafeMode = new SafeMode(zk, "/testing/safemode", "/testing/nodepath", TimeUnit.SECONDS, 5, TimeUnit.SECONDS, 60, 0); setupSafeMode.registerNode("node1", null); SafeMode safeMode = new SafeMode(zk, "/testing/safemode", "/testing/nodepath", TimeUnit.SECONDS, 5, TimeUnit.SECONDS, 60, 0); long s = System.nanoTime(); safeMode.registerNode("node101", null); long e = System.nanoTime(); assertTrue((e - s) < TimeUnit.SECONDS.toNanos(1)); zk.close(); }
From source file:org.apache.blur.manager.indexserver.SafeModeTest.java
License:Apache License
@Test public void testSecondNodeStartup() throws IOException, InterruptedException, KeeperException { ZooKeeper zk = new ZooKeeper(miniCluster.getZkConnectionString(), 20000, new Watcher() { @Override/* w ww . j a v a2 s . c om*/ public void process(WatchedEvent event) { } }); SafeMode setupSafeMode = new SafeMode(zk, "/testing/safemode", "/testing/nodepath", TimeUnit.SECONDS, 5, TimeUnit.SECONDS, 60, 0); setupSafeMode.registerNode("node10", null); SafeMode safeMode = new SafeMode(zk, "/testing/safemode", "/testing/nodepath", TimeUnit.SECONDS, 5, TimeUnit.SECONDS, 15, 0); try { safeMode.registerNode("node10", null); fail("should throw exception."); } catch (Exception e) { } zk.close(); }
From source file:org.apache.blur.MiniCluster.java
License:Apache License
public String getControllerConnectionStr() { String zkConnectionString = zkMiniCluster.getZkConnectionString(); ZooKeeper zk;// w ww . j av a 2s. c o m try { zk = new ZooKeeperClient(zkConnectionString, 30000, new Watcher() { @Override public void process(WatchedEvent event) { } }); } catch (IOException e) { throw new RuntimeException(e); } String onlineControllersPath = ZookeeperPathConstants.getOnlineControllersPath(); try { List<String> children = zk.getChildren(onlineControllersPath, false); StringBuilder builder = new StringBuilder(); for (String s : children) { if (builder.length() != 0) { builder.append(','); } builder.append(s); } return builder.toString(); } catch (KeeperException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } finally { try { zk.close(); } catch (InterruptedException e) { LOG.error("Unkown error while trying to close ZooKeeper client.", e); } } }
From source file:org.apache.blur.MiniCluster.java
License:Apache License
private MiniClusterServer toMiniClusterServerInternal(int serverIndex, TYPE type, final BlurConfiguration configuration) { final ThriftServer thriftServer; try {/*from www . jav a2s. co m*/ thriftServer = getThriftServer(serverIndex, type, configuration); } catch (Exception e) { throw new RuntimeException(e); } return new MiniClusterServer() { @Override public void close() throws IOException { thriftServer.close(); } @Override public void kill() { ZooKeeper zk = null; try { int shardPort = ThriftServer.getBindingPort(thriftServer.getServerTransport()); String nodeNameHostname = ThriftServer.getNodeName(configuration, BLUR_SHARD_HOSTNAME); String nodeName = nodeNameHostname + ":" + shardPort; zk = new ZooKeeperClient(getZkConnectionString(), 30000, new Watcher() { @Override public void process(WatchedEvent event) { } }); String onlineShardsPath = ZookeeperPathConstants .getOnlineShardsPath(org.apache.blur.utils.BlurConstants.BLUR_CLUSTER); String path = onlineShardsPath + "/" + nodeName; zk.delete(path, -1); zk.close(); } catch (Exception e) { throw new RuntimeException(e); } finally { if (zk != null) { try { zk.close(); } catch (InterruptedException e) { LOG.error("Unknown error while trying to close ZooKeeper client.", e); } } } } @Override public void start() { try { thriftServer.start(); } catch (TTransportException e) { LOG.error(e); throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } @Override public void waitUntilOnline() { while (true) { try { Thread.sleep(50); } catch (InterruptedException e) { return; } int localPort = ThriftServer.getBindingPort(thriftServer.getServerTransport()); if (localPort == 0) { continue; } else { try { Thread.sleep(500); } catch (InterruptedException e) { LOG.error("Unknown error", e); } return; } } } }; }
From source file:org.apache.blur.shell.RemoveShardServerCommand.java
License:Apache License
@Override public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException, TException, BlurException { if (args.length != 2) { throw new CommandException("Invalid args: " + help()); }//w w w. ja va 2 s. c om ZooKeeper zooKeeper = null; try { try { BlurConfiguration configuration = new BlurConfiguration(); String connectString = configuration.get(BlurConstants.BLUR_ZOOKEEPER_CONNECTION); int sessionTimeout = configuration.getInt(BlurConstants.BLUR_ZOOKEEPER_TIMEOUT, 30000); zooKeeper = new ZooKeeper(connectString, sessionTimeout, new Watcher() { @Override public void process(WatchedEvent event) { } }); } catch (IOException e) { if (Main.debug) { e.printStackTrace(); } throw new CommandException(e.getMessage()); } String node = args[1]; out.println("Are you sure you want to remove the shard server [" + node + "]? [y/N]"); out.flush(); ConsoleReader reader = getConsoleReader(); try { int readCharacter = reader.readCharacter(); if (!(readCharacter == 'y' || readCharacter == 'Y')) { return; } } catch (IOException e) { if (Main.debug) { e.printStackTrace(); } throw new CommandException(e.getMessage()); } String path = "/blur/clusters/" + Main.getCluster(client) + "/online-nodes/" + node; zooKeeper.delete(path, -1); } catch (InterruptedException e) { if (Main.debug) { e.printStackTrace(); } throw new CommandException(e.getMessage()); } catch (KeeperException e) { if (Main.debug) { e.printStackTrace(); } throw new CommandException(e.getMessage()); } finally { if (zooKeeper != null) { try { zooKeeper.close(); } catch (InterruptedException e) { if (Main.debug) { e.printStackTrace(); } } } } }
From source file:org.apache.blur.trace.ZooKeeperDumpContents.java
License:Apache License
public static void main(String[] args) throws IOException, KeeperException, InterruptedException { BlurConfiguration configuration = new BlurConfiguration(); String zkConnectionStr = configuration.get(BLUR_ZOOKEEPER_CONNECTION); ZooKeeper zooKeeper = new ZooKeeper(zkConnectionStr, 30000, new Watcher() { @Override//from w w w .ja v a 2 s . c o m public void process(WatchedEvent event) { } }); String parentPath = configuration.get(BLUR_ZOOKEEPER_TRACE_PATH); String id = args[0]; String path = parentPath + "/" + id; List<String> children = zooKeeper.getChildren(path, false); System.out.println("["); boolean first = true; for (String c : children) { if (!first) { System.out.println(","); } Stat stat = zooKeeper.exists(path + "/" + c, false); byte[] data = zooKeeper.getData(path + "/" + c, false, stat); String string = new String(data); System.out.println(string); first = false; } System.out.println("]"); zooKeeper.close(); }