public void beforeRemove(ChannelHandlerContext ctx) throws Exception { destroy(ctx); }
public void beforeRemove(ChannelHandlerContext ctx) throws Exception { destroy(ctx); }
@Override public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) { if (e.getState() == IdleState.WRITER_IDLE && enabledTimeout) { e.getChannel().close(); } } }
public HttpPipelineFactory(Configuration conf, Timer timer) throws Exception { SHUFFLE = getShuffle(conf); // TODO Setup SSL Shuffle // if (conf.getBoolean(MRConfig.SHUFFLE_SSL_ENABLED_KEY, // MRConfig.SHUFFLE_SSL_ENABLED_DEFAULT)) { // LOG.info("Encrypted shuffle is enabled."); // sslFactory = new SSLFactory(SSLFactory.Mode.SERVER, conf); // sslFactory.init(); // } this.idleStateHandler = new IdleStateHandler(timer, 0, connectionKeepAliveTimeOut, 0); }
@Override public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception { if (e instanceof IdleStateEvent) { channelIdle(ctx, (IdleStateEvent) e); } else { super.handleUpstream(ctx, e); } }
@Override public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception { long timeoutMillis = getTimeoutMillis(e); if (timeoutMillis > 0) { // Set timeout only when getTimeoutMillis() returns a positive value. ChannelFuture future = e.getFuture(); final Timeout timeout = timer.newTimeout( new WriteTimeoutTask(ctx, future), timeoutMillis, TimeUnit.MILLISECONDS); future.addListener(new TimeoutCanceller(timeout)); } super.writeRequested(ctx, e); }
private void initialize(ChannelHandlerContext ctx) { State state = state(ctx); // Avoid the case where destroy() is called before scheduling timeouts. // See: https://github.com/netty/netty/issues/143 synchronized (state) { switch (state.state) { case 1: case 2: return; } state.state = 1; } if (timeoutMillis > 0) { state.timeout = timer.newTimeout(new ReadTimeoutTask(ctx), timeoutMillis, TimeUnit.MILLISECONDS); } }
@Override public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception { if (e instanceof IdleStateEvent) { channelIdle(ctx, (IdleStateEvent) e); } else { super.handleUpstream(ctx, e); } }
public void run() { try { readTimedOut(ctx); } catch (Throwable t) { fireExceptionCaught(ctx, t); } } });
public void run() { try { channelIdle(ctx, state, lastActivityTimeMillis); } catch (Throwable t) { fireExceptionCaught(ctx, t); } } });
public void run() { try { writeTimedOut(ctx); } catch (Throwable t) { fireExceptionCaught(ctx, t); } } });
@Override public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { // This method will be invoked only if this handler was added // before channelOpen event is fired. If a user adds this handler // after the channelOpen event, initialize() will be called by beforeAdd(). initialize(ctx); ctx.sendUpstream(e); }
@Override public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { // This method will be invoked only if this handler was added // before channelOpen event is fired. If a user adds this handler // after the channelOpen event, initialize() will be called by beforeAdd(). initialize(ctx); ctx.sendUpstream(e); }
private static void destroy(ChannelHandlerContext ctx) { State state = state(ctx); synchronized (state) { if (state.state != 1) { return; } state.state = 2; } if (state.timeout != null) { state.timeout.cancel(); state.timeout = null; } }
public ChannelFuture getFuture() { return succeededFuture(getChannel()); }
private static State state(ChannelHandlerContext ctx) { State state; synchronized (ctx) { // FIXME: It could have been better if there is setAttachmentIfAbsent(). state = (State) ctx.getAttachment(); if (state != null) { return state; } state = new State(); ctx.setAttachment(state); } return state; }
protected void channelIdle( ChannelHandlerContext ctx, IdleState state, long lastActivityTimeMillis) throws Exception { ctx.sendUpstream(new DefaultIdleStateEvent(ctx.getChannel(), state, lastActivityTimeMillis)); }
private static State state(ChannelHandlerContext ctx) { State state; synchronized (ctx) { // FIXME: It could have been better if there is setAttachmentIfAbsent(). state = (State) ctx.getAttachment(); if (state != null) { return state; } state = new State(); ctx.setAttachment(state); } return state; }
@Override public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { destroy(ctx); ctx.sendUpstream(e); }
@Override public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { destroy(ctx); ctx.sendUpstream(e); }