Search in sources :

Example 11 with CompositeCloseable

use of io.servicetalk.concurrent.api.CompositeCloseable in project servicetalk by apple.

the class GracefulConnectionClosureHandlingTest method tearDown.

@AfterEach
void tearDown() throws Exception {
    try {
        CompositeCloseable compositeCloseable = newCompositeCloseable();
        if (connection != null) {
            compositeCloseable.append(connection);
        }
        if (client != null) {
            compositeCloseable.append(client);
        }
        if (serverContext != null) {
            compositeCloseable.append(serverContext);
        }
        compositeCloseable.close();
    } finally {
        if (proxyTunnel != null) {
            safeClose(proxyTunnel);
        }
    }
}
Also used : CompositeCloseable(io.servicetalk.concurrent.api.CompositeCloseable) AsyncCloseables.newCompositeCloseable(io.servicetalk.concurrent.api.AsyncCloseables.newCompositeCloseable) AfterEach(org.junit.jupiter.api.AfterEach)

Example 12 with CompositeCloseable

use of io.servicetalk.concurrent.api.CompositeCloseable in project servicetalk by apple.

the class BasicAuthStrategyInfluencerTest method tearDown.

@AfterEach
void tearDown() throws Exception {
    CompositeCloseable closeable = newCompositeCloseable();
    if (client != null) {
        client.close();
    }
    if (serverContext != null) {
        closeable.append(serverContext);
    }
    if (ioExecutor != null) {
        closeable.append(ioExecutor);
    }
    closeable.close();
}
Also used : CompositeCloseable(io.servicetalk.concurrent.api.CompositeCloseable) AsyncCloseables.newCompositeCloseable(io.servicetalk.concurrent.api.AsyncCloseables.newCompositeCloseable) AfterEach(org.junit.jupiter.api.AfterEach)

Example 13 with CompositeCloseable

use of io.servicetalk.concurrent.api.CompositeCloseable in project servicetalk by apple.

the class ConnectionFactoryFilterTest method tearDown.

@AfterEach
void tearDown() throws Exception {
    CompositeCloseable closeable = AsyncCloseables.newCompositeCloseable();
    if (client != null) {
        closeable.append(client.asClient());
    }
    closeable.append(serverContext);
    closeable.close();
}
Also used : CompositeCloseable(io.servicetalk.concurrent.api.CompositeCloseable) AfterEach(org.junit.jupiter.api.AfterEach)

Example 14 with CompositeCloseable

use of io.servicetalk.concurrent.api.CompositeCloseable in project servicetalk by apple.

the class KeepAliveTest method tearDown.

@AfterEach
void tearDown() throws Exception {
    CompositeCloseable closeable = newCompositeCloseable().appendAll(client, ctx);
    closeable.close();
}
Also used : CompositeCloseable(io.servicetalk.concurrent.api.CompositeCloseable) AsyncCloseables.newCompositeCloseable(io.servicetalk.concurrent.api.AsyncCloseables.newCompositeCloseable) AfterEach(org.junit.jupiter.api.AfterEach)

Example 15 with CompositeCloseable

use of io.servicetalk.concurrent.api.CompositeCloseable in project servicetalk by apple.

the class ChannelSet method closeAsyncGracefully.

@Override
public Completable closeAsyncGracefully() {
    return new SubscribableCompletable() {

        @Override
        protected void handleSubscribe(final Subscriber subscriber) {
            if (!stateUpdater.compareAndSet(ChannelSet.this, OPEN, GRACEFULLY_CLOSING)) {
                toSource(onClose).subscribe(subscriber);
                return;
            }
            if (channelMap.isEmpty()) {
                toSource(onClose).subscribe(subscriber);
                onCloseProcessor.onComplete();
                return;
            }
            CompositeCloseable closeable = newCompositeCloseable();
            for (final Channel channel : channelMap.values()) {
                Attribute<PrivilegedListenableAsyncCloseable> closeableAttribute = channel.attr(CHANNEL_CLOSEABLE_KEY);
                PrivilegedListenableAsyncCloseable channelCloseable = closeableAttribute.getAndSet(null);
                if (null != channelCloseable) {
                    // Upon shutdown of the set, we will close all live channels. If close of individual channels
                    // are offloaded, then this would trigger a surge in threads required to offload these closures.
                    // Here we assume that if there is any offloading required, it is done by offloading the
                    // Completable returned by closeAsyncGracefully() hence offloading each channel is not required.
                    // Hence, we use the "noOffload" variant for each channel for this particular subscribe to use
                    // immediate and effectively disable offloading on each channel.
                    closeable.merge(new AsyncCloseable() {

                        @Override
                        public Completable closeAsync() {
                            return channelCloseable.closeAsyncNoOffload();
                        }

                        @Override
                        public Completable closeAsyncGracefully() {
                            return channelCloseable.closeAsyncGracefullyNoOffload();
                        }
                    });
                } else {
                    channel.close();
                }
            }
            closeable.append(() -> onClose);
            toSource(closeable.closeAsyncGracefully()).subscribe(subscriber);
        }
    };
}
Also used : AsyncCloseable(io.servicetalk.concurrent.api.AsyncCloseable) ListenableAsyncCloseable(io.servicetalk.concurrent.api.ListenableAsyncCloseable) SubscribableCompletable(io.servicetalk.concurrent.api.internal.SubscribableCompletable) Completable(io.servicetalk.concurrent.api.Completable) Channel(io.netty.channel.Channel) CompositeCloseable(io.servicetalk.concurrent.api.CompositeCloseable) AsyncCloseables.newCompositeCloseable(io.servicetalk.concurrent.api.AsyncCloseables.newCompositeCloseable) SubscribableCompletable(io.servicetalk.concurrent.api.internal.SubscribableCompletable)

Aggregations

CompositeCloseable (io.servicetalk.concurrent.api.CompositeCloseable)23 AsyncCloseables.newCompositeCloseable (io.servicetalk.concurrent.api.AsyncCloseables.newCompositeCloseable)16 AfterEach (org.junit.jupiter.api.AfterEach)10 ServerContext (io.servicetalk.transport.api.ServerContext)7 AsyncCloseables (io.servicetalk.concurrent.api.AsyncCloseables)3 Completable (io.servicetalk.concurrent.api.Completable)3 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)3 HttpExecutionStrategies.defaultStrategy (io.servicetalk.http.api.HttpExecutionStrategies.defaultStrategy)3 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)3 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)3 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)3 StreamingHttpService (io.servicetalk.http.api.StreamingHttpService)3 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)3 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)3 ExecutionContextExtension (io.servicetalk.transport.netty.internal.ExecutionContextExtension)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Test (org.junit.jupiter.api.Test)3 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)3 Channel (io.netty.channel.Channel)2 Buffer (io.servicetalk.buffer.api.Buffer)2