public ChannelIoSession(ChannelIoService service, IoProcessorEx<ChannelIoSession<? extends ChannelConfig>> processor, Channel channel, ChannelIoSessionConfig<C> config, Thread ioThread, Executor ioExecutor) { super(0, ioThread, ioExecutor, service.getThreadLocalWriteRequest(0)); this.service = service; this.channel = channel; this.config = config; this.config.setAll(service.getSessionConfig()); this.handler = service.getHandler(); this.processor = processor; this.transportMetadata = service.getTransportMetadata(); }
@Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { Channel channel = e.getChannel(); if (OPTIMIZE_PERFORMANCE_CLIENT) { channel.getConfig().setBufferFactory(CHANNEL_BUFFER_FACTORY); } ChannelIoSession<?> session = service.createSession(channel); String baseName = ctx.getName(); String name = format("%s#session", baseName); ChannelHandler handler = new IoSessionChannelHandler(session, future, initializer, service.getSessionIdleTracker()); ChannelPipeline pipeline = ctx.getPipeline(); pipeline.addAfter(baseName, name, handler); ctx.sendUpstream(e); pipeline.remove(this); }
private void addNow(ChannelIoSession<? extends ChannelConfig> session) { try { init(session); // Build the filter chain of this session. IoFilterChainBuilder chainBuilder = session.getService().getFilterChainBuilder(); chainBuilder.buildFilterChain(session.getFilterChain()); // DefaultIoFilterChain.CONNECT_FUTURE is cleared inside here // in AbstractIoFilterChain.fireSessionOpened(). // Propagate the SESSION_CREATED event up to the chain IoServiceListenerSupport listeners = session.getService().getListeners(); listeners.fireSessionCreated(session); } catch (Throwable e) { ExceptionMonitor.getInstance().exceptionCaught(e, session); try { destroy(session); } catch (Exception e1) { ExceptionMonitor.getInstance().exceptionCaught(e1, session); } } }
@Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { session.getService().initializeSession(session, future, initializer); idleTracker.addSession(session); session.getProcessor().add(session); }
private boolean removeNow(ChannelIoSession<? extends ChannelConfig> session) { clearWriteRequestQueue(session); try { destroy(session); return true; } catch (Exception e) { IoFilterChain filterChain = session.getFilterChain(); filterChain.fireExceptionCaught(e); } finally { clearWriteRequestQueue(session); session.getService().getListeners() .fireSessionDestroyed(session); } return false; }