@Override public void eventReceived(CuratorFramework _fk, CuratorEvent e) throws Exception { if (e.getType().equals(CuratorEventType.WATCHED)) { WatchedEvent event = e.getWatchedEvent(); watcher.execute(event.getState(), event.getType(), event.getPath()); } } });
public void setData(String path, Object obj) { path = "/" + path; byte[] ser = _ser.serializeObject(obj); try { if(_curator.checkExists().forPath(path)!=null) { _curator.setData().forPath(path, ser); } else { _curator.create() .creatingParentsIfNeeded() .withMode(CreateMode.PERSISTENT) .forPath(path, ser); } } catch(Exception e) { throw new RuntimeException(e); } }
public byte[] getData(CuratorFramework zk, String path, boolean watch) throws Exception { String npath = PathUtils.normalize_path(path); try { if (existsNode(zk, npath, watch)) { if (watch) { return zk.getData().watched().forPath(npath); } else { return zk.getData().forPath(npath); } } } catch (KeeperException e) { LOG.error("zookeeper getdata for path" + path, e); } return null; }
public String call() throws Exception { return transport.getZKHandle().create() .creatingParentsIfNeeded() .withMode(CreateMode.EPHEMERAL) .forPath(memberpath); } });
protected TransactionalState(Map conf, String id, Map componentConf, String subroot) { try { conf = new HashMap(conf); // ensure that the serialization registrations are consistent with the declarations in this spout if(componentConf!=null) { conf.put(Config.TOPOLOGY_KRYO_REGISTER, componentConf .get(Config.TOPOLOGY_KRYO_REGISTER)); } String rootDir = conf.get(Config.TRANSACTIONAL_ZOOKEEPER_ROOT) + "/" + id + "/" + subroot; List<String> servers = (List<String>) getWithBackup(conf, Config.TRANSACTIONAL_ZOOKEEPER_SERVERS, Config.STORM_ZOOKEEPER_SERVERS); Object port = getWithBackup(conf, Config.TRANSACTIONAL_ZOOKEEPER_PORT, Config.STORM_ZOOKEEPER_PORT); CuratorFramework initter = Utils.newCuratorStarted(conf, servers, port); try { initter.create().creatingParentsIfNeeded().forPath(rootDir); } catch(KeeperException.NodeExistsException e) { } initter.close(); _curator = Utils.newCuratorStarted(conf, servers, port, rootDir); _ser = new KryoValuesSerializer(conf); _des = new KryoValuesDeserializer(conf); } catch (Exception e) { throw new RuntimeException(e); } }
private synchronized void sync(boolean watched) throws Exception { if ( watched ) { client.getChildren().usingWatcher(watcher).inBackground(callback).forPath(path); } else { client.getChildren().inBackground(callback).forPath(path); } }
public void delete(String path) { path = "/" + path; try { _curator.delete().forPath(path); } catch (Exception e) { throw new RuntimeException(e); } }
public Stat setData(CuratorFramework zk, String path, byte[] data) throws Exception { String npath = PathUtils.normalize_path(path); return zk.setData().forPath(npath, data); }
@Override public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { applyNewData(fullPath, event.getResultCode(), event.getStat(), event.getData()); } };
private void deleteOurPath(String ourPath) throws Exception { try { client.delete().guaranteed().forPath(ourPath); } catch ( KeeperException.NoNodeException e ) { // ignore - already deleted (possibly expired session, etc.) } }
@Override public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { applyNewData(fullPath, event.getResultCode(), event.getStat(), null); } };
@Override public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { setNewChildren(event.getChildren()); } };
@Override public Void apply(UnhandledErrorListener listener) { listener.unhandledError(localReason, e); return null; } }
public void deleteNode(CuratorFramework zk, String path) throws Exception { zk.delete().forPath(PathUtils.normalize_path(path)); }
@Override public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { processChildren(event.getChildren(), mode); } };