@param path
@param watcher

@return String

@throws InterruptedException
@throws KeeperException
@Description: 读数据
@author liaoqiqi
@date 2013-6-14
769122
public String read(String path, Watcher watcher, Stat stat) throws InterruptedException, KeeperException {

        byte[] data = zk.getData(path, watcher, stat);
        return new String(data, CHARSET);
    }
72666
public void getData(final String path, Watcher watcher, DataCallback cb,
            Object ctx) {
        verbotenThreadCheck();
        final String clientPath = path;
        PathUtils.validatePath(clientPath);

        // the watch contains the un-chroot path
        WatchRegistration wcb = null;
        if (watcher != null) {
            wcb = new DataWatchRegistration(watcher, clientPath);
        }

        final String serverPath = prependChroot(clientPath);

        RequestHeader h = new RequestHeader();
        h.setType(ZooDefs.OpCode.getData);
        GetDataRequest request = new GetDataRequest();
        request.setPath(serverPath);
        request.setWatch(watcher != null);
        GetDataResponse response = new GetDataResponse();
        cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
                clientPath, serverPath, ctx, wcb);
    }
260894
private boolean subscribe(String path, EventType watchType,
      long transactionId)
          throws TransactionIdTooOldException, InterruptedException {
    ServerHandler.Client server = connectionManager.getServer();
    NamespaceEvent event =  new NamespaceEvent(path, watchType.getByteValue());
    
    if (LOG.isDebugEnabled()) {
      LOG.debug(listeningPort + ": subscribe: Trying to subscribe for " +
          NotifierUtils.asString(event) + " ... from txId " + transactionId);
    }
    
    for (int retries = 0; retries < 3; retries ++) {
      try {
        server.subscribe(connectionManager.getId(), event, transactionId);
        if (LOG.isDebugEnabled()) {
          LOG.debug(listeningPort + ": subscribe: successful");
        }
        return true;
      } catch (TransactionIdTooOldException e) {
        LOG.warn(listeningPort + ": Failed to subscribe [1]", e);
        throw e;
      } catch (InvalidClientIdException e) {
        LOG.warn(listeningPort + ": Failed to subscribe [2]", e);
      } catch (TException e) {
        LOG.warn(listeningPort + ": Failed to subscribe [3]", e);
        Thread.sleep(1000);
      }
    }
    
    return false;
  }
1138128
private void processPartitionWatchEvent() throws KeeperException, InterruptedException {
        try {
            m_zk.create(m_rootNode, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
            m_zk.getData(m_rootNode, m_childWatch, null);
        } catch (KeeperException.NodeExistsException e) {
            m_zk.getData(m_rootNode, m_childWatch, null);
        }
    }
751843
public String getFinalReason(Path path) {

		StringBuilder sb = new StringBuilder(path + " cannot be modified; ");
		StringBuilder finalPath = new StringBuilder("/");

		// Step through the nodes based on the given path. If any intermediate
		// nodes are marked as final, we can just return true.
		Node currentNode = root;
		for (Term t : path.getTerms()) {
			finalPath.append(t.toString());
			Node nextNode = currentNode.getChild(t);
			if (nextNode == null) {
				return null;
			} else if (nextNode.isFinal()) {
				sb.append(finalPath.toString() + " is marked as final");
				return sb.toString();
			}
			finalPath.append("/");
			currentNode = nextNode;
		}

		// Strip off the last slash. It is not needed.
		finalPath.deleteCharAt(finalPath.length() - 1);

		// Either the path itself is final or a descendant.
		if (currentNode.isFinal()) {
			sb.append(finalPath.toString() + " is marked as final");
		} else if (currentNode.hasChild()) {
			sb.append(finalPath.toString()
					+ currentNode.getFinalDescendantPath()
					+ " is marked as final");
			return sb.toString();
		} else {
			return null;
		}

		return null;
	}
206809
public void getChildren(final String path, Watcher watcher,
            ChildrenCallback cb, Object ctx) {
        verbotenThreadCheck();
        final String clientPath = path;
        PathUtils.validatePath(clientPath);

        // the watch contains the un-chroot path
        WatchRegistration wcb = null;
        if (watcher != null) {
            wcb = new ChildWatchRegistration(watcher, clientPath);
        }

        final String serverPath = prependChroot(clientPath);

        RequestHeader h = new RequestHeader();
        h.setType(ZooDefs.OpCode.getChildren);
        GetChildrenRequest request = new GetChildrenRequest();
        request.setPath(serverPath);
        request.setWatch(watcher != null);
        GetChildrenResponse response = new GetChildrenResponse();
        cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
                clientPath, serverPath, ctx, wcb);
    }
312548
public URL getResource(String path) throws MalformedURLException {
		Result<URL,MalformedURLException> result = getResourceCache.get(path, getResourceRefresher);
		MalformedURLException exception = result.getException();
		if(exception != null) throw exception;
		return result.getValue();
	}
207393
@Override
  public ZKData<String> getZKStringData(String path) throws InterruptedException, KeeperException
  {
    return getZKStringData(path, null);
  }
691258
public static WatchMonitor createAll(Path path, Watcher watcher){
		final WatchMonitor watchMonitor = create(path, EVENTS_ALL);
		watchMonitor.setWatcher(watcher);
		return watchMonitor;
	}
1144691
function addWatcher(dirPath) {
    Debug._l(dirPath);
    Watcher(dirPath, function (filePath, action) {
        switch (action) {
            case Watcher.ADD_EVENT:
            case Watcher.CHANGE_EVENT:
                Debug._l(generateIdFromFilePath(filePath));
                generateCache(filePath);
                break;

            case Watcher.DELETE_EVENT:
                removeCache(generateIdFromFilePath(filePath));
                break;

        }
    });

}
1113719
public void watchPath(DisconfCoreProcessor disconfCoreMgr, DisConfCommonModel disConfCommonModel, String keyName,
                          DisConfigTypeEnum disConfigTypeEnum, String value) throws Exception {

        // 新建
        String monitorPath = makeMonitorPath(disConfigTypeEnum, disConfCommonModel, keyName, value);

        // 进行监控
        NodeWatcher nodeWatcher =
                new NodeWatcher(disconfCoreMgr, monitorPath, keyName, disConfigTypeEnum, new DisconfSysUpdateCallback(),
                        debug);
        nodeWatcher.monitorMaster();
    }
608052
@Override
  public Stat exists(String path) throws InterruptedException, KeeperException
  {
    return exists(path, false);
  }
320422
public boolean exists(String path) throws InterruptedException, KeeperException {

        int retries = 0;
        while (true) {

            try {

                Stat stat = zk.exists(path, false);

                if (stat == null) {

                    return false;

                } else {

                    return true;
                }

            } catch (KeeperException.SessionExpiredException e) {

                throw e;

            } catch (KeeperException e) {

                LOGGER.warn("exists connect lost... will retry " + retries + "\t" + e.toString());

                if (retries++ == MAX_RETRIES) {
                    LOGGER.error("connect final failed");
                    throw e;
                }

                // sleep then retry
                int sec = RETRY_PERIOD_SECONDS * retries;
                LOGGER.warn("sleep " + sec);
                TimeUnit.SECONDS.sleep(sec);
            }
        }
    }
48026
static void mkdirp(ZooKeeper zookeeper, String znode) throws KeeperException, InterruptedException {
        boolean createPath = false;
        for (String path : pathParts(znode)) {
            if (!createPath) {
                Stat stat = zookeeper.exists(path, false);
                if (stat == null) {
                    createPath = true;
                }
            }
            if (createPath) {
                create(zookeeper, path);
            }
        }
    }
452473
public static Runnable watch(Path path, PathEventListener listener, WatchEvent.Kind<?>... kinds) throws IOException {
		synchronized (FileSystemWatcher.class) {
			Application app = LCCore.getApplication();
			Watcher watcher = app.getInstance(Watcher.class);
			if (watcher == null || watcher.stop) {
				watcher = new Watcher(app);
				app.setInstance(Watcher.class, watcher);
			}
			return watcher.watch(path, listener, kinds);
		}
	}
671070
function setupWatchers(path) {
    // We want to track the watchers now and return if we are already watching this folder
    if (watchingFolders[path]) { return; }

    watchingFolders[path] = fs.watch(path, getWatcher(path + "/"));
    watchingFolders[path].on('error', function() {  verifyWatches(); });
    var fileList = fs.readdirSync(path);
    var stats;
    for (var i = 0; i < fileList.length; i++) {
        try {
            stats = fs.statSync(path + "/" + fileList[i]);
        }
        catch (e) {
            continue;
        }
        if (isWatching(fileList[i])) {
            timeStamps[path + "/" + fileList[i]] = stats.mtime.getTime();
        } else {
            if (stats.isDirectory()) {
                if (fileList[i] === "node_modules") {
                    watchingFolders[path + "/" + fileList[i]] = true;
                    continue;
                }
                if (fileList[i] === "tns_modules") {
                    watchingFolders[path + "/" + fileList[i]] = true;
                    continue;
                }
                if (fileList[i] === "App_Resources") {
                    watchingFolders[path + "/" + fileList[i]] = true;
                    continue;
                }
                setupWatchers(path + "/" + fileList[i]);
            }
        }
    }
}
864509
private String getStringResource(String path) {
    	InputStream in = getClass().getResourceAsStream(path);
    	
    	StringBuilder index = new StringBuilder();
    	char[] buffer = new char[1024];
    	int read = 0;
    	try(InputStreamReader reader = new InputStreamReader(in)){
    		while((read = reader.read(buffer)) != -1) {
    			index.append(buffer, 0, read);
    		}
    	} catch (IOException e) {
    		//just return what we've got
    		return index.toString();
    	}
    	return index.toString();
    }