eventThreadField.setAccessible(true); EventThread eventThread = (EventThread) eventThreadField.get(clientCnxn); sendThread.join(CONNECTION_TIMEOUT); eventThread.join(CONNECTION_TIMEOUT); Assert.assertFalse("SendThread did not shutdown after authFail", sendThread.isAlive()); Assert.assertFalse("EventThread did not shutdown after authFail", eventThread.isAlive());
serverAddress = hostProvider.next(1000); startConnect(serverAddress); clientCnxnSocket.updateLastSendAndHeard(); sendPing(); clientCnxnSocket.updateLastSend(); } else { pingRwTimeout = Math.min(2*pingRwTimeout, maxPingRwTimeout); pingRwServer(); cleanAndNotifyState(); cleanup();
/** * Shutdown the send/event threads. This method should not be called * directly - rather it should be called as part of close operation. This * method is primarily here to allow the tests to verify disconnection * behavior. */ public void disconnect() { if (LOG.isDebugEnabled()) { LOG.debug("Disconnecting client for session: 0x" + Long.toHexString(getSessionId())); } sendThread.close(); eventThread.queueEventOfDeath(); }
startConnect(); lastSend = now; lastHeard = now; int timeToNextPing = readTimeout/2 - idleSend; if (timeToNextPing <= 0) { sendPing(); lastSend = now; enableWrite(); } else { if (timeToNextPing < to) { lastHeard = now; lastSend = now; primeConnection(k); if (doIO()) { lastHeard = now; enableWrite(); } else { disableWrite(); cleanup(); if (zooKeeper.state.isAlive()) { eventThread.queueEvent(new WatchedEvent( cleanup(); try {
if (incomingBuffer == lenBuffer) { recvCount++; readLength(); } else if (!initialized) { readConnectResult(); enableRead(); if (!outgoingQueue.isEmpty()) { enableWrite(); initialized = true; } else { readResponse(); lenBuffer.clear(); incomingBuffer = lenBuffer; disableWrite(); } else { enableWrite();
readTimeout = sessionTimeout * 2 / 3; Collections.shuffle(serverAddrs); sendThread = new SendThread(); eventThread = new EventThread();
sock.socket().setSoLinger(false, -1); sock.socket().setTcpNoDelay(true); setName(getName().replaceAll("\\(.*\\)", "(" + addr.getHostName() + ":" + addr.getPort() + ")")); sockKey = sock.register(selector, SelectionKey.OP_CONNECT); if (sock.connect(addr)) { primeConnection(sockKey);
/** * Wait up to wait milliseconds for the underlying threads to shutdown. * THIS METHOD IS EXPECTED TO BE USED FOR TESTING ONLY!!! * * @since 3.3.0 * * @param wait max wait in milliseconds * @return true iff all threads are shutdown, otw false */ protected boolean testableWaitForShutdown(int wait) throws InterruptedException { cnxn.sendThread.join(wait); if (cnxn.sendThread.isAlive()) return false; cnxn.eventThread.join(wait); if (cnxn.eventThread.isAlive()) return false; return true; }
/** * Shutdown the send/event threads. This method should not be called * directly - rather it should be called as part of close operation. This * method is primarily here to allow the tests to verify disconnection * behavior. */ public void disconnect() { if (LOG.isDebugEnabled()) { LOG.debug("Disconnecting client for session: 0x" + Long.toHexString(getSessionId())); } sendThread.close(); eventThread.queueEventOfDeath(); }
SendThread() { super(currentThread().getName() + "-SendThread()"); zooKeeper.state = States.CONNECTING; setUncaughtExceptionHandler(uncaughtExceptionHandler); setDaemon(true); }
serverAddress = hostProvider.next(1000); startConnect(serverAddress); clientCnxnSocket.updateLastSendAndHeard(); sendPing(); clientCnxnSocket.updateLastSend(); } else { pingRwTimeout = Math.min(2*pingRwTimeout, maxPingRwTimeout); pingRwServer(); e); cleanup(); if (state.isAlive()) { eventThread.queueEvent(new WatchedEvent( cleanup(); clientCnxnSocket.close(); if (state.isAlive()) {
enableRead(); if (findSendablePacket(outgoingQueue, cnxn.sendThread.clientTunneledAuthenticationInProgress()) != null) { initialized = true; } else { sendThread.readResponse(incomingBuffer); lenBuffer.clear(); incomingBuffer = lenBuffer; synchronized(outgoingQueue) { Packet p = findSendablePacket(outgoingQueue, cnxn.sendThread.clientTunneledAuthenticationInProgress());
readOnly = canBeReadOnly; sendThread = new SendThread(clientCnxnSocket); eventThread = new EventThread();
if (sc.finishConnect()) { updateLastSendAndHeard(); sendThread.primeConnection(); if (sendThread.getZkState().isConnected()) { synchronized(outgoingQueue) { if (findSendablePacket(outgoingQueue, cnxn.sendThread.clientTunneledAuthenticationInProgress()) != null) { enableWrite();
enableRead(); if (findSendablePacket(outgoingQueue, sendThread.tunnelAuthInProgress()) != null) { initialized = true; } else { sendThread.readResponse(incomingBuffer); lenBuffer.clear(); incomingBuffer = lenBuffer; sendThread.tunnelAuthInProgress());
private void startConnect(InetSocketAddress addr) throws IOException { // initializing it for new connection saslLoginFailed = false; state = States.CONNECTING; setName(getName().replaceAll("\\(.*\\)", "(" + addr.getHostName() + ":" + addr.getPort() + ")")); if (ZooKeeperSaslClient.isEnabled()) { try { String principalUserName = System.getProperty( ZK_SASL_CLIENT_USERNAME, "zookeeper"); zooKeeperSaslClient = new ZooKeeperSaslClient( principalUserName+"/"+addr.getHostName()); } catch (LoginException e) { // An authentication error occurred when the SASL client tried to initialize: // for Kerberos this means that the client failed to authenticate with the KDC. // This is different from an authentication error that occurs during communication // with the Zookeeper server, which is handled below. LOG.warn("SASL configuration failed: " + e + " Will continue connection to Zookeeper server without " + "SASL authentication, if Zookeeper server allows it."); eventThread.queueEvent(new WatchedEvent( Watcher.Event.EventType.None, Watcher.Event.KeeperState.AuthFailed, null)); saslLoginFailed = true; } } logStartConnect(addr); clientCnxnSocket.connect(addr); }
incomingBuffer = lenBuffer; sendThread.primeConnection(); updateNow(); updateLastSendAndHeard(); if (sendThread.tunnelAuthInProgress()) { waitSasl.drainPermits(); needSasl.set(true);
/** * Wait up to wait milliseconds for the underlying threads to shutdown. * THIS METHOD IS EXPECTED TO BE USED FOR TESTING ONLY!!! * * @since 3.3.0 * * @param wait max wait in milliseconds * @return true iff all threads are shutdown, otw false */ protected boolean testableWaitForShutdown(int wait) throws InterruptedException { cnxn.sendThread.join(wait); if (cnxn.sendThread.isAlive()) return false; cnxn.eventThread.join(wait); if (cnxn.eventThread.isAlive()) return false; return true; }
readOnly = canBeReadOnly; sendThread = new SendThread(clientCnxnSocket); eventThread = new EventThread(); this.clientConfig=zooKeeper.getClientConfig();
updateLastHeard(); } else { sendThread.readResponse(incomingBuffer); lenBuffer.clear(); incomingBuffer = lenBuffer;