@@ -287,7 +287,7 @@ public ChannelFuture handshake(Channel channel) { |
287 | 287 | * the {@link ChannelPromise} to be notified when the opening handshake is sent |
288 | 288 | */ |
289 | 289 | public final ChannelFuture handshake(Channel channel, final ChannelPromise promise) { |
290 | | - ChannelPipeline pipeline = channel.pipeline(); |
| 290 | + final ChannelPipeline pipeline = channel.pipeline(); |
291 | 291 | HttpResponseDecoder decoder = pipeline.get(HttpResponseDecoder.class); |
292 | 292 | if (decoder == null) { |
293 | 293 | HttpClientCodec codec = pipeline.get(HttpClientCodec.class); |
@@ -322,26 +322,22 @@ public final ChannelFuture handshake(Channel channel, final ChannelPromise promi |
322 | 322 |
|
323 | 323 | FullHttpRequest request = newHandshakeRequest(); |
324 | 324 |
|
325 | | - channel.writeAndFlush(request).addListener(new ChannelFutureListener() { |
326 | | - @Override |
327 | | - public void operationComplete(ChannelFuture future) { |
328 | | - if (future.isSuccess()) { |
329 | | - ChannelPipeline p = future.channel().pipeline(); |
330 | | - ChannelHandlerContext ctx = p.context(HttpRequestEncoder.class); |
331 | | - if (ctx == null) { |
332 | | - ctx = p.context(HttpClientCodec.class); |
333 | | - } |
334 | | - if (ctx == null) { |
335 | | - promise.setFailure(new IllegalStateException("ChannelPipeline does not contain " + |
336 | | - "an HttpRequestEncoder or HttpClientCodec")); |
337 | | - return; |
338 | | - } |
339 | | - p.addAfter(ctx.name(), "ws-encoder", newWebSocketEncoder()); |
340 | | - |
341 | | - promise.setSuccess(); |
342 | | - } else { |
343 | | - promise.setFailure(future.cause()); |
| 325 | + channel.writeAndFlush(request).addListener(future -> { |
| 326 | + if (future.isSuccess()) { |
| 327 | + ChannelHandlerContext ctx = pipeline.context(HttpRequestEncoder.class); |
| 328 | + if (ctx == null) { |
| 329 | + ctx = pipeline.context(HttpClientCodec.class); |
344 | 330 | } |
| 331 | + if (ctx == null) { |
| 332 | + promise.setFailure(new IllegalStateException("ChannelPipeline does not contain " + |
| 333 | + "an HttpRequestEncoder or HttpClientCodec")); |
| 334 | + return; |
| 335 | + } |
| 336 | + pipeline.addAfter(ctx.name(), "ws-encoder", newWebSocketEncoder()); |
| 337 | + |
| 338 | + promise.setSuccess(); |
| 339 | + } else { |
| 340 | + promise.setFailure(future.cause()); |
345 | 341 | } |
346 | 342 | }); |
347 | 343 | return promise; |
@@ -687,32 +683,24 @@ private ChannelFuture close0(final ChannelOutboundInvoker invoker, final Channel |
687 | 683 | return promise; |
688 | 684 | } |
689 | 685 |
|
690 | | - promise.addListener(new ChannelFutureListener() { |
691 | | - @Override |
692 | | - public void operationComplete(ChannelFuture future) { |
693 | | - // If flush operation failed, there is no reason to expect |
694 | | - // a server to receive CloseFrame. Thus this should be handled |
695 | | - // by the application separately. |
696 | | - // Also, close might be called twice from different threads. |
697 | | - if (future.isSuccess() && channel.isActive() && |
698 | | - FORCE_CLOSE_INIT_UPDATER.compareAndSet(handshaker, 0, 1)) { |
699 | | - final Future<?> forceCloseFuture = channel.executor().schedule(new Runnable() { |
700 | | - @Override |
701 | | - public void run() { |
702 | | - if (channel.isActive()) { |
703 | | - invoker.close(); |
704 | | - forceCloseComplete = true; |
705 | | - } |
| 686 | + promise.addListener(future -> { |
| 687 | + // If flush operation failed, there is no reason to expect |
| 688 | + // a server to receive CloseFrame. Thus this should be handled |
| 689 | + // by the application separately. |
| 690 | + // Also, close might be called twice from different threads. |
| 691 | + if (future.isSuccess() && channel.isActive() && |
| 692 | + FORCE_CLOSE_INIT_UPDATER.compareAndSet(handshaker, 0, 1)) { |
| 693 | + final Future<?> forceCloseFuture = channel.executor().schedule(new Runnable() { |
| 694 | + @Override |
| 695 | + public void run() { |
| 696 | + if (channel.isActive()) { |
| 697 | + invoker.close(); |
| 698 | + forceCloseComplete = true; |
706 | 699 | } |
707 | | - }, forceCloseTimeoutMillis, TimeUnit.MILLISECONDS); |
| 700 | + } |
| 701 | + }, forceCloseTimeoutMillis, TimeUnit.MILLISECONDS); |
708 | 702 |
|
709 | | - channel.closeFuture().addListener(new ChannelFutureListener() { |
710 | | - @Override |
711 | | - public void operationComplete(ChannelFuture future) { |
712 | | - forceCloseFuture.cancel(false); |
713 | | - } |
714 | | - }); |
715 | | - } |
| 703 | + channel.closeFuture().addListener(f -> forceCloseFuture.cancel(false)); |
716 | 704 | } |
717 | 705 | }); |
718 | 706 | return promise; |
|