int main(int argc, char **argv) { int nodeCount; int cleaning=0; if (argc < 4) { usage(argv); } if(strcmp("clean",argv[3])==0){ cleaning=1; } zoo_set_debug_level(ZOO_LOG_LEVEL_INFO); zoo_deterministic_conn_order(1); // enable deterministic order zh = zookeeper_init(argv[1], listener, 10000, 0, 0, 0); if (!zh) return errno; LOG_INFO(LOGSTREAM, "Checking server connection..."); ensureConnected(); if(cleaning==1){ int rc = 0; deletedCounter=0; rc=recursiveDelete(argv[2]); if(rc==ZOK){ LOG_INFO(LOGSTREAM, "Successfully deleted a subtree starting at %s (%d nodes)", argv[2],deletedCounter); exit(0); } exit(1); } nodeCount=atoi(argv[3]); createRoot(argv[2]); while(1) { ensureConnected(); LOG_INFO(LOGSTREAM, "Creating children for path %s",argv[2]); doCreateNodes(argv[2],nodeCount); waitCounter(); LOG_INFO(LOGSTREAM, "Starting the write cycle for path %s",argv[2]); doWrites(argv[2],nodeCount); waitCounter(); LOG_INFO(LOGSTREAM, "Starting the read cycle for path %s",argv[2]); doReads(argv[2],nodeCount); waitCounter(); LOG_INFO(LOGSTREAM, "Starting the delete cycle for path %s",argv[2]); doDeletes(argv[2],nodeCount); waitCounter(); } zookeeper_close(zh); return 0; }
void LedReader::run() { int count = 0; while (!m_stop) { count++; if (doWrites()) count = 5; if (count == 5) { doReads(); count = 0; } msleep(100); } }