本文整理汇总了Java中org.apache.zookeeper.server.ServerCnxn类的典型用法代码示例。如果您正苦于以下问题:Java ServerCnxn类的具体用法?Java ServerCnxn怎么用?Java ServerCnxn使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServerCnxn类属于org.apache.zookeeper.server包,在下文中一共展示了ServerCnxn类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateSession
import org.apache.zookeeper.server.ServerCnxn; //导入依赖的package包/类
/**
* validate a session for a client
*
* @param clientId
* the client to be revalidated
* @param timeout
* the timeout for which the session is valid
* @return
* @throws IOException
*/
void validateSession(ServerCnxn cnxn, long clientId, int timeout)
throws IOException {
LOG.info("Revalidating client: 0x" + Long.toHexString(clientId));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeLong(clientId);
dos.writeInt(timeout);
dos.close();
QuorumPacket qp = new QuorumPacket(Leader.REVALIDATE, -1, baos
.toByteArray(), null);
pendingRevalidations.put(clientId, cnxn);
if (LOG.isTraceEnabled()) {
ZooTrace.logTraceMessage(LOG,
ZooTrace.SESSION_TRACE_MASK,
"To validate session 0x"
+ Long.toHexString(clientId));
}
writePacket(qp, true);
}
示例2: revalidate
import org.apache.zookeeper.server.ServerCnxn; //导入依赖的package包/类
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);
}
}
示例3: handleAuthentication
import org.apache.zookeeper.server.ServerCnxn; //导入依赖的package包/类
public KeeperException.Code
handleAuthentication(ServerCnxn cnxn, byte[] authData)
{
String id = new String(authData);
try {
String digest = generateDigest(id);
if (digest.equals(superDigest)) {
cnxn.addAuthInfo(new Id("super", ""));
}
cnxn.addAuthInfo(new Id(getScheme(), digest));
return KeeperException.Code.OK;
} catch (NoSuchAlgorithmException e) {
LOG.error("Missing algorithm",e);
}
return KeeperException.Code.AUTHFAILED;
}
示例4: revalidate
import org.apache.zookeeper.server.ServerCnxn; //导入依赖的package包/类
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);
}
}
示例5: commandRun
import org.apache.zookeeper.server.ServerCnxn; //导入依赖的package包/类
@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());
}
}
示例6: testFourLetterWordsAllDisabledByDefault
import org.apache.zookeeper.server.ServerCnxn; //导入依赖的package包/类
@Test(timeout=30000)
public void testFourLetterWordsAllDisabledByDefault() throws Exception {
stopServer();
ServerCnxn.resetWhiteList();
System.setProperty("zookeeper.4lw.commands.whitelist", "stat");
startServer();
// Default white list for 3.5.x is empty, so all command should fail.
verifyAllCommandsFail();
TestableZooKeeper zk = createClient();
verifyAllCommandsFail();
zk.getData("/", true, null);
verifyAllCommandsFail();
zk.close();
verifyFuzzyMatch("stat", "Outstanding");
verifyAllCommandsFail();
}
示例7: testFourLetterWordsEnableSomeCommands
import org.apache.zookeeper.server.ServerCnxn; //导入依赖的package包/类
@Test(timeout=30000)
public void testFourLetterWordsEnableSomeCommands() throws Exception {
stopServer();
ServerCnxn.resetWhiteList();
System.setProperty("zookeeper.4lw.commands.whitelist", "stat, ruok, isro");
startServer();
// stat, ruok and isro are white listed.
verifyFuzzyMatch("stat", "Outstanding");
verifyExactMatch("ruok", "imok");
verifyExactMatch("isro", "rw");
// Rest of commands fail.
verifyExactMatch("conf", generateExpectedMessage("conf"));
verifyExactMatch("cons", generateExpectedMessage("cons"));
verifyExactMatch("crst", generateExpectedMessage("crst"));
verifyExactMatch("dump", generateExpectedMessage("dump"));
verifyExactMatch("envi", generateExpectedMessage("envi"));
verifyExactMatch("gtmk", generateExpectedMessage("gtmk"));
verifyExactMatch("stmk", generateExpectedMessage("stmk"));
verifyExactMatch("srst", generateExpectedMessage("srst"));
verifyExactMatch("wchc", generateExpectedMessage("wchc"));
verifyExactMatch("wchp", generateExpectedMessage("wchp"));
verifyExactMatch("wchs", generateExpectedMessage("wchs"));
verifyExactMatch("mntr", generateExpectedMessage("mntr"));
}
示例8: commandRun
import org.apache.zookeeper.server.ServerCnxn; //导入依赖的package包/类
@Override
public void commandRun() {
if (zkServer == null) {
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());
}
}
示例9: revalidateSession
import org.apache.zookeeper.server.ServerCnxn; //导入依赖的package包/类
@Override
protected void revalidateSession(ServerCnxn cnxn, long sessionId,
int sessionTimeout) throws IOException {
super.revalidateSession(cnxn, sessionId, sessionTimeout);
try {
// setowner as the leader itself, unless updated
// via the follower handlers
setOwner(sessionId, ServerCnxn.me);
} catch (SessionExpiredException e) {
// this is ok, it just means that the session revalidation failed.
}
}
示例10: handleAuthentication
import org.apache.zookeeper.server.ServerCnxn; //导入依赖的package包/类
public KeeperException.Code
handleAuthentication(ServerCnxn cnxn, byte[] authData)
{
// Should never call this: SASL authentication is negotiated at session initiation.
// TODO: consider substituting current implementation of direct ClientCnxn manipulation with
// a call to this method (SASLAuthenticationProvider:handleAuthentication()) at session initiation.
return KeeperException.Code.AUTHFAILED;
}
示例11: handleAuthentication
import org.apache.zookeeper.server.ServerCnxn; //导入依赖的package包/类
public KeeperException.Code
handleAuthentication(ServerCnxn cnxn, byte[] authData)
{
String id = cnxn.getRemoteSocketAddress().getAddress().getHostAddress();
cnxn.addAuthInfo(new Id(getScheme(), id));
return KeeperException.Code.OK;
}
示例12: revalidateSession
import org.apache.zookeeper.server.ServerCnxn; //导入依赖的package包/类
@Override
protected void revalidateSession(ServerCnxn cnxn, long sessionId,
int sessionTimeout) throws IOException {
if (upgradeableSessionTracker.isLocalSession(sessionId)) {
super.revalidateSession(cnxn, sessionId, sessionTimeout);
} else {
getLearner().validateSession(cnxn, sessionId, sessionTimeout);
}
}