README 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 src/c. Skip to step 3.
  28. 2) unzip/untar the source tarball and cd to the zookeeper-x.x.x/src/c directory
  29. 3) change directory to src/c and do a "autoreconf -if" to bootstrap
  30. autoconf, automake and libtool. Please make sure you have autoconf
  31. version 2.59 or greater installed. If cppunit is installed in a non-standard
  32. directory, you need to specify where to find cppunit.m4. For example, if
  33. cppunit is installed under /usr/local, run:
  34. ACLOCAL="aclocal -I /usr/local/share/aclocal" autoreconf -if
  35. 4) do a "./configure [OPTIONS]" to generate the makefile. See INSTALL
  36. for general information about running configure. Additionally, the
  37. configure supports the following options:
  38. --enable-debug enables optimization and enables debug info compiler
  39. options, disabled by default
  40. --without-syncapi disables Sync API support; zookeeper_mt library won't
  41. be built, enabled by default
  42. --disable-static do not build static libraries, enabled by default
  43. --disable-shared do not build shared libraries, enabled by default
  44. --without-cppunit do not build the test library, enabled by default.
  45. 5) do a "make" or "make install" to build the libraries and install them.
  46. Alternatively, you can also build and run a unit test suite (and
  47. you probably should). Please make sure you have cppunit-1.10.x or
  48. higher installed before you execute step 4. Once ./configure has
  49. finished, do a "make check". It will build the libraries, build
  50. the tests and run them.
  51. 6) to generate doxygen documentation do a "make doxygen-doc". All
  52. documentations will be placed to a new subfolder named docs. By
  53. default only HTML documentation is generated. For information on
  54. other document formats please use "./configure --help"
  55. USING THE CLIENT
  56. You can test your client by running a zookeeper server (see
  57. instructions on the project wiki page on how to run it) and connecting
  58. to it using the zookeeper shell application cli that is built as part
  59. of the installation procedure.
  60. cli_mt (multithreaded, built against zookeeper_mt library) is shown in
  61. this example, but you could also use cli_st (singlethreaded, built
  62. against zookeeper_st library):
  63. $ cli_mt zookeeper_host:9876
  64. To start a client with read-only mode enabled, use the -r flag:
  65. $ cli_mt -r zookeeper_host:9876
  66. This is a client application that gives you a shell for executing
  67. simple zookeeper commands. Once successfully started and connected to
  68. the server it displays a shell prompt.
  69. You can now enter zookeeper commands. For example, to create a node:
  70. > create /my_new_node
  71. To verify that the node's been created:
  72. > ls /
  73. You should see a list of nodes who are the children of the root node "/".
  74. Here's a list of command supported by the cli shell:
  75. ls <path> -- list children of a znode identified by <path>. The
  76. command set a children watch on the znode.
  77. get <path> -- get the value of a znode at <path>
  78. set <path> <value> -- set the value of a znode at <path> to <value>
  79. create [+e|+s] <path> -- create a znode as a child of znode <path>;
  80. use +e option to create an ephemeral znode,
  81. use +s option to create a znode with a sequence number
  82. appended to the name. The operation will fail if
  83. the parent znode (the one identified by <path>) doesn't
  84. exist.
  85. delete <path> -- delete the znode at <path>. The command will fail if the znode
  86. has children.
  87. sync <path> -- make sure all pending updates have been applied to znode at <path>
  88. exists <path> -- returns a result code indicating whether the znode at <path>
  89. exists. The command also sets a znode watch.
  90. myid -- prints out the current zookeeper session id.
  91. quit -- exit the shell.
  92. In order to be able to use the zookeeper API in your application you have to
  93. 1) remember to include the zookeeper header
  94. #include <zookeeper/zookeeper.h>
  95. 2) use -DTHREADED compiler option to enable Sync API; in this case you should
  96. be linking your code against zookeeper_mt library
  97. Please take a look at cli.c to understand how to use the two API types.
  98. (TODO: some kind of short tutorial would be helpful, I guess)