Search in sources :

Example 41 with ContextMap

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

the class ContextPreservingRunnable method run.

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

Example 42 with ContextMap

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

the class ContextPreservingSubscriber method onErrorSlowPath.

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

Example 43 with ContextMap

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

the class ContextPreservingSubscriber method onNext.

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

Example 44 with ContextMap

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

the class ContextPreservingSubscription method requestSlowPath.

private void requestSlowPath(long l) {
    ContextMap prev = CONTEXT_THREAD_LOCAL.get();
    try {
        CONTEXT_THREAD_LOCAL.set(saved);
        subscription.request(l);
    } finally {
        CONTEXT_THREAD_LOCAL.set(prev);
    }
}
Also used : ContextMap(io.servicetalk.context.api.ContextMap)

Example 45 with ContextMap

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

the class ContextPreservingSingleSubscriber method onErrorSlowPath.

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

Aggregations

ContextMap (io.servicetalk.context.api.ContextMap)45 ContextMapHolder (io.servicetalk.context.api.ContextMapHolder)20 AsyncContext (io.servicetalk.concurrent.api.AsyncContext)3 Executor (io.servicetalk.concurrent.api.Executor)3 SourceAdapters.toSource (io.servicetalk.concurrent.api.SourceAdapters.toSource)3 TerminalSignalConsumer (io.servicetalk.concurrent.api.TerminalSignalConsumer)3 AbstractOffloadingTest (io.servicetalk.concurrent.api.internal.AbstractOffloadingTest)3 EnumSet (java.util.EnumSet)3 BiFunction (java.util.function.BiFunction)3 CoreMatchers.is (org.hamcrest.CoreMatchers.is)3 CoreMatchers.not (org.hamcrest.CoreMatchers.not)3 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)3 CoreMatchers.sameInstance (org.hamcrest.CoreMatchers.sameInstance)3 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)3 Matchers.lessThan (org.hamcrest.Matchers.lessThan)3 Cancellable (io.servicetalk.concurrent.Cancellable)2 TestCancellable (io.servicetalk.concurrent.api.TestCancellable)2 PublisherSource (io.servicetalk.concurrent.PublisherSource)1 Completable (io.servicetalk.concurrent.api.Completable)1 Publisher (io.servicetalk.concurrent.api.Publisher)1