use of reactor.netty.ConnectionObserver in project reactor-netty by reactor.
the class ServerTransport method childObserve.
/**
* Set or add the given {@link ConnectionObserver} for each remote connection
*
* @param observer the {@link ConnectionObserver} addition
* @return a new {@link ServerTransport} reference
*/
public T childObserve(ConnectionObserver observer) {
Objects.requireNonNull(observer, "observer");
T dup = duplicate();
ConnectionObserver current = configuration().childObserver;
dup.configuration().childObserver = current == null ? observer : current.then(observer);
return dup;
}
use of reactor.netty.ConnectionObserver in project reactor-netty by reactor.
the class Transport method observe.
/**
* Set or add the given {@link ConnectionObserver} to observe the connection state changes.
*
* @param observer the {@link ConnectionObserver} to be set or add
* @return a new {@link Transport} reference
*/
public T observe(ConnectionObserver observer) {
Objects.requireNonNull(observer, "observer");
T dup = duplicate();
ConnectionObserver current = configuration().observer;
dup.configuration().observer = current == null ? observer : current.then(observer);
return dup;
}
use of reactor.netty.ConnectionObserver in project reactor-netty by reactor.
the class TcpResourcesTest method before.
@BeforeEach
void before() {
loopDisposed = new AtomicBoolean();
poolDisposed = new AtomicBoolean();
LoopResources loopResources = new LoopResources() {
@Override
public EventLoopGroup onServer(boolean useNative) {
throw new UnsupportedOperationException();
}
@Override
public Mono<Void> disposeLater(Duration quietPeriod, Duration timeout) {
return Mono.<Void>empty().doOnSuccess(c -> loopDisposed.set(true));
}
@Override
public boolean isDisposed() {
return loopDisposed.get();
}
};
ConnectionProvider poolResources = new ConnectionProvider() {
@Override
public Mono<? extends Connection> acquire(TransportConfig config, ConnectionObserver observer, Supplier<? extends SocketAddress> remoteAddress, AddressResolverGroup<?> resolverGroup) {
return Mono.never();
}
@Override
public Mono<Void> disposeLater() {
return Mono.<Void>empty().doOnSuccess(c -> poolDisposed.set(true));
}
@Override
public boolean isDisposed() {
return poolDisposed.get();
}
};
tcpResources = new TcpResources(loopResources, poolResources);
}
use of reactor.netty.ConnectionObserver in project reactor-netty by reactor.
the class TracingChannelInboundHandler method channelActive.
@Override
@SuppressWarnings("try")
public void channelActive(ChannelHandlerContext ctx) {
Connection conn = Connection.from(ctx.channel());
if (conn instanceof ConnectionObserver) {
TraceContext parent = ((ConnectionObserver) conn).currentContext().getOrDefault(TraceContext.class, null);
if (parent != null) {
try (Scope scope = currentTraceContext.maybeScope(parent)) {
ctx.fireChannelActive();
}
return;
}
}
ctx.fireChannelActive();
}
use of reactor.netty.ConnectionObserver in project reactor-netty by reactor.
the class FluxReceiveTest method testIssue1016.
@Test
void testIssue1016() throws Exception {
EmbeddedChannel channel = new EmbeddedChannel();
Connection connection = Connection.from(channel);
ConnectionObserver observer = (conn, newState) -> {
if (newState == ConnectionObserver.State.DISCONNECTING) {
if (conn.channel().isActive() && !conn.isPersistent()) {
conn.dispose();
}
}
};
ChannelOperations<?, ?> ops = new ChannelOperations<>(connection, observer);
ops.bind();
ByteBuf buffer = channel.alloc().buffer();
buffer.writeCharSequence("testIssue1016", Charset.defaultCharset());
ops.inbound.onInboundNext(buffer);
CountDownLatch latch = new CountDownLatch(1);
// There is a subscriber, but there is no request for an item
ops.receive().subscribe(new TestSubscriber(latch));
ops.onInboundError(new OutOfMemoryError());
assertThat(latch.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
assertThat(buffer.refCnt()).isEqualTo(0);
}
Aggregations