README 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. Zookeeper C client library
  2. This package provides a C client interface to Zookeeper server.
  3. For the latest information about ZooKeeper, please visit our website at:
  4. http://zookeeper.apache.org/
  5. and our wiki, at:
  6. https://cwiki.apache.org/confluence/display/ZOOKEEPER
  7. Full documentation for this release can also be found in ../../docs/index.html
  8. OVERVIEW
  9. The client supports two types of APIs -- synchronous and asynchronous.
  10. Asynchronous API provides non-blocking operations with completion callbacks and
  11. relies on the application to implement event multiplexing on its behalf.
  12. On the other hand, Synchronous API provides a blocking flavor of
  13. zookeeper operations and runs its own event loop in a separate thread.
  14. Sync and Async APIs can be mixed and matched within the same application.
  15. The package includes two shared libraries: zookeeper_st and
  16. zookeeper_mt. The former only provides the Async API and is not
  17. thread-safe. The only reason this library exists is to support the
  18. platforms were pthread library is not available or unstable
  19. (i.e. FreeBSD 4.x). In all other cases the application developers are
  20. advised to link against zookeeper_mt as it includes support for both
  21. Sync and Async API.
  22. INSTALLATION
  23. If you're building the client from a source checkout you need to
  24. follow the steps outlined below. If you're building from a release
  25. tar downloaded from Apache please skip to step 2.
  26. 1) do a "ant compile_jute" from the zookeeper top level directory (.../trunk).
  27. This will create a directory named "generated" under zookeeper-client/zookeeper-client-c.
  28. Skip to step 3.
  29. 2) unzip/untar the source tarball and cd to the zookeeper-x.x.x/zookeeper-client/zookeeper-client-c directory
  30. 3) change directory to zookeeper-client/zookeeper-client-c and do a "autoreconf -if" to bootstrap
  31. autoconf, automake and libtool. Please make sure you have autoconf
  32. version 2.59 or greater installed. If cppunit is installed in a non-standard
  33. directory, you need to specify where to find cppunit.m4. For example, if
  34. cppunit is installed under /usr/local, run:
  35. ACLOCAL="aclocal -I /usr/local/share/aclocal" autoreconf -if
  36. 4) do a "./configure [OPTIONS]" to generate the makefile. See INSTALL
  37. for general information about running configure. Additionally, the
  38. configure supports the following options:
  39. --enable-debug enables optimization and enables debug info compiler
  40. options, disabled by default
  41. --without-syncapi disables Sync API support; zookeeper_mt library won't
  42. be built, enabled by default
  43. --disable-static do not build static libraries, enabled by default
  44. --disable-shared do not build shared libraries, enabled by default
  45. --without-cppunit do not build the test library, enabled by default.
  46. 5) do a "make" or "make install" to build the libraries and install them.
  47. Alternatively, you can also build and run a unit test suite (and
  48. you probably should). Please make sure you have cppunit-1.10.x or
  49. higher installed before you execute step 4. Once ./configure has
  50. finished, do a "make check". It will build the libraries, build
  51. the tests and run them.
  52. 6) to generate doxygen documentation do a "make doxygen-doc". All
  53. documentations will be placed to a new subfolder named docs. By
  54. default only HTML documentation is generated. For information on
  55. other document formats please use "./configure --help"
  56. Alternatively you can use the CMake build system. On Windows, this is required.
  57. Follow steps 1 and 2 above, and then continue here.
  58. 1) do a "cmake [OPTIONS]" to generate the makefile or msbuild files (the correct
  59. build system will be generated based on your platform). Some options from above
  60. are supported:
  61. -DCMAKE_BUILD_TYPE Debug by default, Release enables optimzation etc.
  62. -DWANT_SYNCAPI ON by default, OFF disables the Sync API support
  63. -DWANT_CPPUNIT ON except on Windows, OFF disables the tests
  64. -DWITH_OPENSSL ON by default, OFF disables the SSL support. You can also
  65. specify a custom path by -DWITH_OPENSSL=/path/to/openssl/
  66. -DWITH_CYRUS_SASL ON by default, OFF disables SASL support. You can also
  67. specify a custom path by -DWITH_CYRUS_SASL=/path/to/cyrus-sasl/
  68. -DBUILD_SHARED_LIBS not yet supported, only static libraries are built
  69. other CMake options see "cmake --help" for generic options, such as generator
  70. 2) do a "cmake --build ." to build the default targets. Alternatively you can
  71. invoke "make" or "msbuild" manually. If the tests were enabled, use "ctest -V"
  72. to run them.
  73. Current limitations of the CMake build system include lack of Solaris support,
  74. no shared library option, no explicitly exported symbols (all are exported by
  75. default), no versions on the libraries, and no documentation generation.
  76. Features of CMake include a single, easily consumed cross-platform build system
  77. to generate the ZooKeeper C Client libraries for any project, with little to no
  78. configuration.
  79. EXAMPLE/SAMPLE C CLIENT SHELL
  80. NOTE: the ZooKeeper C client shell (cli_st and cli_mt) is meant as a
  81. example/sample of ZooKeeper C client API usage. It is not a full
  82. fledged client and not meant for production usage - see the Java
  83. client shell for a fully featured shell.
  84. You can test your client by running a zookeeper server (see
  85. instructions on the project wiki page on how to run it) and connecting
  86. to it using the zookeeper shell application cli that is built as part
  87. of the installation procedure.
  88. cli_mt (multithreaded, built against zookeeper_mt library) is shown in
  89. this example, but you could also use cli_st (singlethreaded, built
  90. against zookeeper_st library):
  91. $ cli_mt zookeeper_host:9876
  92. To start a client with read-only mode enabled, use the -r flag:
  93. $ cli_mt -r zookeeper_host:9876
  94. This is a client application that gives you a shell for executing
  95. simple zookeeper commands. Once successfully started and connected to
  96. the server it displays a shell prompt.
  97. You can now enter zookeeper commands. For example, to create a node:
  98. > create /my_new_node
  99. To verify that the node's been created:
  100. > ls /
  101. You should see a list of nodes who are the children of the root node "/".
  102. Here's a list of command supported by the cli shell:
  103. ls <path> -- list children of a znode identified by <path>. The
  104. command set a children watch on the znode.
  105. get <path> -- get the value of a znode at <path>
  106. set <path> <value> -- set the value of a znode at <path> to <value>
  107. create [+e|+s] <path> -- create a znode as a child of znode <path>;
  108. use +e option to create an ephemeral znode,
  109. use +s option to create a znode with a sequence number
  110. appended to the name. The operation will fail if
  111. the parent znode (the one identified by <path>) doesn't
  112. exist.
  113. delete <path> -- delete the znode at <path>. The command will fail if the znode
  114. has children.
  115. sync <path> -- make sure all pending updates have been applied to znode at <path>
  116. exists <path> -- returns a result code indicating whether the znode at <path>
  117. exists. The command also sets a znode watch.
  118. myid -- prints out the current zookeeper session id.
  119. quit -- exit the shell.
  120. In order to be able to use the zookeeper API in your application you have to
  121. 1) remember to include the zookeeper header
  122. #include <zookeeper/zookeeper.h>
  123. 2) use -DTHREADED compiler option to enable Sync API; in this case you should
  124. be linking your code against zookeeper_mt library
  125. Please take a look at cli.c to understand how to use the two API types.
  126. (TODO: some kind of short tutorial would be helpful, I guess)