use of reactor.netty.Connection in project reactor-netty by reactor.
the class ContextAwareChannelMetricsHandler method recordException.
@Override
protected void recordException(ChannelHandlerContext ctx, SocketAddress address) {
Connection connection = Connection.from(ctx.channel());
ChannelOperations<?, ?> ops = connection.as(ChannelOperations.class);
if (ops != null) {
recorder().incrementErrorsCount(ops.currentContext(), address);
} else if (connection instanceof ConnectionObserver) {
recorder().incrementErrorsCount(((ConnectionObserver) connection).currentContext(), address);
} else {
super.recordException(ctx, address);
}
}
use of reactor.netty.Connection in project reactor-netty by reactor.
the class ChannelOperationsHandler method channelInactive.
@Override
public final 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);
}
}
use of reactor.netty.Connection in project reactor-netty by reactor.
the class ClientTransport method connect.
/**
* Connect the {@link ClientTransport} and return a {@link Mono} of {@link Connection}. If
* {@link Mono} is cancelled, the underlying connection will be aborted. Once the
* {@link Connection} has been emitted and is not necessary anymore, disposing must be
* done by the user via {@link Connection#dispose()}.
*
* @return a {@link Mono} of {@link Connection}
*/
protected Mono<? extends Connection> connect() {
CONF config = configuration();
ConnectionObserver observer = config.defaultConnectionObserver().then(config.observer);
AddressResolverGroup<?> resolver = config.resolverInternal();
Mono<? extends Connection> mono = config.connectionProvider().acquire(config, observer, config.remoteAddress, resolver);
if (config.doOnConnect != null) {
mono = mono.doOnSubscribe(s -> config.doOnConnect.accept(config));
}
return mono;
}
use of reactor.netty.Connection in project reactor-netty by reactor.
the class Http2Pool method destroyPoolable.
Mono<Void> destroyPoolable(Http2PooledRef ref) {
Mono<Void> mono = Mono.empty();
try {
if (ref.slot.decrementConcurrencyAndGet() == 0) {
ref.slot.invalidate();
Connection connection = ref.poolable();
Http2FrameCodec frameCodec = connection.channel().pipeline().get(Http2FrameCodec.class);
if (frameCodec != null) {
releaseConnection(connection);
}
}
} catch (Throwable destroyFunctionError) {
mono = Mono.error(destroyFunctionError);
}
return mono;
}
use of reactor.netty.Connection in project reactor-netty by reactor.
the class HttpServerTests method httpPipelining.
@Test
void httpPipelining() throws Exception {
AtomicInteger i = new AtomicInteger();
disposableServer = createServer().handle((req, resp) -> resp.header(HttpHeaderNames.CONTENT_LENGTH, "1").sendString(Mono.just(i.incrementAndGet()).flatMap(d -> Mono.delay(Duration.ofSeconds(4 - d)).map(x -> d + "\n")))).bindNow();
DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/plaintext");
CountDownLatch latch = new CountDownLatch(6);
Connection client = TcpClient.create().port(disposableServer.port()).handle((in, out) -> {
in.withConnection(x -> x.addHandlerFirst(new HttpClientCodec())).receiveObject().ofType(DefaultHttpContent.class).as(ByteBufFlux::fromInbound).asString().log().map(Integer::parseInt).subscribe(d -> {
for (int x = 0; x < d; x++) {
latch.countDown();
}
});
return out.sendObject(Flux.just(request.retain(), request.retain(), request.retain())).neverComplete();
}).wiretap(true).connectNow();
assertThat(latch.await(45, TimeUnit.SECONDS)).as("latch await").isTrue();
client.disposeNow();
}
Aggregations