Search in sources :

Example 11 with ConnectionObserver

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;
}
Also used : ConnectionObserver(reactor.netty.ConnectionObserver)

Example 12 with ConnectionObserver

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;
}
Also used : ConnectionObserver(reactor.netty.ConnectionObserver)

Example 13 with ConnectionObserver

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);
}
Also used : ConnectionObserver(reactor.netty.ConnectionObserver) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LoopResources(reactor.netty.resources.LoopResources) AddressResolverGroup(io.netty.resolver.AddressResolverGroup) Duration(java.time.Duration) Supplier(java.util.function.Supplier) SocketAddress(java.net.SocketAddress) ConnectionProvider(reactor.netty.resources.ConnectionProvider) TransportConfig(reactor.netty.transport.TransportConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 14 with ConnectionObserver

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();
}
Also used : ConnectionObserver(reactor.netty.ConnectionObserver) Scope(brave.propagation.CurrentTraceContext.Scope) Connection(reactor.netty.Connection) CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext)

Example 15 with ConnectionObserver

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);
}
Also used : ConnectionObserver(reactor.netty.ConnectionObserver) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BaseHttpTest(reactor.netty.BaseHttpTest) Random(java.util.Random) Mono(reactor.core.publisher.Mono) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) Flux(reactor.core.publisher.Flux) ConnectionObserver(reactor.netty.ConnectionObserver) CoreSubscriber(reactor.core.CoreSubscriber) Charset(java.nio.charset.Charset) ByteBuf(io.netty.buffer.ByteBuf) Duration(java.time.Duration) Subscription(org.reactivestreams.Subscription) Connection(reactor.netty.Connection) DisposableServer(reactor.netty.DisposableServer) Connection(reactor.netty.Connection) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) CountDownLatch(java.util.concurrent.CountDownLatch) BaseHttpTest(reactor.netty.BaseHttpTest) Test(org.junit.jupiter.api.Test)

Aggregations

ConnectionObserver (reactor.netty.ConnectionObserver)16 Connection (reactor.netty.Connection)9 InetSocketAddress (java.net.InetSocketAddress)7 SocketAddress (java.net.SocketAddress)7 Duration (java.time.Duration)6 Mono (reactor.core.publisher.Mono)5 EventLoopGroup (io.netty.channel.EventLoopGroup)4 AddressResolverGroup (io.netty.resolver.AddressResolverGroup)4 Supplier (java.util.function.Supplier)4 ConnectionProvider (reactor.netty.resources.ConnectionProvider)4 LoopResources (reactor.netty.resources.LoopResources)4 Channel (io.netty.channel.Channel)3 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)3 List (java.util.List)3 Objects (java.util.Objects)3 TimeUnit (java.util.concurrent.TimeUnit)3 Test (org.junit.jupiter.api.Test)3 CoreSubscriber (reactor.core.CoreSubscriber)3 PooledConnection (reactor.netty.resources.DefaultPooledConnectionProvider.PooledConnection)3 TransportConfig (reactor.netty.transport.TransportConfig)3