Search in sources :

Example 1 with ServerCnxn

use of org.apache.zookeeper.server.ServerCnxn in project zookeeper by apache.

the class RemoveWatchesTest method isServerSessionWatcher.

/**
     * Checks if a session is registered with the server as a watcher.
     *
     * @param long sessionId the session ID to check
     * @param path the path to check for watchers
     * @param type the type of watcher
     * @return true if the client session is a watcher on path for the type
     */
private boolean isServerSessionWatcher(long sessionId, String path, WatcherType type) {
    Set<ServerCnxn> cnxns = new HashSet<>();
    CollectionUtils.addAll(cnxns, serverFactory.getConnections().iterator());
    for (ServerCnxn cnxn : cnxns) {
        if (cnxn.getSessionId() == sessionId) {
            return getServer(serverFactory).getZKDatabase().getDataTree().containsWatcher(path, type, cnxn);
        }
    }
    return false;
}
Also used : ServerCnxn(org.apache.zookeeper.server.ServerCnxn) HashSet(java.util.HashSet)

Example 2 with ServerCnxn

use of org.apache.zookeeper.server.ServerCnxn in project zookeeper by apache.

the class Learner method revalidate.

protected void revalidate(QuorumPacket qp) throws IOException {
    ByteArrayInputStream bis = new ByteArrayInputStream(qp.getData());
    DataInputStream dis = new DataInputStream(bis);
    long sessionId = dis.readLong();
    boolean valid = dis.readBoolean();
    ServerCnxn cnxn = pendingRevalidations.remove(sessionId);
    if (cnxn == null) {
        LOG.warn("Missing session 0x" + Long.toHexString(sessionId) + " for validation");
    } else {
        zk.finishSessionInit(cnxn, valid);
    }
    if (LOG.isTraceEnabled()) {
        ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, "Session 0x" + Long.toHexString(sessionId) + " is valid: " + valid);
    }
}
Also used : ServerCnxn(org.apache.zookeeper.server.ServerCnxn) ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream)

Example 3 with ServerCnxn

use of org.apache.zookeeper.server.ServerCnxn in project zookeeper by apache.

the class ConsCommand method commandRun.

@Override
public void commandRun() {
    if (!isZKServerRunning()) {
        pw.println(ZK_NOT_SERVING);
    } else {
        for (ServerCnxn c : factory.getConnections()) {
            c.dumpConnectionInfo(pw, false);
            pw.println();
        }
        pw.println();
    }
}
Also used : ServerCnxn(org.apache.zookeeper.server.ServerCnxn)

Example 4 with ServerCnxn

use of org.apache.zookeeper.server.ServerCnxn in project zookeeper by apache.

the class StatCommand method commandRun.

@Override
public void commandRun() {
    if (!isZKServerRunning()) {
        pw.println(ZK_NOT_SERVING);
    } else {
        pw.print("Zookeeper version: ");
        pw.println(Version.getFullVersion());
        if (zkServer instanceof ReadOnlyZooKeeperServer) {
            pw.println("READ-ONLY mode; serving only read-only clients");
        }
        if (len == FourLetterCommands.statCmd) {
            LOG.info("Stat command output");
            pw.println("Clients:");
            for (ServerCnxn c : factory.getConnections()) {
                c.dumpConnectionInfo(pw, true);
                pw.println();
            }
            pw.println();
        }
        pw.print(zkServer.serverStats().toString());
        pw.print("Node count: ");
        pw.println(zkServer.getZKDatabase().getNodeCount());
    }
}
Also used : ServerCnxn(org.apache.zookeeper.server.ServerCnxn) ReadOnlyZooKeeperServer(org.apache.zookeeper.server.quorum.ReadOnlyZooKeeperServer)

Aggregations

ServerCnxn (org.apache.zookeeper.server.ServerCnxn)4 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 HashSet (java.util.HashSet)1 ReadOnlyZooKeeperServer (org.apache.zookeeper.server.quorum.ReadOnlyZooKeeperServer)1