List of usage examples for io.netty.handler.timeout WriteTimeoutHandler WriteTimeoutHandler
public WriteTimeoutHandler(long timeout, TimeUnit unit)
From source file:com.github.spapageo.jannel.channel.ChannelHandlerProvider.java
License:Open Source License
public ChannelHandler getChangeHandler(HandlerType handlerType, ClientSessionConfiguration sessionConfiguration, SessionCallbackHandler clientSession, Transcoder transcoder) { switch (handlerType) { case MESSAGE_LOGGER: return MESSAGE_LOGGER; case SESSION_WRAPPER: return new SessionWrapperHandler(clientSession); case WRITE_TIMEOUT_HANDLER: return new WriteTimeoutHandler(sessionConfiguration.getWriteTimeout(), TimeUnit.MILLISECONDS); case MESSAGE_DECODER: return new MessageDecoder(transcoder); case MESSAGE_ENCODER: return new MessageEncoder(transcoder); case LENGTH_FRAME_DECODER: return new LengthFieldBasedFrameDecoder(MAXIMUM_MESSAGE_BYTE_SIZE, MESSAGE_FIELD_OFFSET, LENGTH_FIELD_SIZE, 0, LENGTH_FIELD_SIZE); case LENGTH_FRAME_ENCODER: return new LengthFieldPrepender(LENGTH_FIELD_SIZE, false); default://from w ww .j ava2 s . com throw new IllegalArgumentException("Invalid handler type"); } }
From source file:com.relayrides.pushy.apns.ApnsClient.java
License:Open Source License
protected ApnsClient(final SslContext sslContext, final EventLoopGroup eventLoopGroup) { this.bootstrap = new Bootstrap(); if (eventLoopGroup != null) { this.bootstrap.group(eventLoopGroup); this.shouldShutDownEventLoopGroup = false; } else {//from w w w . j a v a 2s . co m this.bootstrap.group(new NioEventLoopGroup(1)); this.shouldShutDownEventLoopGroup = true; } this.bootstrap.channel(SocketChannelClassUtil.getSocketChannelClass(this.bootstrap.config().group())); this.bootstrap.option(ChannelOption.TCP_NODELAY, true); this.bootstrap.handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(final SocketChannel channel) throws Exception { final ChannelPipeline pipeline = channel.pipeline(); final ProxyHandlerFactory proxyHandlerFactory = ApnsClient.this.proxyHandlerFactory; if (proxyHandlerFactory != null) { pipeline.addFirst(proxyHandlerFactory.createProxyHandler()); } if (ApnsClient.this.writeTimeoutMillis > 0) { pipeline.addLast( new WriteTimeoutHandler(ApnsClient.this.writeTimeoutMillis, TimeUnit.MILLISECONDS)); } pipeline.addLast(sslContext.newHandler(channel.alloc())); pipeline.addLast(new ApplicationProtocolNegotiationHandler("") { @Override protected void configurePipeline(final ChannelHandlerContext context, final String protocol) { if (ApplicationProtocolNames.HTTP_2.equals(protocol)) { final ApnsClientHandler apnsClientHandler = new ApnsClientHandler.ApnsClientHandlerBuilder() .server(false).apnsClient(ApnsClient.this) .authority( ((InetSocketAddress) context.channel().remoteAddress()).getHostName()) .encoderEnforceMaxConcurrentStreams(true).build(); synchronized (ApnsClient.this.bootstrap) { if (ApnsClient.this.gracefulShutdownTimeoutMillis != null) { apnsClientHandler.gracefulShutdownTimeoutMillis( ApnsClient.this.gracefulShutdownTimeoutMillis); } } context.pipeline().addLast( new IdleStateHandler(0, 0, PING_IDLE_TIME_MILLIS, TimeUnit.MILLISECONDS)); context.pipeline().addLast(apnsClientHandler); final ChannelPromise connectionReadyPromise = ApnsClient.this.connectionReadyPromise; if (connectionReadyPromise != null) { connectionReadyPromise.trySuccess(); } } else { throw new IllegalArgumentException("Unexpected protocol: " + protocol); } } }); } }); }
From source file:io.werval.server.netty.HttpServerChannelInitializer.java
License:Apache License
@Override public void initChannel(Channel channel) { ChannelPipeline pipeline = channel.pipeline(); // Connection Events String remoteHostString = ((InetSocketAddress) channel.remoteAddress()).getHostString(); app.events().emit(new ConnectionEvent.Opened(remoteHostString)); channel.closeFuture()/*from w w w . jav a2 s. c o m*/ .addListener(future -> app.events().emit(new ConnectionEvent.Closed(remoteHostString))); if (app.config().bool(WERVAL_HTTP_LOG_LOWLEVEL_ENABLED)) { // Log Netty Bytes LogLevel level = LogLevel.valueOf(app.config().string(WERVAL_HTTP_LOG_LOWLEVEL_LEVEL).toUpperCase(US)); pipeline.addLast("byte-logging", new LoggingHandler("io.werval.server.netty.LowLevelLogger", level)); } // Read/Write Timeout long readTimeout = app.config().seconds(WERVAL_HTTP_TIMEOUT_READ); long writeTimeout = app.config().seconds(WERVAL_HTTP_TIMEOUT_WRITE); pipeline.addLast("read-timeout", new ReadTimeoutHandler(readTimeout, SECONDS)); pipeline.addLast("write-timeout", new WriteTimeoutHandler(writeTimeout, SECONDS)); // HTTP Decoding / Encoding // HTTP decoders always generates multiple message objects per a single HTTP message: // // 1 * HttpRequest / HttpResponse // 0 - n * HttpContent // 1 * LastHttpContent // // or a single FullHttpRequest if a handler ask for it pipeline.addLast("http-codec", new HttpServerCodec()); // GZip decompression support pipeline.addLast("http-decompressor", new HttpContentDecompressor()); // Allow to send chunked data pipeline.addLast("chunked-write-handler", new ChunkedWriteHandler()); // Protocol Switching Handler pipeline.addLast("subprotocol-switcher", new SubProtocolSwitchHandler(allChannels, app, devSpi)); }