Java Code Examples for reactor.netty.Connection#as()
The following examples show how to use
reactor.netty.Connection#as() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChannelOperationsHandler.java From reactor-netty with Apache License 2.0 | 6 votes |
@Override final public void channelInactive(ChannelHandlerContext ctx) { try { Connection connection = Connection.from(ctx.channel()); ChannelOperations<?, ?> ops = connection.as(ChannelOperations.class); if (ops != null) { ops.onInboundClose(); } else { listener.onStateChange(connection, ConnectionObserver.State.DISCONNECTING); } } catch (Throwable err) { exceptionCaught(ctx, err); } }
Example 2
Source File: HttpClientConnect.java From reactor-netty with Apache License 2.0 | 6 votes |
@Override public void onUncaughtException(Connection connection, Throwable error) { if (error instanceof RedirectClientException) { if (log.isDebugEnabled()) { log.debug(format(connection.channel(), "The request will be redirected")); } } else if (AbortedException.isConnectionReset(error) && handler.shouldRetry) { HttpClientOperations ops = connection.as(HttpClientOperations.class); if (ops != null) { ops.retrying = true; } if (log.isDebugEnabled()) { log.debug(format(connection.channel(), "The connection observed an error, the request will be retried"), error); } } else if (log.isWarnEnabled()) { log.warn(format(connection.channel(), "The connection observed an error"), error); } sink.error(error); }
Example 3
Source File: HttpClientConfig.java From reactor-netty with Apache License 2.0 | 6 votes |
@Override public void onUncaughtException(Connection connection, Throwable error) { if (doOnRedirect != null && error instanceof RedirectClientException) { doOnRedirect.accept(connection.as(HttpClientOperations.class), connection); return; } HttpClientOperations ops = connection.as(HttpClientOperations.class); if (ops == null) { return; } if (doOnRequestError != null && ops.retrying && ops.responseState == null) { doOnRequestError.accept(connection.as(HttpClientOperations.class), error); return; } if (doOnResponseError != null && (ops.responseState != null) && !(error instanceof RedirectClientException)) { doOnResponseError.accept(connection.as(HttpClientOperations.class), error); } }
Example 4
Source File: ChannelOperationsHandler.java From reactor-netty with Apache License 2.0 | 5 votes |
@Override final public void exceptionCaught(ChannelHandlerContext ctx, Throwable err) { Connection connection = Connection.from(ctx.channel()); ChannelOperations<?, ?> ops = connection.as(ChannelOperations.class); if (ops != null) { ops.onInboundError(err); } else { listener.onUncaughtException(connection, err); } }
Example 5
Source File: HttpClientConfig.java From reactor-netty with Apache License 2.0 | 5 votes |
@Override public void onStateChange(Connection connection, State newState) { if (doOnRequest != null && newState == HttpClientState.REQUEST_PREPARED) { doOnRequest.accept(connection.as(HttpClientOperations.class), connection); return; } if (doAfterResponseSuccess != null && newState == HttpClientState.RESPONSE_COMPLETED) { doAfterResponseSuccess.accept(connection.as(HttpClientOperations.class), connection); return; } if (doAfterRequest != null && newState == HttpClientState.REQUEST_SENT) { doAfterRequest.accept(connection.as(HttpClientOperations.class), connection); return; } if (doOnResponse != null && newState == HttpClientState.RESPONSE_RECEIVED) { doOnResponse.accept(connection.as(HttpClientOperations.class), connection); return; } if (doOnResponseError != null && newState == HttpClientState.RESPONSE_INCOMPLETE) { HttpClientOperations ops = connection.as(HttpClientOperations.class); if (ops == null) { return; } if (ops.responseState != null) { doOnResponseError.accept(ops, new PrematureCloseException("Connection prematurely closed DURING response")); } } }
Example 6
Source File: HttpTrafficHandler.java From reactor-netty with Apache License 2.0 | 5 votes |
void sendNewState(Connection connection, ConnectionObserver.State state) { ChannelOperations<?, ?> ops = connection.as(ChannelOperations.class); if (ops != null) { listener.onStateChange(ops, state); } else { listener.onStateChange(connection, state); } }