README 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. Please refer to the "Installation" item under "C Binding" section in file
  24. ".../trunk/zookeeper-docs/src/main/resources/markdown/zookeeperProgrammers.md"
  25. EXAMPLE/SAMPLE C CLIENT SHELL
  26. NOTE: the ZooKeeper C client shell (cli_st and cli_mt) is meant as a
  27. example/sample of ZooKeeper C client API usage. It is not a full
  28. fledged client and not meant for production usage - see the Java
  29. client shell for a fully featured shell.
  30. You can test your client by running a zookeeper server (see
  31. instructions on the project wiki page on how to run it) and connecting
  32. to it using the zookeeper shell application cli that is built as part
  33. of the installation procedure.
  34. cli_mt (multithreaded, built against zookeeper_mt library) is shown in
  35. this example, but you could also use cli_st (singlethreaded, built
  36. against zookeeper_st library):
  37. $ cli_mt zookeeper_host:9876
  38. To start a client with read-only mode enabled, use the -r flag:
  39. $ cli_mt -r zookeeper_host:9876
  40. This is a client application that gives you a shell for executing
  41. simple zookeeper commands. Once successfully started and connected to
  42. the server it displays a shell prompt.
  43. You can now enter zookeeper commands. For example, to create a node:
  44. > create /my_new_node
  45. To verify that the node's been created:
  46. > ls /
  47. You should see a list of nodes who are the children of the root node "/".
  48. Here's a list of command supported by the cli shell:
  49. ls <path> -- list children of a znode identified by <path>. The
  50. command set a children watch on the znode.
  51. get <path> -- get the value of a znode at <path>
  52. set <path> <value> -- set the value of a znode at <path> to <value>
  53. create [+e|+s] <path> -- create a znode as a child of znode <path>;
  54. use +e option to create an ephemeral znode,
  55. use +s option to create a znode with a sequence number
  56. appended to the name. The operation will fail if
  57. the parent znode (the one identified by <path>) doesn't
  58. exist.
  59. delete <path> -- delete the znode at <path>. The command will fail if the znode
  60. has children.
  61. sync <path> -- make sure all pending updates have been applied to znode at <path>
  62. exists <path> -- returns a result code indicating whether the znode at <path>
  63. exists. The command also sets a znode watch.
  64. myid -- prints out the current zookeeper session id.
  65. quit -- exit the shell.
  66. In order to be able to use the zookeeper API in your application you have to
  67. 1) remember to include the zookeeper header
  68. #include <zookeeper/zookeeper.h>
  69. 2) use -DTHREADED compiler option to enable Sync API; in this case you should
  70. be linking your code against zookeeper_mt library
  71. Please take a look at cli.c to understand how to use the two API types.
  72. (TODO: some kind of short tutorial would be helpful, I guess)