|
13 | 13 | * See the License for the specific language governing permissions and
|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
| 16 | + |
16 | 17 | package io.reactivex.netty.client;
|
17 | 18 |
|
18 | 19 | import io.netty.bootstrap.Bootstrap;
|
@@ -74,34 +75,38 @@ public void call() {
|
74 | 75 | connectFuture.addListener(new ChannelFutureListener() {
|
75 | 76 | @Override
|
76 | 77 | public void operationComplete(ChannelFuture future) throws Exception {
|
77 |
| - if (!future.isSuccess()) { |
78 |
| - eventsSubject.onEvent(ClientMetricsEvent.CONNECT_FAILED, Clock.onEndMillis(startTimeMillis), |
79 |
| - future.cause()); |
80 |
| - subscriber.onError(future.cause()); |
81 |
| - } else { |
82 |
| - eventsSubject.onEvent(ClientMetricsEvent.CONNECT_SUCCESS, Clock.onEndMillis(startTimeMillis)); |
83 |
| - ChannelPipeline pipeline = future.channel().pipeline(); |
84 |
| - ChannelHandlerContext ctx = pipeline.lastContext(); // The connection uses the context for write which should always start from the tail. |
85 |
| - final ObservableConnection<I, O> newConnection = connectionFactory.newConnection(ctx); |
86 |
| - ChannelHandler lifecycleHandler = pipeline.get(RxRequiredConfigurator.CONN_LIFECYCLE_HANDLER_NAME); |
87 |
| - if (null == lifecycleHandler) { |
88 |
| - onNewConnection(newConnection, subscriber); |
| 78 | + try { |
| 79 | + if (!future.isSuccess()) { |
| 80 | + eventsSubject.onEvent(ClientMetricsEvent.CONNECT_FAILED, Clock.onEndMillis(startTimeMillis), |
| 81 | + future.cause()); |
| 82 | + subscriber.onError(future.cause()); |
89 | 83 | } else {
|
90 |
| - @SuppressWarnings("unchecked") |
91 |
| - ConnectionLifecycleHandler<I, O> handler = (ConnectionLifecycleHandler<I, O>) lifecycleHandler; |
92 |
| - SslHandler sslHandler = pipeline.get(SslHandler.class); |
93 |
| - if (null == sslHandler) { |
94 |
| - handler.setConnection(newConnection); |
| 84 | + eventsSubject.onEvent(ClientMetricsEvent.CONNECT_SUCCESS, Clock.onEndMillis(startTimeMillis)); |
| 85 | + ChannelPipeline pipeline = future.channel().pipeline(); |
| 86 | + ChannelHandlerContext ctx = pipeline.lastContext(); // The connection uses the context for write which should always start from the tail. |
| 87 | + final ObservableConnection<I, O> newConnection = connectionFactory.newConnection(ctx); |
| 88 | + ChannelHandler lifecycleHandler = pipeline.get(RxRequiredConfigurator.CONN_LIFECYCLE_HANDLER_NAME); |
| 89 | + if (null == lifecycleHandler) { |
95 | 90 | onNewConnection(newConnection, subscriber);
|
96 | 91 | } else {
|
97 |
| - sslHandler.handshakeFuture().addListener(new GenericFutureListener<Future<? super Channel>>() { |
98 |
| - @Override |
99 |
| - public void operationComplete(Future<? super Channel> future) throws Exception { |
100 |
| - onNewConnection(newConnection, subscriber); |
101 |
| - } |
102 |
| - }); |
| 92 | + @SuppressWarnings("unchecked") |
| 93 | + ConnectionLifecycleHandler<I, O> handler = (ConnectionLifecycleHandler<I, O>) lifecycleHandler; |
| 94 | + SslHandler sslHandler = pipeline.get(SslHandler.class); |
| 95 | + if (null == sslHandler) { |
| 96 | + handler.setConnection(newConnection); |
| 97 | + onNewConnection(newConnection, subscriber); |
| 98 | + } else { |
| 99 | + sslHandler.handshakeFuture().addListener(new GenericFutureListener<Future<? super Channel>>() { |
| 100 | + @Override |
| 101 | + public void operationComplete(Future<? super Channel> future) throws Exception { |
| 102 | + onNewConnection(newConnection, subscriber); |
| 103 | + } |
| 104 | + }); |
| 105 | + } |
103 | 106 | }
|
104 | 107 | }
|
| 108 | + } catch (Throwable throwable) { |
| 109 | + subscriber.onError(throwable); |
105 | 110 | }
|
106 | 111 | }
|
107 | 112 | });
|
|
0 commit comments