Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support for creating container nodes #107

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## 1.2.0
1. [New: Support for container nodes](https://github.com/alexguan/node-zookeeper-client/pull/107)

## 1.1.0

1. [New: Add removeRecursive and listSubTreeBFS methods](https://github.com/alexguan/node-zookeeper-client/pull/88)
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ Client.prototype.create = function (path, data, acls, mode, callback) {
assert(acls.length > 0, 'acls must be a non-empty array.');

header = new jute.protocol.RequestHeader();
header.type = jute.OP_CODES.CREATE;
header.type = mode === CreateMode.CONTAINER ?
jute.OP_CODES.CREATE_CONTAINER :
jute.OP_CODES.CREATE;

payload = new jute.protocol.CreateRequest();
payload.path = path;
Expand Down
1 change: 1 addition & 0 deletions lib/ConnectionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ ConnectionManager.prototype.onSocketData = function (buffer) {
if (responseHeader.err === 0) {
switch (pendingPacket.request.header.type) {
case jute.OP_CODES.CREATE:
case jute.OP_CODES.CREATE_CONTAINER:
responsePayload = new jute.protocol.CreateResponse();
break;
case jute.OP_CODES.DELETE:
Expand Down
8 changes: 7 additions & 1 deletion lib/CreateMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ var CREATE_MODES = {
* The znode will be deleted upon the client's disconnect, and its name
* will be appended with a monotonically increasing number.
*/
EPHEMERAL_SEQUENTIAL : 3
EPHEMERAL_SEQUENTIAL : 3,

/**
* The znode will be deleted when it has been without any children for
* some time.
*/
CONTAINER : 4,
};

module.exports = CREATE_MODES;
6 changes: 5 additions & 1 deletion lib/Transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ Transaction.prototype.create = function (path, data, acls, mode) {

assert(acls.length > 0, 'acls must be a non-empty array.');

var type = mode === CreateMode.CONTAINER ?
jute.OP_CODES.CREATE_CONTAINER :
jute.OP_CODES.CREATE;

this.ops.push({
type : jute.OP_CODES.CREATE,
type : type,
path : path,
data : data,
acls : acls,
Expand Down
3 changes: 3 additions & 0 deletions lib/jute/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var OP_CODES = {
GET_CHILDREN2 : 12,
CHECK : 13,
MULTI : 14,
CREATE_CONTAINER: 19,
AUTH : 100,
SET_WATCHES : 101,
SASL : 102,
Expand Down Expand Up @@ -504,6 +505,7 @@ function TransactionRequest(ops) {

switch (op.type) {
case jute.OP_CODES.CREATE:
case jute.OP_CODES.CREATE_CONTAINER:
record = new jute.protocol.CreateRequest();
record.path = op.path;
record.data = op.data;
Expand Down Expand Up @@ -621,6 +623,7 @@ TransactionResponse.prototype.deserialize = function (buffer, offset) {

switch (header.type) {
case jute.OP_CODES.CREATE:
case jute.OP_CODES.CREATE_CONTAINER:
response = new jute.protocol.CreateResponse();
response.setChrootPath(self.chrootPath);
bytesRead += response.deserialize(buffer, offset + bytesRead);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-zookeeper-client",
"version": "1.1.0",
"version": "1.2.0",
"description": "A pure Javascript ZooKeeper client for Node.js.",
"author": "Alex Guan <alex.guan@gmail.com>",
"license": "MIT",
Expand Down