if (this.connectFuture != null) {
throw new IllegalStateException(String.format("%s already started a connection attempt.", this.name));
}
final Bootstrap bootstrap = new Bootstrap();
bootstrap.group(this.eventLoopGroup);
bootstrap.channel(NioSocketChannel.class);
bootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
// TODO Remove this when Netty 5 is available
bootstrap.option(ChannelOption.AUTO_CLOSE, false);
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(final SocketChannel channel) {
final ChannelPipeline pipeline = channel.pipeline();
final SSLEngine sslEngine = apnsConnection.sslContext.createSSLEngine();
sslEngine.setUseClientMode(true);
pipeline.addLast("ssl", new SslHandler(sslEngine));
pipeline.addLast("decoder", new RejectedNotificationDecoder());
pipeline.addLast("encoder", new ApnsPushNotificationEncoder());
pipeline.addLast(ApnsConnection.PIPELINE_MAIN_HANDLER, new ApnsConnectionHandler(apnsConnection));
}
});
log.debug("{} beginning connection process.", apnsConnection.name);
this.connectFuture = bootstrap.connect(this.environment.getApnsGatewayHost(), this.environment.getApnsGatewayPort());
this.connectFuture.addListener(new GenericFutureListener<ChannelFuture>() {
@Override
public void operationComplete(final ChannelFuture connectFuture) {
if (connectFuture.isSuccess()) {