From 42ce237c358538046c7ec68a919023276a0744fb Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Mon, 24 Nov 2014 18:07:21 +0000 Subject: now follows specified config file --- ZKTest/Debug/ZKTest | Bin 132947 -> 140071 bytes ZKTest/Debug/src/ZKTest.o | Bin 250712 -> 259776 bytes ZKTest/src/ZKTest.cpp | 81 +++++++++++++++++++++++++++++++++++++++------- 3 files changed, 70 insertions(+), 11 deletions(-) diff --git a/ZKTest/Debug/ZKTest b/ZKTest/Debug/ZKTest index be25bfa..d9d17c1 100755 Binary files a/ZKTest/Debug/ZKTest and b/ZKTest/Debug/ZKTest differ diff --git a/ZKTest/Debug/src/ZKTest.o b/ZKTest/Debug/src/ZKTest.o index df5a147..11cfd6d 100644 Binary files a/ZKTest/Debug/src/ZKTest.o and b/ZKTest/Debug/src/ZKTest.o differ diff --git a/ZKTest/src/ZKTest.cpp b/ZKTest/src/ZKTest.cpp index 7fd87a0..07a2307 100644 --- a/ZKTest/src/ZKTest.cpp +++ b/ZKTest/src/ZKTest.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -20,23 +21,64 @@ using namespace std; static zhandle_t *zk; static const clientid_t *session_id; +char* nodeType = "default"; struct String_vector list_of_children = {0}; int timeout = 3000; int responseCode = 0; std::mutex mutex_lock; void safeShutdown(zhandle_t *zzh); +void configure(); +void configurationwatcher(zhandle_t *zzh, int type, int state, const char *path, + void *watcherCtx); 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) { + /* + * checking to see if the host entered as the second argument is valid + * if no host is entered the program will default to local host + */ + char* hosts; + char* check = "localhost"; + char* check2 = ":"; + if(argc >1) + { + for (int i = 1; i < argc-1; i++ ) + { + if(isdigit(argv[i][0])) + { + if(strstr(argv[i],check2) != NULL) + { + hosts = argv[i]; + } + } + else if(strstr(argv[i],check) !=NULL) + { + if(strstr(argv[i],check2) != NULL) + { + hosts = argv[1]; + } + + } + else if(isalpha(argv[i][0])) + { + nodeType = argv[i]; + } + } + } + else + { + hosts = "localhost:2181"; + } + session_id = NULL; char* p; cout << "Initialising Zookeeper" << endl; // prints !!!Hello World!!! - zk = zookeeper_init("localhost:2181", watcher, timeout, session_id, NULL, 0); + zk = zookeeper_init(hosts, watcher, timeout, session_id, NULL, 0); while (!zk) { @@ -69,11 +111,9 @@ int main(int argc, char **argv) safeShutdown(zk); return 0; -} +}// End of Main + -/////////////////////////////////////////////////////////////////////// -/// END OF MAIN /// -/////////////////////////////////////////////////////////////////////// void safeShutdown(zhandle_t *zzh) { @@ -133,18 +173,28 @@ void watcher(zhandle_t *zzh, int type, int state, const char *path, std::cout<> temp; + string addition_of_strings = "/configTest/" + temp; + const char* node_to_watch = addition_of_strings.c_str(); + std::cout<<"setting watch for config type of "<