普遍模型-lin总线协议2.1

4.3普遍模型我们进入主-从模式例子的章节之前,先看一些ZooKeeper的应用中使用的通用代码的模型: 1.进行调用异步。 2.实现回调对象,并传入异步调用函数中。 3.如果操作需要设置监视点,实现一个Watcher对象,并传入异步调用函数中。以下为exists的异步调用的示例代码: zk.exists("/myZnode",① myWatcher, existsCallback, null); Watcher myWatcher = new Watcher() {② public void process(WatchedEvent e) { // Process the watch event } } StatCallback existsCallback = new StatCallback() {③ public void processResult(int rc, String path, Object ctx, Stat stat) { // Process the result of the exists call } };
pdf 文件大小:4.47MB