Search in sources :

Example 1 with ConnectResponse

use of org.apache.zookeeper_voltpatches.proto.ConnectResponse in project voltdb by VoltDB.

the class NIOServerCnxn method finishSessionInit.

@Override
public void finishSessionInit(boolean valid) {
    // register with JMX
    try {
        jmxConnectionBean = new ConnectionBean(this, zk);
        MBeanRegistry.getInstance().register(jmxConnectionBean, zk.jmxServerBean);
    } catch (Exception e) {
        LOG.warn("Failed to register with JMX", e);
        jmxConnectionBean = null;
    }
    try {
        ConnectResponse rsp = new ConnectResponse(0, valid ? sessionTimeout : // send 0 if session is no
        0, // send 0 if session is no
        valid ? sessionId : 0, // longer valid
        valid ? zk.generatePasswd(sessionId) : new byte[16]);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputArchive bos = BinaryOutputArchive.getArchive(baos);
        bos.writeInt(-1, "len");
        rsp.serialize(bos, "connect");
        baos.close();
        ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());
        bb.putInt(bb.remaining() - 4).rewind();
        sendBuffer(bb);
        if (!valid) {
            LOG.info("Invalid session 0x" + Long.toHexString(sessionId) + " for client " + sock.socket().getRemoteSocketAddress() + ", probably expired");
            sendCloseSession();
        } else {
            LOG.info("Established session 0x" + Long.toHexString(sessionId) + " with negotiated timeout " + sessionTimeout + " for client " + sock.socket().getRemoteSocketAddress());
        }
        // Now that the session is ready we can start receiving packets
        synchronized (this.factory) {
            sk.selector().wakeup();
            enableRecv();
        }
    } catch (Exception e) {
        LOG.warn("Exception while establishing session, closing", e);
        close();
    }
}
Also used : BinaryOutputArchive(org.apache.jute_voltpatches.BinaryOutputArchive) ConnectResponse(org.apache.zookeeper_voltpatches.proto.ConnectResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer) CancelledKeyException(java.nio.channels.CancelledKeyException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) IOException(java.io.IOException)

Example 2 with ConnectResponse

use of org.apache.zookeeper_voltpatches.proto.ConnectResponse in project voltdb by VoltDB.

the class ConnectResponse method equals.

@Override
public boolean equals(Object peer_) {
    if (!(peer_ instanceof ConnectResponse)) {
        return false;
    }
    if (peer_ == this) {
        return true;
    }
    ConnectResponse peer = (ConnectResponse) peer_;
    boolean ret = false;
    ret = (protocolVersion == peer.protocolVersion);
    if (!ret)
        return ret;
    ret = (timeOut == peer.timeOut);
    if (!ret)
        return ret;
    ret = (sessionId == peer.sessionId);
    if (!ret)
        return ret;
    ret = org.apache.jute_voltpatches.Utils.bufEquals(passwd, peer.passwd);
    if (!ret)
        return ret;
    return ret;
}
Also used : ConnectResponse(org.apache.zookeeper_voltpatches.proto.ConnectResponse)

Example 3 with ConnectResponse

use of org.apache.zookeeper_voltpatches.proto.ConnectResponse in project voltdb by VoltDB.

the class ConnectResponse method compareTo.

public int compareTo(Object peer_) throws ClassCastException {
    if (!(peer_ instanceof ConnectResponse)) {
        throw new ClassCastException("Comparing different types of records.");
    }
    ConnectResponse peer = (ConnectResponse) peer_;
    int ret = 0;
    ret = (protocolVersion == peer.protocolVersion) ? 0 : ((protocolVersion < peer.protocolVersion) ? -1 : 1);
    if (ret != 0)
        return ret;
    ret = (timeOut == peer.timeOut) ? 0 : ((timeOut < peer.timeOut) ? -1 : 1);
    if (ret != 0)
        return ret;
    ret = (sessionId == peer.sessionId) ? 0 : ((sessionId < peer.sessionId) ? -1 : 1);
    if (ret != 0)
        return ret;
    {
        byte[] my = passwd;
        byte[] ur = peer.passwd;
        ret = org.apache.jute_voltpatches.Utils.compareBytes(my, 0, my.length, ur, 0, ur.length);
    }
    if (ret != 0)
        return ret;
    return ret;
}
Also used : ConnectResponse(org.apache.zookeeper_voltpatches.proto.ConnectResponse)

Aggregations

ConnectResponse (org.apache.zookeeper_voltpatches.proto.ConnectResponse)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 CancelledKeyException (java.nio.channels.CancelledKeyException)1 BinaryOutputArchive (org.apache.jute_voltpatches.BinaryOutputArchive)1 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)1