README 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. Zookeeper C client library
  2. This package provides a C client interface to Zookeeper server. For general
  3. information about Zookeeper please see http://zookeeper.wiki.sourceforge.net/.
  4. The homepage for this project is http://sourceforge.net/projects/zookeeper/.
  5. OVERVIEW
  6. The client supports two types of APIs -- synchronous and asynchronous.
  7. Asynchronous API provides non-blocking operations with completion callbacks and
  8. relies on the application to implement event multiplexing on its behalf.
  9. On the other hand, Synchronous API provides a blocking flavor of zookeeper operations
  10. and runs its own event loop in a separate thread.
  11. Sync and Async APIs can be mixed and matched within the same application.
  12. The package includes two shared libraries: zookeeper_st and zookeeper_mt. The former
  13. only provides the Async API and is not thread-safe. The only reason this library
  14. exists is to support the platforms were pthread library is not available or unstable
  15. (i.e. FreeBSD 4.x). In all other cases the application developers are advised to link
  16. against zookeeper_mt as it includes support for both Sync and Async API.
  17. INSTALLATION
  18. If you're building the client from a check-out from Source Forge repository, you
  19. need to follow the steps outlined below. If you're building from a project source package
  20. downloaded from Source Forge please skip to step 3.
  21. 1) do a "ant compile_jute" from the zookeeper top level directory (.../trunk/zookeeper).
  22. This will create a directory named "generated" under zookeeper/c.
  23. 2) change directory to the zookeeper/c and do a "autoreconf -i" to bootstrap
  24. autoconf, automake and libtool. Please make sure you have autoconf version 2.59
  25. or greater installed. Skip to step 4.
  26. 3) unzip/untar the source tarball and cd to the zookeeper-x.x.x/ directory
  27. 4) do a "./configure [OPTIONS]" to generate the makefile. See INSTALL for general
  28. information about running configure. Additionally, the configure supports
  29. the following options:
  30. --enable-debug enables optimization and enables debug info compiler options,
  31. disabled by default
  32. --without-syncapi disables Sync API support; zookeeper_mt library won't be built,
  33. enabled by default
  34. --disable-static do not build static libraries, enabled by default
  35. --disable-shared do not build shared libraries, enabled by default
  36. 5) do a "make" or "make install" to build the libraries and install them.
  37. Alternatively, you can also build and run a unit test suite (and you probably should).
  38. Please make sure you have cppunit-1.10.x or higher installed before you execute step 4.
  39. Once ./configure has finished, do a "make run-check". It will build the libraries,
  40. build the tests and run them.
  41. 6) to generate doxygen documentation do a "make doxygen-doc". All documentations will be
  42. placed to a new subfolder named docs. By default only HTML documentation is generated.
  43. For information on other document formats please use "./configure --help"
  44. USING THE CLIENT
  45. You can test your client by running a zookeeper server (see instructions on
  46. the project wiki page on how to run it) and connecting to it using the zookeeper shell
  47. application cli that is built as part of the installation procedure.
  48. cli_mt (multithreaded, built against zookeeper_mt library) is shown in this example,
  49. but you could also use cli_st (singlethreaded, built against zookeeper_st library):
  50. $ cli_mt zookeeper_host:9876
  51. This is a client application that gives you a shell for executing simple zookeeper
  52. commands. Once succesully started and connected to the server it displays a shell prompt.
  53. You can now enter zookeeper commands. For example, to create a node:
  54. > create /my_new_node
  55. To verify that the node's been created:
  56. > ls /
  57. You should see a list of nodes who are the children of the root node "/".
  58. Here's a list of command supported by the cli shell:
  59. ls <path> -- list children of a znode identified by <path>. The command
  60. set a children watch on the znode.
  61. get <path> -- get the value of a znode at <path>
  62. set <path> <value> -- set the value of a znode at <path> to <value>
  63. create [+e|+s] <path> -- create a znode as a child of znode <path>;
  64. use +e option to create an ephemeral znode,
  65. use +s option to create a znode with a sequence number
  66. appended to the name. The operation will fail if
  67. the parent znode (the one identified by <path>) doesn't
  68. exist.
  69. delete <path> -- delete the znode at <path>. The command will fail if the znode
  70. has children.
  71. sync <path> -- make sure all pending updates have been applied to znode at <path>
  72. exists <path> -- returns a result code indicating whether the znode at <path>
  73. exists. The command also sets a znode watch.
  74. myid -- prints out the current zookeeper session id.
  75. quit -- exit the shell.
  76. In order to be able to use the zookeeper API in your application you have to
  77. 1) remember to include the zookeeper header
  78. #include <zookeeper/zookeeper.h>
  79. 2) use -DTHREADED compiler option to enable Sync API; in this case you should
  80. be linking your code against zookeeper_mt library
  81. Please take a look at cli.c to understand how to use the two API types.
  82. (TODO: some kind of short tutorial would be helpful, I guess)
  83. SUPPORT
  84. For questions, please email <zookeeper-user@lists.sourceforge.net>