我是ZooKeeper的新手。
static zhandle_t *zh;
static void data_watcher(zhandle_t *wzh, int type, int state, const char * zpath, void *watcher_ctx)
{
char *zoo_data = malloc(ZDATALEN * sizeof(char));
int zoo_data_len = ZDATALEN;
if (state == ZOO_CONNECTED_STATE)
{
if (type == ZOO_CHANGED_EVENT)
{
// Which zh to use here? wzh or zh?
zoo_wget(wzh, zoo_path, data_watcher, (void *)watcher_ctx, zoo_data, &zoo_data_len, NULL);
fprintf(stderr, "!!! Data Change Detected\n");
fprintf(stderr, "%s\n", zoo_data);
}
}
}
int main ()
{
zh = zookeeper_init(host_port, connection_watcher, 2000, 0, 0, 0);
...
zoo_wget(zh, zoo_path, data_watcher, watcher_ctx, zdata_buf, &zdata_len, NULL)
}
如上所示,我在这里感到疑惑的是,在观察者回调函数中使用哪个zookeeper处理?为什么?非常感谢你的时间。