本文整理汇总了Java中org.apache.zookeeper.ClientCnxn类的典型用法代码示例。如果您正苦于以下问题:Java ClientCnxn类的具体用法?Java ClientCnxn怎么用?Java ClientCnxn使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClientCnxn类属于org.apache.zookeeper包,在下文中一共展示了ClientCnxn类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processResult
import org.apache.zookeeper.ClientCnxn; //导入依赖的package包/类
public void processResult(int rc, String path, Object ctx, byte data[], Stat stat) {
// processResult() is used by ClientCnxn's sendThread to respond to
// data[] contains the Zookeeper Server's SASL token.
// ctx is the ZooKeeperSaslClient object. We use this object's respondToServer() method
// to reply to the Zookeeper Server's SASL token
ZooKeeperSaslClient client = ((ClientCnxn)ctx).zooKeeperSaslClient;
if (client == null) {
LOG.warn("sasl client was unexpectedly null: cannot respond to Zookeeper server.");
return;
}
byte[] usedata = data;
if (data != null) {
LOG.debug("ServerSaslResponseCallback(): saslToken server response: (length="+usedata.length+")");
}
else {
usedata = new byte[0];
LOG.debug("ServerSaslResponseCallback(): using empty data[] as server response (length="+usedata.length+")");
}
client.respondToServer(usedata, (ClientCnxn)ctx);
}
示例2: sendSaslPacket
import org.apache.zookeeper.ClientCnxn; //导入依赖的package包/类
private void sendSaslPacket(byte[] saslToken, ClientCnxn cnxn)
throws SaslException{
if (LOG.isDebugEnabled()) {
LOG.debug("ClientCnxn:sendSaslPacket:length="+saslToken.length);
}
GetSASLRequest request = new GetSASLRequest();
request.setToken(saslToken);
SetSASLResponse response = new SetSASLResponse();
ServerSaslResponseCallback cb = new ServerSaslResponseCallback();
try {
cnxn.sendPacket(request,response,cb, ZooDefs.OpCode.sasl);
} catch (IOException e) {
throw new SaslException("Failed to send SASL packet to server.",
e);
}
}
示例3: initialize
import org.apache.zookeeper.ClientCnxn; //导入依赖的package包/类
public void initialize(ClientCnxn cnxn) throws SaslException {
if (saslClient == null) {
saslState = SaslState.FAILED;
throw new SaslException("saslClient failed to initialize properly: it's null.");
}
if (saslState == SaslState.INITIAL) {
if (saslClient.hasInitialResponse()) {
sendSaslPacket(cnxn);
}
else {
byte[] emptyToken = new byte[0];
sendSaslPacket(emptyToken, cnxn);
}
saslState = SaslState.INTERMEDIATE;
}
}
示例4: injectSessionExpiration
import org.apache.zookeeper.ClientCnxn; //导入依赖的package包/类
public static void injectSessionExpiration(ZooKeeper zooKeeper)
{
try
{
WatchedEvent event = new WatchedEvent(Watcher.Event.EventType.None, Watcher.Event.KeeperState.Expired, null);
ClientCnxn clientCnxn = (ClientCnxn)cnxnField.get(zooKeeper);
Object eventThread = eventThreadField.get(clientCnxn);
queueEventMethod.invoke(eventThread, event);
queueEventOfDeathMethod.invoke(eventThread);
stateField.set(clientCnxn, ZooKeeper.States.CLOSED);
Object sendThread = sendThreadField.get(clientCnxn);
Object clientCnxnSocket = getClientCnxnSocketMethod.invoke(sendThread);
wakeupCnxnMethod.invoke(clientCnxnSocket);
}
catch ( ReflectiveOperationException e )
{
throw new RuntimeException("Could not inject session expiration using reflection", e);
}
}