Search in sources :

Example 1 with ConnectRequest

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

the class ConnectRequest method compareTo.

public int compareTo(Object peer_) throws ClassCastException {
    if (!(peer_ instanceof ConnectRequest)) {
        throw new ClassCastException("Comparing different types of records.");
    }
    ConnectRequest peer = (ConnectRequest) peer_;
    int ret = 0;
    ret = (protocolVersion == peer.protocolVersion) ? 0 : ((protocolVersion < peer.protocolVersion) ? -1 : 1);
    if (ret != 0)
        return ret;
    ret = (lastZxidSeen == peer.lastZxidSeen) ? 0 : ((lastZxidSeen < peer.lastZxidSeen) ? -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 : ConnectRequest(org.apache.zookeeper_voltpatches.proto.ConnectRequest)

Example 2 with ConnectRequest

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

the class ConnectRequest method equals.

@Override
public boolean equals(Object peer_) {
    if (!(peer_ instanceof ConnectRequest)) {
        return false;
    }
    if (peer_ == this) {
        return true;
    }
    ConnectRequest peer = (ConnectRequest) peer_;
    boolean ret = false;
    ret = (protocolVersion == peer.protocolVersion);
    if (!ret)
        return ret;
    ret = (lastZxidSeen == peer.lastZxidSeen);
    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 : ConnectRequest(org.apache.zookeeper_voltpatches.proto.ConnectRequest)

Example 3 with ConnectRequest

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

the class NIOServerCnxn method readConnectRequest.

private void readConnectRequest() throws IOException, InterruptedException {
    BinaryInputArchive bia = BinaryInputArchive.getArchive(new ByteBufferInputStream(incomingBuffer));
    ConnectRequest connReq = new ConnectRequest();
    connReq.deserialize(bia, "connect");
    if (LOG.isDebugEnabled()) {
        LOG.debug("Session establishment request from client " + sock.socket().getRemoteSocketAddress() + " client's lastZxid is 0x" + Long.toHexString(connReq.getLastZxidSeen()));
    }
    if (zk == null) {
        throw new IOException("ZooKeeperServer not running");
    }
    if (connReq.getLastZxidSeen() > zk.getZKDatabase().getDataTreeLastProcessedZxid()) {
        String msg = "Refusing session request for client " + sock.socket().getRemoteSocketAddress() + " as it has seen zxid 0x" + Long.toHexString(connReq.getLastZxidSeen()) + " our last zxid is 0x" + Long.toHexString(zk.getZKDatabase().getDataTreeLastProcessedZxid()) + " client must try another server";
        LOG.info(msg);
        throw new CloseRequestException(msg);
    }
    sessionTimeout = connReq.getTimeOut();
    byte[] passwd = connReq.getPasswd();
    int minSessionTimeout = zk.getMinSessionTimeout();
    if (sessionTimeout < minSessionTimeout) {
        sessionTimeout = minSessionTimeout;
    }
    int maxSessionTimeout = zk.getMaxSessionTimeout();
    if (sessionTimeout > maxSessionTimeout) {
        sessionTimeout = maxSessionTimeout;
    }
    // We don't want to receive any packets until we are sure that the
    // session is setup
    disableRecv();
    if (connReq.getSessionId() != 0) {
        throw new IOException("Reopening sessions is not supported anymore");
    } else {
        LOG.info("Client attempting to establish new session at " + sock.socket().getRemoteSocketAddress());
        zk.createSession(this, passwd, sessionTimeout);
    }
    initialized = true;
}
Also used : BinaryInputArchive(org.apache.jute_voltpatches.BinaryInputArchive) ConnectRequest(org.apache.zookeeper_voltpatches.proto.ConnectRequest) IOException(java.io.IOException)

Aggregations

ConnectRequest (org.apache.zookeeper_voltpatches.proto.ConnectRequest)3 IOException (java.io.IOException)1 BinaryInputArchive (org.apache.jute_voltpatches.BinaryInputArchive)1