• Stars
    star
    99
  • Rank 343,315 (Top 7 %)
  • Language
    C
  • License
    Apache License 2.0
  • Created over 11 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lua binding of apache zookeeper.

ZKLUA: an one-minute introduction for beginners

Zklua is the first(as far as I know) lua binding of apache zookeeper. If you are wondering what is apache zookeeper, please visit the zookeeper official website to get more information about it, hereinafter is an one-sentence description that can inform of you what is apache zookeeper:

ZooKeeper is a high-performance coordination service for distributed applications. It exposes common services - such as naming, configuration management, synchronization, and group services - in a simple interface so you don't have to write them from scratch. You can use it off-the-shelf to implement consensus, group management, leader election, and presence protocols.

Zklua provides a complete API binding of Lua for apache zookeeper(hereinafter referred to as zookeeper), including synchronous and asynchronous interface as well as some useful auxiliary APIs. That is, you may create/delete/get/update(CRUD) a zookeeper node(ZNode) in lua language synchronously and/or asynchronously without any pains.

How to build zklua

Prepare to build zklua

First of all, you have to get zklua source code from github:

$ git clone [email protected]:forhappy/zklua.git

Dependencies

Zklua has no other dependencies except for zookeeper c API implementation, which usually resides in zookeeper-X.Y.Z/src/c, hence you need to install zookeeper c API at first.

Install zklua

all you have to do is just a make to compile zklua:

$ make

If you want to install zklua into your system after you have compiled zklua, you need to make install(as root):

$ make install

Getting started in 5 minutes

Examples

Deleting a ZNode.

Here is a tiny lua example to show you deleting a ZNode from zookeeper server.

require "zklua"
  
function zklua_my_watcher(zh, type, state, path, watcherctx)
    if type == zklua.ZOO_SESSION_EVENT then
        if state == zklua.ZOO_CONNECTED_STATE then
            print("Connected to zookeeper service successfully!\n");
            elseif (state == ZOO_EXPIRED_SESSION_STATE) then
            print("Zookeeper session expired!\n");
        end
    end
end
	
function zklua_my_void_completion(rc, data)
    print("zklua_my_void_completion:\n")
    print("rc: "..rc.."\tdata: "..data)
end
	
zklua.set_log_stream("zklua.log")
	
zh = zklua.init("127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183", zklua_my_watcher, 10000)
	
ret = zklua.adelete(zh, "/zklua", -1, zklua_my_void_completion, "zklua adelete.")
print("zklua.adelete ret: "..ret)
	
print("hit any key to continue...")
io.read()

Set watch on a specified path.

Here is a tiny lua example to show you set a watch on a specified path.

require "zklua"
    
function zklua_my_global_watcher(zh, type, state, path, watcherctx)
    if type == zklua.ZOO_SESSION_EVENT then
        if state == zklua.ZOO_CONNECTED_STATE then
            print("Connected to zookeeper service successfully!\n");
         elseif (state == ZOO_EXPIRED_SESSION_STATE) then
            print("Zookeeper session expired!\n");
        end
    end
end

function zklua_my_local_watcher(zh, type, state, path, watcherctx)
    print("zklua_my_local_watcher(".."type: "..type..", state: "..state..", path: "..path..")")
    print("zklua_my_local_watcher(".."watcherctx: "..watcherctx..")")
end
    
function zklua_my_stat_completion(rc, stat, data)
    print("zklua_my_stat_completion:\n")
    print("rc: "..rc.."\tdata: "..data)
end
    
zklua.set_log_stream("zklua.log")
    
zh = zklua.init("127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183", zklua_my_global_watcher, 10000)
    
ret = zklua.awexists(zh, "/zklua",
                     zklua_my_local_watcher,"zklua_my_local_watcher",
                     zklua_my_stat_completion, "zklua aexists.")
print("zklua.aexists ret: "..ret)
    
print("hit any key to continue...")
io.read()

API specification

See docs/zklua.lua for more details about zklua's API specification.

License

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

More Repositories

1

Cplusplus-Concurrency-In-Practice

A Detailed Cplusplus Concurrency Tutorial ใ€ŠC++ ๅนถๅ‘็ผ–็จ‹ๆŒ‡ๅ—ใ€‹
C++
5,280
star
2

awesome-lua

A curated list of awesome Lua frameworks, libraries and software.
341
star
3

rbtree

rbtree implementation adapted from linux kernel thus can be used in your own c program(of course in userspace).
C
154
star
4

c-recipes

c/c++ language useful recipes
C++
92
star
5

cpy-leveldb

python bingding for leveldb using c api
C
88
star
6

reveldb

reveldb enables you to access google's leveldb in a completely RESTful way.
C
71
star
7

tinydb

a tiny nosql database supporting pluggable storage engine.
C
40
star
8

RegexKit

RegexKit: A Regular Expression Toolbox Based On NW.js(Node-Webkit) And Other Greate Open Source Projects.
JavaScript
37
star
9

lua-snappy

Lua binding of google's snappy compressor.
C++
30
star
10

aliyun-pk-report-2012

aliyun pk report 2012
20
star
11

CS61

CS61 learning schedules and assessments
C
16
star
12

OSSC

Aliyun OSS C SDK
C
16
star
13

neo4j-cpp-driver

neo4j cpp driver.
C++
15
star
14

uv-ocaml

Ocaml binding for joyent/libuv[https://github.com/joyent/libuv]
C
15
star
15

mycv

my personal curriculum vitae(or resume)
13
star
16

tstring

Tiny c++ style string utility implementation in c.
C
12
star
17

zkocaml

Apache zookeeper client binding for OCAML programming language.
C
7
star
18

libloader

load your program before /ld-linux-so.2,only for some hacks
C
7
star
19

barriers

sample barriers implementations
C
6
star
20

Weibo-mining

Weibo mining
Java
6
star
21

tiny-threadpool

very tiny threadpool in c
C
5
star
22

cos-go-sdk

COS Go SDK
Go
5
star
23

py-quicklz

python binding for quicklz compression library
C
4
star
24

pyredis

python bingding for redis based on hiredis c api
C
4
star
25

haiep

HBase automatic import and export processing
Java
4
star
26

ocaml-http-parser

http request/response parser for OCAML based on joyent/http-parser[ https://github.com/joyent/http-parser ].
C
3
star
27

LLDB

LevelDB-backended and Libevent-driven Database server
C
2
star
28

forhappy

My HTML Curriculum Vitae
CSS
2
star
29

NHT-git-tutorial

NHT-git tutorial at Freewheel.
2
star
30

CPP-Tech-Salon

C++11 Tech Salon at FreeWheel
2
star
31

py-fastlz

python binding for fastlz compression library
C
1
star
32

weibo-mining-report

Weibo mining report
1
star
33

go-ssh

Fork from code.google.com/p/go.crypto/ssh.
Go
1
star