@Override public void close() { CloseFuture future = session.close(false); try { future.await(CLOSE_TIMEOUT_MS); } catch (InterruptedException ex) { // it's fine to return--there isn't really any "error" here. } }
@Override public void closeImmediately() { CloseFuture future = session.close(true); try { future.await(CLOSE_TIMEOUT_MS); } catch (InterruptedException ex) { // it's fine to return--there isn't really any "error" here. } }
/** {@inheritDoc} */ @Override public void messageReceived (IoSession session, Object message) throws Exception { LOG.info("Server received: {}\n", message.toString().trim()); String str = message.toString(); if(str.trim().equalsIgnoreCase(m_conversation.getExpectedClose())) { if(m_conversation.getExpectedCloseResponse() != null) { session.write(m_conversation.getExpectedCloseResponse()); } if (!session.close(false).await(500)) { LOG.warn("Conversation did not complete promptly in 500ms"); } return; } }
public void close() { logger.info("session will be closed now"); closeFuture.setClosed(); try { // allow some time to flush before closibng if(!minaSession.close(false).await(5000, TimeUnit.MILLISECONDS)) { // no really close if necessary minaSession.close(true); } } catch (InterruptedException e) { // ignore } logger.info("session closed"); }
/** * Closes all managed sessions of an Initiator/Acceptor. * * @param ioService Acceptor or Initiator implementation * @param awaitTermination whether to wait for underlying ExecutorService to terminate * @param logger used for logging WARNING when IoSession could not be closed */ public static void closeManagedSessionsAndDispose(IoService ioService, boolean awaitTermination, Logger logger) { Map<Long, IoSession> managedSessions = ioService.getManagedSessions(); for (IoSession ioSession : managedSessions.values()) { if (!ioSession.isClosing()) { CloseFuture closeFuture = ioSession.closeNow(); boolean completed = false; try { completed = closeFuture.await(1000, TimeUnit.MILLISECONDS); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } if (!completed) { logger.warn("Could not close IoSession {}", ioSession); } } } if (!ioService.isDisposing()) { ioService.dispose(awaitTermination); } }
/** * Closes all managed sessions of an Initiator/Acceptor. * * @param ioService Acceptor or Initiator implementation * @param awaitTermination whether to wait for underlying ExecutorService to terminate * @param logger used for logging WARNING when IoSession could not be closed */ public static void closeManagedSessionsAndDispose(IoService ioService, boolean awaitTermination, Logger logger) { Map<Long, IoSession> managedSessions = ioService.getManagedSessions(); for (IoSession ioSession : managedSessions.values()) { if (!ioSession.isClosing()) { CloseFuture closeFuture = ioSession.closeNow(); boolean completed = false; try { completed = closeFuture.await(1000, TimeUnit.MILLISECONDS); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } if (!completed) { logger.warn("Could not close IoSession {}", ioSession); } } } if (!ioService.isDisposing()) { ioService.dispose(awaitTermination); } }
/** {@inheritDoc} */ @Override public void disconnect() { if (future != null) { try { // session will be null if connect failed if (session != null) { // close, now CloseFuture closeFuture = session.closeNow(); // now wait for the close to be completed if (closeFuture.await(1000, TimeUnit.MILLISECONDS)) { if (!future.isCanceled()) { if (future.cancel()) { log.debug("Connect future cancelled after close future"); } } } } else if (future.cancel()) { log.debug("Connect future cancelled"); } } catch (Exception e) { log.warn("Exception during disconnect", e); } finally { // we can now dispose the connector socketConnector.dispose(false); } } super.disconnect(); }