/* session expiration is handled for us (and a new session created) */ void my_watcher(zhandle_t *zzh, int type, int state, const char *path) { session_context *context = (session_context *)zoo_get_context(zzh); int rc; if (type != ZOO_SESSION_EVENT) { info("%d %d %s", type, state, path); rc = zoo_aget_children(zzh, context->path, 1, strings_completion, NULL); if (rc) warn("Failed to list path"); } else { if (is_connected(zzh)) { watcher_data *wdata = (watcher_data *)context->data; if (!wdata->following) { rc = zoo_aget_children(zzh, context->path, 1, strings_completion, NULL); if (rc) warn("Failed to list path"); else wdata->following = 1; } } } }
/* session expiration is handled for us (and a new session created) */ static void watcher(zhandle_t *zzh, int type, int state, const char *ppath) { char *path; session_context *context = (session_context *)zoo_get_context(zzh); int rc; path = (char *)clients_context_get_arg(context, "path"); if (type != ZOO_SESSION_EVENT) { info("%d %d %s", type, state, path); rc = zoo_aget(zzh, path, 1, get_cb, NULL); if (rc) warn("Failed to get path"); return; } if (is_connected(zzh)) { watcher_data *data = (watcher_data *)clients_context_data(context); if (!data->following) { rc = zoo_aget(zzh, path, 1, get_cb, NULL); if (rc) warn("Failed to get path"); else data->following = 1; } } }
/* session expiration is handled for us (and a new session created) */ void my_watcher(zhandle_t *zzh, int type, int state, const char *path) { session_context *context; watcher_data *wdata; int rc; if (type != ZOO_SESSION_EVENT) return; if (state == ZOO_CONNECTED_STATE) { context = (session_context *)zoo_get_context(zzh); wdata = (watcher_data *)context->data; if (!wdata->created) { int flags = ZOO_EPHEMERAL|ZOO_SEQUENCE; rc = zoo_acreate(zzh, context->path, "test", 4, &ZOO_OPEN_ACL_UNSAFE, flags, create_cb, NULL); if (rc) warn("Failed to create path"); else wdata->created = 1; } } }
static void watcher(zhandle_t *zh, int type, int state, const char *path, void* context) { VALUE self, watcher_id; return; // watchers don't work in ruby yet self = (VALUE)zoo_get_context(zh);; watcher_id = rb_intern("watcher"); fprintf(stderr,"C watcher %d state = %d for %s.\n", type, state, (path ? path: "null")); rb_funcall(self, watcher_id, 3, INT2FIX(type), INT2FIX(state), rb_str_new2(path)); }
static int destroy_zkrb_instance(struct zkrb_instance_data* ptr) { int rv = ZOK; if (ptr->zh) { const void *ctx = zoo_get_context(ptr->zh); /* Note that after zookeeper_close() returns, ZK handle is invalid */ rv = zookeeper_close(ptr->zh); free((void *) ctx); } #warning [wickman] TODO: fire off warning if queue is not empty if (ptr->queue) zkrb_queue_free(ptr->queue); ptr->zh = NULL; ptr->queue = NULL; return rv; }
static int destroy_zkrb_instance(struct zkrb_instance_data* ptr) { int rv = ZOK; if (ptr->zh) { const void *ctx = zoo_get_context(ptr->zh); /* Note that after zookeeper_close() returns, ZK handle is invalid */ zkrb_debug("obj_id: %lx, calling zookeeper_close", ptr->object_id); rv = zookeeper_close(ptr->zh); zkrb_debug("obj_id: %lx, zookeeper_close returned %d", ptr->object_id, rv); free((void *) ctx); } #warning [wickman] TODO: fire off warning if queue is not empty if (ptr->queue) { zkrb_debug("obj_id: %lx, freeing queue pointer: %p", ptr->object_id, ptr->queue); zkrb_queue_free(ptr->queue); } ptr->zh = NULL; ptr->queue = NULL; return rv; }
static int destroy_zkrb_instance(zkrb_instance_data_t* zk) { int rv = ZOK; zkrb_debug("destroy_zkrb_instance, zk_local_ctx: %p, zh: %p, queue: %p", zk, zk->zh, zk->queue); if (zk->zh) { const void *ctx = zoo_get_context(zk->zh); /* Note that after zookeeper_close() returns, ZK handle is invalid */ zkrb_debug("obj_id: %lx, calling zookeeper_close", zk->object_id); if (we_are_forked(zk)) { zkrb_debug("FORK DETECTED! orig_pid: %d, current pid: %d, " "using socket-closing hack before zookeeper_close", zk->orig_pid, getpid()); int fd = ((int *)zk->zh)[0]; // nasty, brutish, and wonderfully effective hack (see above) close(fd); } rv = zookeeper_close(zk->zh); zkrb_debug("obj_id: %lx, zookeeper_close returned %d, calling context: %p", zk->object_id, rv, ctx); zkrb_calling_context_free((zkrb_calling_context *) ctx); } zk->zh = NULL; if (zk->queue) { zkrb_debug("obj_id: %lx, freeing queue pointer: %p", zk->object_id, zk->queue); zkrb_queue_free(zk->queue); } zk->queue = NULL; return rv; }