@Override public void cleanup() { cnxn.close(); } }
@SuppressWarnings("unchecked") private void closeSessionWithoutWakeup(long sessionId) { NIOServerCnxn cnxn = (NIOServerCnxn) sessionMap.remove(sessionId); if (cnxn != null) { try { cnxn.close(); } catch (Exception e) { LOG.warn("exception during session close", e); } } }
/** * clean up the socket related to a command and also make sure we flush the * data before we do that * * @param pwriter * the pwriter for a command socket */ private void cleanupWriterSocket(PrintWriter pwriter) { try { if (pwriter != null) { pwriter.flush(); pwriter.close(); } } catch (Exception e) { LOG.info("Error closing PrintWriter ", e); } finally { try { close(); } catch (Exception e) { LOG.error("Error closing a command socket ", e); } } }
public void run() { try { while (!stopped) { long waitTime = cnxnExpiryQueue.getWaitTime(); if (waitTime > 0) { Thread.sleep(waitTime); continue; } for (NIOServerCnxn conn : cnxnExpiryQueue.poll()) { conn.close(); } } } catch (InterruptedException e) { LOG.info("ConnnectionExpirerThread interrupted"); } } }
/** * clear all the connections in the selector * */ @Override @SuppressWarnings("unchecked") synchronized public void closeAll() { selector.wakeup(); HashSet<NIOServerCnxn> cnxns; synchronized (this.cnxns) { cnxns = (HashSet<NIOServerCnxn>)this.cnxns.clone(); } // got to clear all the connections that we have in the selector for (NIOServerCnxn cnxn: cnxns) { try { // don't hold this.cnxns lock as deadlock may occur cnxn.close(); } catch (Exception e) { LOG.warn("Ignoring exception closing cnxn sessionid 0x" + Long.toHexString(cnxn.sessionId), e); } } }
public void doWork() throws InterruptedException { if (!key.isValid()) { selectorThread.cleanupSelectionKey(key); return; } if (key.isReadable() || key.isWritable()) { cnxn.doIO(key); // Check if we shutdown or doIO() closed this connection if (stopped) { cnxn.close(); return; } if (!key.isValid()) { selectorThread.cleanupSelectionKey(key); return; } touchCnxn(cnxn); } // Mark this connection as once again ready for selection cnxn.enableSelectable(); // Push an update request on the queue to resume selecting // on the current set of interest ops, which may have changed // as a result of the I/O operations we just performed. if (!selectorThread.addInterestOpsUpdateRequest(key)) { cnxn.close(); } }
LOG.debug("CancelledKeyException stack trace", e); close(); } catch (CloseRequestException e) { close(); } catch (EndOfStreamException e) { LOG.warn(e.getMessage()); close(); } catch (ClientCnxnLimitException e) { + Long.toHexString(sessionId) + ": " + e.getMessage()); close(); } catch (IOException e) { LOG.warn("Exception causing close of session 0x" LOG.debug("IOException stack trace", e); close();
NIOServerCnxn cnxn = (NIOServerCnxn) key.attachment(); if (cnxn.isSelectable()) { cnxn.close();
/** * clean up the socket related to a command and also make sure we flush the * data before we do that * * @param pwriter * the pwriter for a command socket */ private void cleanupWriterSocket(PrintWriter pwriter) { try { if (pwriter != null) { pwriter.flush(); pwriter.close(); } } catch (Exception e) { LOG.info("Error closing PrintWriter ", e); } finally { try { close(); } catch (Exception e) { LOG.error("Error closing a command socket ", e); } } }
@SuppressWarnings("unchecked") private void closeSessionWithoutWakeup(long sessionId) { HashSet<NIOServerCnxn> cnxns; synchronized (this.cnxns) { cnxns = (HashSet<NIOServerCnxn>)this.cnxns.clone(); } for (NIOServerCnxn cnxn : cnxns) { if (cnxn.sessionId == sessionId) { try { cnxn.close(); } catch (Exception e) { LOG.warn("exception during session close", e); } break; } } } }
/** * Clear all the connections in the selector. * * You must first close ss (the serversocketchannel) if you wish * to block any new connections from being established. * */ @SuppressWarnings("unchecked") synchronized public void clear() { selector.wakeup(); HashSet<NIOServerCnxn> cnxns; synchronized (this.cnxns) { cnxns = (HashSet<NIOServerCnxn>)this.cnxns.clone(); } // got to clear all the connections that we have in the selector for (NIOServerCnxn cnxn: cnxns) { try { // don't hold this.cnxns lock as deadlock may occur cnxn.close(); } catch (Exception e) { LOG.warn("Ignoring exception closing cnxn sessionid 0x" + Long.toHexString(cnxn.sessionId), e); } } }