public void close() { if (httpKeepAliveRunnable != null) { httpKeepAliveRunnable.close(); } }
public HttpAcceptorHandler(final HttpKeepAliveRunnable httpKeepAliveTask, final long responseTime, Channel channel) { super(); this.responseTime = responseTime; this.httpKeepAliveTask = httpKeepAliveTask; this.channel = channel; httpKeepAliveTask.registerKeepAliveHandler(this); }
@Override public void channelDisconnected(final ChannelHandlerContext ctx, final ChannelStateEvent e) throws Exception { super.channelDisconnected(ctx, e); httpKeepAliveTask.unregisterKeepAliveHandler(this); channel = null; }
private void switchToHttp(ChannelHandlerContext ctx) { ChannelPipeline p = ctx.pipeline(); p.addLast("http-decoder", new HttpRequestDecoder()); p.addLast("http-aggregator", new HttpObjectAggregator(Integer.MAX_VALUE)); p.addLast("http-encoder", new HttpResponseEncoder()); //create it lazily if and when we need it if (httpKeepAliveRunnable == null) { long httpServerScanPeriod = ConfigurationHelper.getLongProperty(TransportConstants.HTTP_SERVER_SCAN_PERIOD_PROP_NAME, TransportConstants.DEFAULT_HTTP_SERVER_SCAN_PERIOD, configuration); httpKeepAliveRunnable = new HttpKeepAliveRunnable(); Future<?> future = scheduledThreadPool.scheduleAtFixedRate(httpKeepAliveRunnable, httpServerScanPeriod, httpServerScanPeriod, TimeUnit.MILLISECONDS); httpKeepAliveRunnable.setFuture(future); } long httpResponseTime = ConfigurationHelper.getLongProperty(TransportConstants.HTTP_RESPONSE_TIME_PROP_NAME, TransportConstants.DEFAULT_HTTP_RESPONSE_TIME, configuration); HttpAcceptorHandler httpHandler = new HttpAcceptorHandler(httpKeepAliveRunnable, httpResponseTime, ctx.channel()); ctx.pipeline().addLast("http-handler", httpHandler); p.addLast(new ProtocolDecoder(false, true)); p.remove(this); } }
TransportConstants.DEFAULT_HTTP_RESPONSE_TIME, configuration); httpKeepAliveRunnable = new HttpKeepAliveRunnable(); Future<?> future = scheduledThreadPool.scheduleAtFixedRate(httpKeepAliveRunnable, httpServerScanPeriod, httpServerScanPeriod, TimeUnit.MILLISECONDS); httpKeepAliveRunnable.setFuture(future);
@Override public void channelInactive(final ChannelHandlerContext ctx) throws Exception { super.channelInactive(ctx); httpKeepAliveTask.unregisterKeepAliveHandler(this); channel = null; }
@Override public void channelConnected(final ChannelHandlerContext ctx, final ChannelStateEvent e) throws Exception { super.channelConnected(ctx, e); channel = e.getChannel(); httpKeepAliveTask.registerKeepAliveHandler(this); }
httpKeepAliveRunnable.close();