Java 类org.apache.zookeeper.proto.ReplyHeader 实例源码

项目:fuck_zookeeper    文件:NettyServerCnxn.java   
@Override
public void process(WatchedEvent event) {
    ReplyHeader h = new ReplyHeader(-1, -1L, 0);
    if (LOG.isTraceEnabled()) {
        ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK,
                                 "Deliver event " + event + " to 0x"
                                 + Long.toHexString(this.sessionId)
                                 + " through " + this);
    }

    // Convert WatchedEvent to a type that can be sent over the wire
    WatcherEvent e = event.getWrapper();

    try {
        sendResponse(h, e, "notification");
    } catch (IOException e1) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Problem sending to " + getRemoteSocketAddress(), e1);
        }
        close();
    }
}
项目:fuck_zookeeper    文件:ClientCnxn.java   
public void sendPacket(Record request, Record response, AsyncCallback cb, int opCode)
throws IOException {
    // Generate Xid now because it will be sent immediately,
    // by call to sendThread.sendPacket() below.
    int xid = getXid();
    RequestHeader h = new RequestHeader();
    h.setXid(xid);
    h.setType(opCode);

    ReplyHeader r = new ReplyHeader();
    r.setXid(xid);

    Packet p = new Packet(h, r, request, response, null, false);
    p.cb = cb;
    sendThread.sendPacket(p);
}
项目:fuck_zookeeper    文件:ClientTest.java   
/**
 * We create a perfectly valid 'exists' request, except that the opcode is wrong.
 * @return
 * @throws Exception
 */
@Test
public void testNonExistingOpCode() throws Exception  {
    TestableZooKeeper zk = createClient();

    final String path = "/m1";

    RequestHeader h = new RequestHeader();
    h.setType(888);  // This code does not exists
    ExistsRequest request = new ExistsRequest();
    request.setPath(path);
    request.setWatch(false);
    ExistsResponse response = new ExistsResponse();
    ReplyHeader r = zk.submitRequest(h, request, response, null);

    Assert.assertEquals(r.getErr(), Code.UNIMPLEMENTED.intValue());

    try {
        zk.exists("/m1", false);
        fail("The connection should have been closed");
    } catch (KeeperException.ConnectionLossException expected) {
    }
}
项目:https-github.com-apache-zookeeper    文件:NettyServerCnxn.java   
@Override
public void process(WatchedEvent event) {
    ReplyHeader h = new ReplyHeader(-1, -1L, 0);
    if (LOG.isTraceEnabled()) {
        ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK,
                                 "Deliver event " + event + " to 0x"
                                 + Long.toHexString(this.sessionId)
                                 + " through " + this);
    }

    // Convert WatchedEvent to a type that can be sent over the wire
    WatcherEvent e = event.getWrapper();

    try {
        sendResponse(h, e, "notification");
    } catch (IOException e1) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Problem sending to " + getRemoteSocketAddress(), e1);
        }
        close();
    }
}
项目:https-github.com-apache-zookeeper    文件:ClientCnxn.java   
public void sendPacket(Record request, Record response, AsyncCallback cb, int opCode)
throws IOException {
    // Generate Xid now because it will be sent immediately,
    // by call to sendThread.sendPacket() below.
    int xid = getXid();
    RequestHeader h = new RequestHeader();
    h.setXid(xid);
    h.setType(opCode);

    ReplyHeader r = new ReplyHeader();
    r.setXid(xid);

    Packet p = new Packet(h, r, request, response, null, false);
    p.cb = cb;
    sendThread.sendPacket(p);
}
项目:https-github.com-apache-zookeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of create.
 *
 * @see #create(String, byte[], List, CreateMode)
 */
public void create(final String path, byte data[], List<ACL> acl,
        CreateMode createMode, StringCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath, createMode.isSequential());
    EphemeralType.validateTTL(createMode, -1);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(createMode.isContainer() ? ZooDefs.OpCode.createContainer : ZooDefs.OpCode.create);
    CreateRequest request = new CreateRequest();
    CreateResponse response = new CreateResponse();
    ReplyHeader r = new ReplyHeader();
    request.setData(data);
    request.setFlags(createMode.toFlag());
    request.setPath(serverPath);
    request.setAcl(acl);
    cnxn.queuePacket(h, r, request, response, cb, clientPath,
            serverPath, ctx, null);
}
项目:https-github.com-apache-zookeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of create with ttl.
 *
 * @see #create(String, byte[], List, CreateMode, Stat, long)
 */
public void create(final String path, byte data[], List<ACL> acl,
        CreateMode createMode, Create2Callback cb, Object ctx, long ttl)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath, createMode.isSequential());
    EphemeralType.validateTTL(createMode, ttl);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    setCreateHeader(createMode, h);
    ReplyHeader r = new ReplyHeader();
    Create2Response response = new Create2Response();
    Record record = makeCreateRecord(createMode, serverPath, data, acl, ttl);
    cnxn.queuePacket(h, r, record, response, cb, clientPath,
            serverPath, ctx, null);
}
项目:https-github.com-apache-zookeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of exists.
 *
 * @see #exists(String, Watcher)
 */
public void exists(final String path, Watcher watcher,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new ExistsWatchRegistration(watcher, clientPath);
    }

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.exists);
    ExistsRequest request = new ExistsRequest();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    SetDataResponse response = new SetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, wcb);
}
项目:https-github.com-apache-zookeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of getData.
 *
 * @see #getData(String, Watcher, Stat)
 */
public void getData(final String path, Watcher watcher,
        DataCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new DataWatchRegistration(watcher, clientPath);
    }

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getData);
    GetDataRequest request = new GetDataRequest();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    GetDataResponse response = new GetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, wcb);
}
项目:https-github.com-apache-zookeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of getConfig.
 *
 * @see #getConfig(Watcher, Stat)
 */
public void getConfig(Watcher watcher,
        DataCallback cb, Object ctx)
{
    final String configZnode = ZooDefs.CONFIG_NODE;

    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new DataWatchRegistration(watcher, configZnode);
    }

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getData);
    GetDataRequest request = new GetDataRequest();
    request.setPath(configZnode);
    request.setWatch(watcher != null);
    GetDataResponse response = new GetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
           configZnode, configZnode, ctx, wcb);
}
项目:https-github.com-apache-zookeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of setData.
 *
 * @see #setData(String, byte[], int)
 */
public void setData(final String path, byte data[], int version,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setData);
    SetDataRequest request = new SetDataRequest();
    request.setPath(serverPath);
    request.setData(data);
    request.setVersion(version);
    SetDataResponse response = new SetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, null);
}
项目:https-github.com-apache-zookeeper    文件:ZooKeeper.java   
/**
 * Return the ACL and stat of the node of the given path.
 * <p>
 * A KeeperException with error code KeeperException.NoNode will be thrown
 * if no node with the given path exists.
 *
 * @param path
 *                the given path for the node
 * @param stat
 *                the stat of the node will be copied to this parameter if
 *                not null.
 * @return the ACL array of the given node.
 * @throws InterruptedException If the server transaction is interrupted.
 * @throws KeeperException If the server signals an error with a non-zero error code.
 * @throws IllegalArgumentException if an invalid path is specified
 */
public List<ACL> getACL(final String path, Stat stat)
    throws KeeperException, InterruptedException
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getACL);
    GetACLRequest request = new GetACLRequest();
    request.setPath(serverPath);
    GetACLResponse response = new GetACLResponse();
    ReplyHeader r = cnxn.submitRequest(h, request, response, null);
    if (r.getErr() != 0) {
        throw KeeperException.create(KeeperException.Code.get(r.getErr()),
                clientPath);
    }
    if (stat != null) {
        DataTree.copyStat(response.getStat(), stat);
    }
    return response.getAcl();
}
项目:https-github.com-apache-zookeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of getACL.
 *
 * @see #getACL(String, Stat)
 */
public void getACL(final String path, Stat stat, ACLCallback cb,
        Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getACL);
    GetACLRequest request = new GetACLRequest();
    request.setPath(serverPath);
    GetACLResponse response = new GetACLResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, null);
}
项目:https-github.com-apache-zookeeper    文件:ZooKeeper.java   
/**
 * Set the ACL for the node of the given path if such a node exists and the
 * given aclVersion matches the acl version of the node. Return the stat of the
 * node.
 * <p>
 * A KeeperException with error code KeeperException.NoNode will be thrown
 * if no node with the given path exists.
 * <p>
 * A KeeperException with error code KeeperException.BadVersion will be
 * thrown if the given aclVersion does not match the node's aclVersion.
 *
 * @param path the given path for the node
 * @param acl the given acl for the node
 * @param aclVersion the given acl version of the node
 * @return the stat of the node.
 * @throws InterruptedException If the server transaction is interrupted.
 * @throws KeeperException If the server signals an error with a non-zero error code.
 * @throws org.apache.zookeeper.KeeperException.InvalidACLException If the acl is invalide.
 * @throws IllegalArgumentException if an invalid path is specified
 */
public Stat setACL(final String path, List<ACL> acl, int aclVersion)
    throws KeeperException, InterruptedException
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);
    validateACL(acl);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setACL);
    SetACLRequest request = new SetACLRequest();
    request.setPath(serverPath);
    request.setAcl(acl);
    request.setVersion(aclVersion);
    SetACLResponse response = new SetACLResponse();
    ReplyHeader r = cnxn.submitRequest(h, request, response, null);
    if (r.getErr() != 0) {
        throw KeeperException.create(KeeperException.Code.get(r.getErr()),
                clientPath);
    }
    return response.getStat();
}
项目:https-github.com-apache-zookeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of setACL.
 *
 * @see #setACL(String, List, int)
 */
public void setACL(final String path, List<ACL> acl, int version,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setACL);
    SetACLRequest request = new SetACLRequest();
    request.setPath(serverPath);
    request.setAcl(acl);
    request.setVersion(version);
    SetACLResponse response = new SetACLResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, null);
}
项目:https-github.com-apache-zookeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of getChildren.
 *
 * @see #getChildren(String, Watcher)
 */
public void getChildren(final String path, Watcher watcher,
        ChildrenCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new ChildWatchRegistration(watcher, clientPath);
    }

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getChildren);
    GetChildrenRequest request = new GetChildrenRequest();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    GetChildrenResponse response = new GetChildrenResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, wcb);
}
项目:https-github.com-apache-zookeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of getChildren.
 *
 * @since 3.3.0
 * 
 * @see #getChildren(String, Watcher, Stat)
 */
public void getChildren(final String path, Watcher watcher,
        Children2Callback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new ChildWatchRegistration(watcher, clientPath);
    }

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getChildren2);
    GetChildren2Request request = new GetChildren2Request();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    GetChildren2Response response = new GetChildren2Response();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, wcb);
}
项目:https-github.com-apache-zookeeper    文件:ZooKeeper.java   
private void removeWatches(int opCode, String path, Watcher watcher,
        WatcherType watcherType, boolean local)
        throws InterruptedException, KeeperException {
    PathUtils.validatePath(path);
    final String clientPath = path;
    final String serverPath = prependChroot(clientPath);
    WatchDeregistration wcb = new WatchDeregistration(clientPath, watcher,
            watcherType, local, watchManager);

    RequestHeader h = new RequestHeader();
    h.setType(opCode);
    Record request = getRemoveWatchesRequest(opCode, watcherType,
            serverPath);

    ReplyHeader r = cnxn.submitRequest(h, request, null, null, wcb);
    if (r.getErr() != 0) {
        throw KeeperException.create(KeeperException.Code.get(r.getErr()),
                clientPath);
    }
}
项目:https-github.com-apache-zookeeper    文件:ZooKeeper.java   
private void removeWatches(int opCode, String path, Watcher watcher,
        WatcherType watcherType, boolean local, VoidCallback cb, Object ctx) {
    PathUtils.validatePath(path);
    final String clientPath = path;
    final String serverPath = prependChroot(clientPath);
    WatchDeregistration wcb = new WatchDeregistration(clientPath, watcher,
            watcherType, local, watchManager);

    RequestHeader h = new RequestHeader();
    h.setType(opCode);
    Record request = getRemoveWatchesRequest(opCode, watcherType,
            serverPath);

    cnxn.queuePacket(h, new ReplyHeader(), request, null, cb, clientPath,
            serverPath, ctx, null, wcb);
}
项目:ZooKeeper    文件:NettyServerCnxn.java   
@Override
public void process(WatchedEvent event) {
    ReplyHeader h = new ReplyHeader(-1, -1L, 0);
    if (LOG.isTraceEnabled()) {
        ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK,
                                 "Deliver event " + event + " to 0x"
                                 + Long.toHexString(this.sessionId)
                                 + " through " + this);
    }

    // Convert WatchedEvent to a type that can be sent over the wire
    WatcherEvent e = event.getWrapper();

    try {
        sendResponse(h, e, "notification");
    } catch (IOException e1) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Problem sending to " + getRemoteSocketAddress(), e1);
        }
        close();
    }
}
项目:ZooKeeper    文件:ClientCnxn.java   
public void sendPacket(Record request, Record response, AsyncCallback cb, int opCode)
throws IOException {
    // Generate Xid now because it will be sent immediately,
    // by call to sendThread.sendPacket() below.
    int xid = getXid();
    RequestHeader h = new RequestHeader();
    h.setXid(xid);
    h.setType(opCode);

    ReplyHeader r = new ReplyHeader();
    r.setXid(xid);

    Packet p = new Packet(h, r, request, response, null, false);
    p.cb = cb;
    sendThread.sendPacket(p);
}
项目:ZooKeeper    文件:ClientTest.java   
/**
 * We create a perfectly valid 'exists' request, except that the opcode is wrong.
 * @return
 * @throws Exception
 */
@Test
public void testNonExistingOpCode() throws Exception  {
    TestableZooKeeper zk = createClient();

    final String path = "/m1";

    RequestHeader h = new RequestHeader();
    h.setType(888);  // This code does not exists
    ExistsRequest request = new ExistsRequest();
    request.setPath(path);
    request.setWatch(false);
    ExistsResponse response = new ExistsResponse();
    ReplyHeader r = zk.submitRequest(h, request, response, null);

    Assert.assertEquals(r.getErr(), Code.UNIMPLEMENTED.intValue());

    try {
        zk.exists("/m1", false);
        fail("The connection should have been closed");
    } catch (KeeperException.ConnectionLossException expected) {
    }
}
项目:SecureKeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of setACL.
 *
 * @see #setACL(String, List, int)
 */
public void setACL(final String path, List<ACL> acl, int version,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setACL);
    SetACLRequest request = new SetACLRequest();
    request.setPath(serverPath);
    request.setAcl(acl);
    request.setVersion(version);
    SetACLResponse response = new SetACLResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, null);
}
项目:StreamProcessingInfrastructure    文件:NettyServerCnxn.java   
@Override
public void process(WatchedEvent event) {
    ReplyHeader h = new ReplyHeader(-1, -1L, 0);
    if (LOG.isTraceEnabled()) {
        ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK,
                                 "Deliver event " + event + " to 0x"
                                 + Long.toHexString(this.sessionId)
                                 + " through " + this);
    }

    // Convert WatchedEvent to a type that can be sent over the wire
    WatcherEvent e = event.getWrapper();

    try {
        sendResponse(h, e, "notification");
    } catch (IOException e1) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Problem sending to " + getRemoteSocketAddress(), e1);
        }
        close();
    }
}
项目:SecureKeeper    文件:NettyServerCnxn.java   
@Override
public void process(WatchedEvent event) {
    ReplyHeader h = new ReplyHeader(-1, -1L, 0);
    if (LOG.isTraceEnabled()) {
        ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK,
                                 "Deliver event " + event + " to 0x"
                                 + Long.toHexString(this.sessionId)
                                 + " through " + this);
    }

    // Convert WatchedEvent to a type that can be sent over the wire
    WatcherEvent e = event.getWrapper();

    try {
        sendResponse(h, e, "notification");
    } catch (IOException e1) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Problem sending to " + getRemoteSocketAddress(), e1);
        }
        close();
    }
}
项目:SecureKeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of create.
 *
 * @see #create(String, byte[], List, CreateMode, Stat)
 */
public void create(final String path, byte data[], List<ACL> acl,
        CreateMode createMode, Create2Callback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath, createMode.isSequential());

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(createMode.isContainer() ? ZooDefs.OpCode.createContainer : ZooDefs.OpCode.create2);
    CreateRequest request = new CreateRequest();
    Create2Response response = new Create2Response();
    ReplyHeader r = new ReplyHeader();
    request.setData(data);
    request.setFlags(createMode.toFlag());
    request.setPath(serverPath);
    request.setAcl(acl);
    cnxn.queuePacket(h, r, request, response, cb, clientPath,
            serverPath, ctx, null);
}
项目:SecureKeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of exists.
 *
 * @see #exists(String, Watcher)
 */
public void exists(final String path, Watcher watcher,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new ExistsWatchRegistration(watcher, clientPath);
    }

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.exists);
    ExistsRequest request = new ExistsRequest();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    SetDataResponse response = new SetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, wcb);
}
项目:bigstreams    文件:ZooKeeper.java   
/**
 * The Asynchronous version of exists. The request doesn't actually until
 * the asynchronous callback is called.
 *
 * @see #exists(String, boolean)
 */
public void exists(final String path, Watcher watcher,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new ExistsWatchRegistration(watcher, clientPath);
    }

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.exists);
    ExistsRequest request = new ExistsRequest();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    SetDataResponse response = new SetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, wcb);
}
项目:bigstreams    文件:ZooKeeper.java   
/**
 * Set the ACL for the node of the given path if such a node exists and the
 * given version matches the version of the node. Return the stat of the
 * node.
 * <p>
 * A KeeperException with error code KeeperException.NoNode will be thrown
 * if no node with the given path exists.
 * <p>
 * A KeeperException with error code KeeperException.BadVersion will be
 * thrown if the given version does not match the node's version.
 *
 * @param path
 * @param acl
 * @param version
 * @return the stat of the node.
 * @throws InterruptedException If the server transaction is interrupted.
 * @throws KeeperException If the server signals an error with a non-zero error code.
 * @throws org.apache.zookeeper.KeeperException.InvalidACLException If the acl is invalide.
 * @throws IllegalArgumentException if an invalid path is specified
 */
public Stat setACL(final String path, List<ACL> acl, int version)
    throws KeeperException, InterruptedException
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setACL);
    SetACLRequest request = new SetACLRequest();
    request.setPath(serverPath);
    if (acl != null && acl.size() == 0) {
        throw new KeeperException.InvalidACLException();
    }
    request.setAcl(acl);
    request.setVersion(version);
    SetACLResponse response = new SetACLResponse();
    ReplyHeader r = cnxn.submitRequest(h, request, response, null);
    if (r.getErr() != 0) {
        throw KeeperException.create(KeeperException.Code.get(r.getErr()),
                clientPath);
    }
    return response.getStat();
}
项目:bigstreams    文件:ZooKeeper.java   
/**
 * The Asynchronous version of setACL. The request doesn't actually until
 * the asynchronous callback is called.
 *
 * @see #setACL(String, List, int)
 */
public void setACL(final String path, List<ACL> acl, int version,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.setACL);
    SetACLRequest request = new SetACLRequest();
    request.setPath(serverPath);
    request.setAcl(acl);
    request.setVersion(version);
    SetACLResponse response = new SetACLResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, null);
}
项目:bigstreams    文件:ZooKeeper.java   
/**
 * The Asynchronous version of getChildren. The request doesn't actually
 * until the asynchronous callback is called.
 *
 * @see #getChildren(String, Watcher)
 */
public void getChildren(final String path, Watcher watcher,
        ChildrenCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new ChildWatchRegistration(watcher, clientPath);
    }

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getChildren);
    GetChildrenRequest request = new GetChildrenRequest();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    GetChildrenResponse response = new GetChildrenResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, wcb);
}
项目:bigstreams    文件:ZooKeeper.java   
/**
 * The Asynchronous version of getChildren. The request doesn't actually
 * until the asynchronous callback is called.
 *
 * @since 3.3.0
 * 
 * @see #getChildren(String, Watcher, Stat)
 */
public void getChildren(final String path, Watcher watcher,
        Children2Callback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new ChildWatchRegistration(watcher, clientPath);
    }

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getChildren2);
    GetChildren2Request request = new GetChildren2Request();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    GetChildren2Response response = new GetChildren2Response();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, wcb);
}
项目:SecureKeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of exists.
 *
 * @see #exists(String, Watcher)
 */
public void exists(final String path, Watcher watcher,
        StatCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new ExistsWatchRegistration(watcher, clientPath);
    }

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.exists);
    ExistsRequest request = new ExistsRequest();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    SetDataResponse response = new SetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, wcb);
}
项目:zookeeper-src-learning    文件:NettyServerCnxn.java   
@Override
public void process(WatchedEvent event) {
    ReplyHeader h = new ReplyHeader(-1, -1L, 0);
    if (LOG.isTraceEnabled()) {
        ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK,
                                 "Deliver event " + event + " to 0x"
                                 + Long.toHexString(this.sessionId)
                                 + " through " + this);
    }

    // Convert WatchedEvent to a type that can be sent over the wire
    WatcherEvent e = event.getWrapper();

    try {
        sendResponse(h, e, "notification");
    } catch (IOException e1) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Problem sending to " + getRemoteSocketAddress(), e1);
        }
        close();
    }
}
项目:SecureKeeper    文件:ZooKeeper.java   
/**
 * The asynchronous version of create.
 *
 * @see #create(String, byte[], List, CreateMode)
 */
public void create(final String path, byte data[], List<ACL> acl,
        CreateMode createMode, StringCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath, createMode.isSequential());

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(createMode.isContainer() ? ZooDefs.OpCode.createContainer : ZooDefs.OpCode.create);
    CreateRequest request = new CreateRequest();
    CreateResponse response = new CreateResponse();
    ReplyHeader r = new ReplyHeader();
    request.setData(data);
    request.setFlags(createMode.toFlag());
    request.setPath(serverPath);
    request.setAcl(acl);
    cnxn.queuePacket(h, r, request, response, cb, clientPath,
            serverPath, ctx, null);
}
项目:SecureKeeper    文件:ZooKeeper.java   
/**
 * Return the ACL and stat of the node of the given path.
 * <p>
 * A KeeperException with error code KeeperException.NoNode will be thrown
 * if no node with the given path exists.
 *
 * @param path
 *                the given path for the node
 * @param stat
 *                the stat of the node will be copied to this parameter if
 *                not null.
 * @return the ACL array of the given node.
 * @throws InterruptedException If the server transaction is interrupted.
 * @throws KeeperException If the server signals an error with a non-zero error code.
 * @throws IllegalArgumentException if an invalid path is specified
 */
public List<ACL> getACL(final String path, Stat stat)
    throws KeeperException, InterruptedException
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getACL);
    GetACLRequest request = new GetACLRequest();
    request.setPath(serverPath);
    GetACLResponse response = new GetACLResponse();
    ReplyHeader r = cnxn.submitRequest(h, request, response, null);
    if (r.getErr() != 0) {
        throw KeeperException.create(KeeperException.Code.get(r.getErr()),
                clientPath);
    }
    if (stat != null) {
        DataTree.copyStat(response.getStat(), stat);
    }
    return response.getAcl();
}
项目:zookeeper-src-learning    文件:ClientCnxn.java   
public void sendPacket(Record request, Record response, AsyncCallback cb, int opCode)
        throws IOException {
    // Generate Xid now because it will be sent immediately,
    // by call to sendThread.sendPacket() below.
    int xid = getXid();
    RequestHeader h = new RequestHeader();
    h.setXid(xid);
    h.setType(opCode);

    ReplyHeader r = new ReplyHeader();
    r.setXid(xid);

    Packet p = new Packet(h, r, request, response, null, false);
    p.cb = cb;
    sendThread.sendPacket(p);
}
项目:zookeeper-src-learning    文件:ZooKeeper.java   
/**
 * The asynchronous version of create.
 *
 * @see #create(String, byte[], List, CreateMode)
 */

public void create(final String path, byte data[], List<ACL> acl,
        CreateMode createMode,  StringCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath, createMode.isSequential());

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.create);
    CreateRequest request = new CreateRequest();
    CreateResponse response = new CreateResponse();
    ReplyHeader r = new ReplyHeader();
    request.setData(data);
    request.setFlags(createMode.toFlag());
    request.setPath(serverPath);
    request.setAcl(acl);
    cnxn.queuePacket(h, r, request, response, cb, clientPath,
            serverPath, ctx, null);
}
项目:SecureKeeper    文件:ZooKeeper.java   
private void removeWatches(int opCode, String path, Watcher watcher,
        WatcherType watcherType, boolean local, VoidCallback cb, Object ctx) {
    PathUtils.validatePath(path);
    final String clientPath = path;
    final String serverPath = prependChroot(clientPath);
    WatchDeregistration wcb = new WatchDeregistration(clientPath, watcher,
            watcherType, local, watchManager);

    RequestHeader h = new RequestHeader();
    h.setType(opCode);
    Record request = getRemoveWatchesRequest(opCode, watcherType,
            serverPath);

    cnxn.queuePacket(h, new ReplyHeader(), request, null, cb, clientPath,
            serverPath, ctx, null, wcb);
}
项目:zookeeper-src-learning    文件:ZooKeeper.java   
/**
 * The asynchronous version of getData.
 *
 * @see #getData(String, Watcher, Stat)
 */
public void getData(final String path, Watcher watcher,
        DataCallback cb, Object ctx)
{
    final String clientPath = path;
    PathUtils.validatePath(clientPath);

    // the watch contains the un-chroot path
    WatchRegistration wcb = null;
    if (watcher != null) {
        wcb = new DataWatchRegistration(watcher, clientPath);
    }

    final String serverPath = prependChroot(clientPath);

    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.getData);
    GetDataRequest request = new GetDataRequest();
    request.setPath(serverPath);
    request.setWatch(watcher != null);
    GetDataResponse response = new GetDataResponse();
    cnxn.queuePacket(h, new ReplyHeader(), request, response, cb,
            clientPath, serverPath, ctx, wcb);
}