/** * @see IoSession#getCloseFuture() */ public CloseFuture getCloseFuture() { return wrappedSession.getCloseFuture(); }
@Override public Object invoke(Invocation invocation) throws Throwable { session.getCloseFuture().setClosed(); return null; } }
/** * Fires a {@link IoEventType#SESSION_IDLE} event to any applicable sessions * in the specified collection. * * @param sessions The sessions that are notified * @param currentTime the current time (i.e. {@link System#currentTimeMillis()}) */ public static void notifyIdleness(Iterator<? extends IoSession> sessions, long currentTime) { while (sessions.hasNext()) { IoSession session = sessions.next(); if (!session.getCloseFuture().isClosed()) { notifyIdleSession(session, currentTime); } } }
/** * Fires a {@link IoEventType#SESSION_IDLE} event to any applicable sessions * in the specified collection. * * @param sessions The sessions that are notified * @param currentTime the current time (i.e. {@link System#currentTimeMillis()}) */ public static void notifyIdleness(Iterator<? extends IoSession> sessions, long currentTime) { while (sessions.hasNext()) { IoSession session = sessions.next(); if (!session.getCloseFuture().isClosed()) { notifyIdleSession(session, currentTime); } } }
public MinaBackedSessionContext(ServerRuntimeContext serverRuntimeContext, SessionStateHolder sessionStateHolder, IoSession minaSession) { super(serverRuntimeContext, sessionStateHolder); this.minaSession = minaSession; closeFuture = minaSession.getCloseFuture(); closeFuture.addListener(this); sessionStateHolder.setState(SessionState.INITIATED); // connection established }
/** * Stop communicating with the IT-100 and release the port. * @throws Exception If there is an error while trying to close the port. */ public void disconnect() throws Exception { if (session != null) { session.getCloseFuture().awaitUninterruptibly(); } if (connector != null) { connector.dispose(); } }
/** * 关闭连接 * @param connection * @throws InterruptedException * @author 唐延波 * @date 2015-6-24 */ @Override public void close(ConnectFuture connection) throws InterruptedException{ connection.getSession().getCloseFuture().awaitUninterruptibly(); }
@Override public void operationComplete(ConnectFuture future) { try { // Add a listener to the CloseFuture that will dispose of the connector once the // conversation is complete future.getSession().getCloseFuture().addListener(new IoFutureListener<CloseFuture>() { @Override public void operationComplete(CloseFuture future) { LOG.debug("Disposing of connector: {}", Thread.currentThread().getName()); connector.dispose(); } }); } catch (RuntimeIoException e) { LOG.debug("Exception of type {} caught, disposing of connector: {}", e.getClass().getName(), Thread.currentThread().getName(), e); // This will be thrown in the event of a ConnectException for example connector.dispose(); } } };
@Override public void operationComplete(ConnectFuture future) { if (future.isConnected()) { IoSession newSession = future.getSession(); newSession.getCloseFuture().addListener(new IoFutureListener<CloseFuture>() { @Override public void operationComplete(CloseFuture future) { session.set(null); if (reconnect.get()) { scheduler.schedule(connectTask, reconnectDelay, TimeUnit.MILLISECONDS); } } }); session.set(newSession); } else { scheduler.schedule(connectTask, reconnectDelay, TimeUnit.MILLISECONDS); } } });
/** * {@inheritDoc} */ @Override public void remove(IoSession session) { if (!session.getCloseFuture().isClosed()) { session.getFilterChain().fireSessionClosed(); } }
public void disconnect() { if ( session != null && session.isConnected() ) { session.close(); session.getCloseFuture().join(); } }
/** * {@inheritDoc} */ @Override public void remove(IoSession session) { if (!session.getCloseFuture().isClosed()) { session.getFilterChain().fireSessionClosed(); } }
public void close() { if (this.ioSession != null) { if (this.ioSession.isConnected()) { ioSession.getCloseFuture().awaitUninterruptibly(); } this.ioSession.closeNow(); this.ioSession = null; } if (this.connectFuture != null) { this.connectFuture.cancel(); this.connectFuture = null; } }
session.getCloseFuture().awaitUninterruptibly();
IoSession take(HttpResourceAddress serverAddress) { IoSession transportSession = removeThreadAligned(serverAddress); if (transportSession != null) { // Got a cached persistent connection // Remove session idle tracking for this session transportSession.getConfig().setBothIdleTime(0); IoFilterChain filterChain = transportSession.getFilterChain(); if (filterChain.contains(IDLE_FILTER)) { filterChain.remove(IDLE_FILTER); } // Remove our CloseFuture listener as it is out of pool CloseFuture closeFuture = transportSession.getCloseFuture(); closeFuture.removeListener(closeListener); SERVER_ADDRESS.remove(transportSession); } return transportSession; }
boolean recycle(DefaultHttpSession httpSession) { if (!add(httpSession)) { return false; } HttpResourceAddress serverAddress = (HttpResourceAddress)httpSession.getRemoteAddress(); IoSession transportSession = httpSession.getParent(); SERVER_ADDRESS.set(transportSession, serverAddress); // Connection needs to be removed from pool upon session's close. Adding // a close future listener for that CloseFuture closeFuture = transportSession.getCloseFuture(); closeFuture.addListener(closeListener); // Track transport session idle so that we don't waste resources. // Upstream server can take new fresh connections if gateway closes idle connections transportSession.getFilterChain().addLast(IDLE_FILTER, idleFilter); int keepAliveTimeout = serverAddress.getOption(HttpResourceAddress.KEEP_ALIVE_TIMEOUT); transportSession.getConfig().setBothIdleTime(keepAliveTimeout); return true; }
@Override protected ServerSession createSession(final IoSession io) throws Exception { if (io.getConfig() instanceof SocketSessionConfig) { final SocketSessionConfig c = (SocketSessionConfig) io.getConfig(); c.setKeepAlive(keepAlive); } final ServerSession s = (ServerSession) super.createSession(io); final int id = idGenerator.next(); final SocketAddress peer = io.getRemoteAddress(); final SshSession sd = new SshSession(id, peer); s.setAttribute(SshSession.KEY, sd); // Log a session close without authentication as a failure. // io.getCloseFuture().addListener(new IoFutureListener<IoFuture>() { @Override public void operationComplete(IoFuture future) { if (sd.isAuthenticationError()) { sshLog.onAuthFail(sd); } } }); return s; } });
@Override protected ServerSession createSession(final IoSession io) throws Exception { if (io.getConfig() instanceof SocketSessionConfig) { final SocketSessionConfig c = (SocketSessionConfig) io.getConfig(); c.setKeepAlive(keepAlive); } final ServerSession s = (ServerSession) super.createSession(io); final int id = idGenerator.next(); final SocketAddress peer = io.getRemoteAddress(); final SshSession sd = new SshSession(id, peer); s.setAttribute(SshSession.KEY, sd); // Log a session close without authentication as a failure. // io.getCloseFuture().addListener(new IoFutureListener<IoFuture>() { @Override public void operationComplete(IoFuture future) { if (sd.isAuthenticationError()) { sshLog.onAuthFail(sd); } } }); return s; } });
session.getCloseFuture().awaitUninterruptibly();
} else { acceptSession.getCloseFuture().addListener(new IoFutureListener<CloseFuture>() { @Override public void operationComplete(CloseFuture ioFuture) {