Search in sources :

Example 21 with ContextMap

use of io.servicetalk.context.api.ContextMap in project servicetalk by apple.

the class ContextPreservingSubscriber method onError.

@Override
public final void onError(Throwable t) {
    final Thread currentThread = Thread.currentThread();
    if (currentThread instanceof ContextMapHolder) {
        final ContextMapHolder asyncContextMapHolder = (ContextMapHolder) currentThread;
        ContextMap prev = asyncContextMapHolder.context();
        try {
            asyncContextMapHolder.context(saved);
            subscriber.onError(t);
        } finally {
            asyncContextMapHolder.context(prev);
        }
    } else {
        onErrorSlowPath(t);
    }
}
Also used : ContextMapHolder(io.servicetalk.context.api.ContextMapHolder) ContextMap(io.servicetalk.context.api.ContextMap)

Example 22 with ContextMap

use of io.servicetalk.context.api.ContextMap in project servicetalk by apple.

the class ContextPreservingSubscriber method onComplete.

@Override
public final void onComplete() {
    final Thread currentThread = Thread.currentThread();
    if (currentThread instanceof ContextMapHolder) {
        final ContextMapHolder asyncContextMapHolder = (ContextMapHolder) currentThread;
        ContextMap prev = asyncContextMapHolder.context();
        try {
            asyncContextMapHolder.context(saved);
            subscriber.onComplete();
        } finally {
            asyncContextMapHolder.context(prev);
        }
    } else {
        onCompleteSlowPath();
    }
}
Also used : ContextMapHolder(io.servicetalk.context.api.ContextMapHolder) ContextMap(io.servicetalk.context.api.ContextMap)

Example 23 with ContextMap

use of io.servicetalk.context.api.ContextMap in project servicetalk by apple.

the class ContextPreservingSubscriber method onSubscribe.

@Override
public final void onSubscribe(Subscription s) {
    final Thread currentThread = Thread.currentThread();
    if (currentThread instanceof ContextMapHolder) {
        final ContextMapHolder asyncContextMapHolder = (ContextMapHolder) currentThread;
        ContextMap prev = asyncContextMapHolder.context();
        try {
            asyncContextMapHolder.context(saved);
            invokeOnSubscribe(s);
        } finally {
            asyncContextMapHolder.context(prev);
        }
    } else {
        onSubscribeSlowPath(s);
    }
}
Also used : ContextMapHolder(io.servicetalk.context.api.ContextMapHolder) ContextMap(io.servicetalk.context.api.ContextMap)

Example 24 with ContextMap

use of io.servicetalk.context.api.ContextMap in project servicetalk by apple.

the class ContextPreservingSubscriber method onCompleteSlowPath.

private void onCompleteSlowPath() {
    ContextMap prev = CONTEXT_THREAD_LOCAL.get();
    try {
        CONTEXT_THREAD_LOCAL.set(saved);
        subscriber.onComplete();
    } finally {
        CONTEXT_THREAD_LOCAL.set(prev);
    }
}
Also used : ContextMap(io.servicetalk.context.api.ContextMap)

Example 25 with ContextMap

use of io.servicetalk.context.api.ContextMap in project servicetalk by apple.

the class ContextPreservingSubscriber method onSubscribeSlowPath.

private void onSubscribeSlowPath(Subscription s) {
    ContextMap prev = CONTEXT_THREAD_LOCAL.get();
    try {
        CONTEXT_THREAD_LOCAL.set(saved);
        invokeOnSubscribe(s);
    } finally {
        CONTEXT_THREAD_LOCAL.set(prev);
    }
}
Also used : ContextMap(io.servicetalk.context.api.ContextMap)

Aggregations

ContextMap (io.servicetalk.context.api.ContextMap)49 ContextMapHolder (io.servicetalk.context.api.ContextMapHolder)20 Single (io.servicetalk.concurrent.api.Single)5 AsyncContext (io.servicetalk.concurrent.api.AsyncContext)4 Completable (io.servicetalk.concurrent.api.Completable)4 Executor (io.servicetalk.concurrent.api.Executor)4 SourceAdapters.toSource (io.servicetalk.concurrent.api.SourceAdapters.toSource)4 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)4 ListenableAsyncCloseable (io.servicetalk.concurrent.api.ListenableAsyncCloseable)3 TerminalSignalConsumer (io.servicetalk.concurrent.api.TerminalSignalConsumer)3 AbstractOffloadingTest (io.servicetalk.concurrent.api.internal.AbstractOffloadingTest)3 Cancellable (io.servicetalk.concurrent.Cancellable)2 Publisher (io.servicetalk.concurrent.api.Publisher)2 FilterableStreamingHttpConnection (io.servicetalk.http.api.FilterableStreamingHttpConnection)2 TransportObserver (io.servicetalk.transport.api.TransportObserver)2 ArrayList (java.util.ArrayList)2 EnumSet (java.util.EnumSet)2 BiFunction (java.util.function.BiFunction)2 Nullable (javax.annotation.Nullable)2 CoreMatchers.is (org.hamcrest.CoreMatchers.is)2