Permalink
Browse files

add awexists.lua

  • Loading branch information...
1 parent b03f354 commit e07175b3721f933811f587c3fe2b84910a3f1b63 @forhappy committed Apr 12, 2013
Showing with 31 additions and 0 deletions.
  1. +31 −0 examples/awexists.lua
View
31 examples/awexists.lua
@@ -0,0 +1,31 @@
+require "zklua"
+
+function zklua_my_global_watcher(zh, type, state, path, watcherctx)
+ if type == zklua.ZOO_SESSION_EVENT then
+ if state == zklua.ZOO_CONNECTED_STATE then
+ print("Connected to zookeeper service successfully!\n");
+ elseif (state == ZOO_EXPIRED_SESSION_STATE) then
+ print("Zookeeper session expired!\n");
+ end
+ end
+end
+
+function zklua_my_local_watcher(zh, type, state, path, watcherctx)
+ print("zklua_my_local_watcher(".."type: "..type..", state: "..state..", path: "..path..")")
+ print("zklua_my_local_watcher(".."watcherctx: "..watcherctx..")")
+end
+
+function zklua_my_stat_completion(rc, stat, data)
+ print("zklua_my_stat_completion:\n")
+ print("rc: "..rc.."\tdata: "..data)
+end
+
+zklua.set_log_stream("zklua.log")
+
+zh = zklua.init("127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183", zklua_my_global_watcher, 10000)
+
+ret = zklua.awexists(zh, "/zklua", zklua_my_local_watcher,"zklua_my_local_watcher", zklua_my_stat_completion, "zklua aexists.")
+print("zklua.aexists ret: "..ret)
+
+print("hit any key to continue...")
+io.read()

0 comments on commit e07175b

Please sign in to comment.