From a75fff7251f44c334b492350316a46a11755d490 Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Mon, 24 Nov 2014 11:44:15 +0000 Subject: added recursive child discovery to the system infinate levels may now be discovered correctly --- ZKTest/src/ZKTest.cpp | 77 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 23 deletions(-) (limited to 'ZKTest/src/ZKTest.cpp') diff --git a/ZKTest/src/ZKTest.cpp b/ZKTest/src/ZKTest.cpp index 7e22c21..7fd87a0 100644 --- a/ZKTest/src/ZKTest.cpp +++ b/ZKTest/src/ZKTest.cpp @@ -7,6 +7,8 @@ //============================================================================ #include +#include +#include #include #include #include @@ -18,13 +20,15 @@ using namespace std; static zhandle_t *zk; static const clientid_t *session_id; -struct String_vector *list_of_children; +struct String_vector list_of_children = {0}; int timeout = 3000; int responseCode = 0; +std::mutex mutex_lock; void safeShutdown(zhandle_t *zzh); void watcher(zhandle_t *zzh, int type, int state, const char *path, void *watcherCtx); +void discoverChildren(const char* path); int main(int argc, char **argv) { @@ -49,10 +53,20 @@ int main(int argc, char **argv) while (zk) { - + /* + * mutex used to make the main program loop wait until there is feedback + * from zookeeper. initially locks, then loops around. thread cannot lock + * again until the current lock has been unlocked. + */ + mutex_lock.lock(); + + /* + * debug test to show that the loop does not continue until watcher + * is called + */ + std::cout<<"loop locked"<count; i++) - { - std::cout<count<data[i] , true, NULL); - } - } + std::cout<