サンプルコード
@Grab(group='org.apache.zookeeper', module='zookeeper', version='3.4.6') import org.apache.zookeeper.* import org.apache.zookeeper.data.* def zk = new ZooKeeper("localhost:2181", 3000, null) def path = "/lock" def lock = new Object() try { while(true){ def stat = zk.exists(path, new Watcher(){ public void process(WatchedEvent event){ synchronized(lock){ lock.notifyAll() } } }); if( stat == null ){ synchronized(lock){ lock.wait() } } else { break } } } catch(InterruptedException iex) { throw iex } finally { zk.close() }動作環境
groovy 2.3.6, JDK 7 Update 65, Hadoop 2.5.0, zookeeper 3.4.6
0 件のコメント:
コメントを投稿