Search in sources :

Example 16 with ContextMap

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

the class ContextPreservingConsumer method slowPath.

private void slowPath(T t) {
    ContextMap prev = CONTEXT_THREAD_LOCAL.get();
    try {
        CONTEXT_THREAD_LOCAL.set(saved);
        delegate.accept(t);
    } finally {
        CONTEXT_THREAD_LOCAL.set(prev);
    }
}
Also used : ContextMap(io.servicetalk.context.api.ContextMap)

Example 17 with ContextMap

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

the class ContextPreservingRunnable method slowPath.

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

Example 18 with ContextMap

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

the class ContextPreservingCancellable method slowPath.

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

Example 19 with ContextMap

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

the class ContextPreservingBiConsumer method slowPath.

private void slowPath(T t, U u) {
    ContextMap prev = CONTEXT_THREAD_LOCAL.get();
    try {
        CONTEXT_THREAD_LOCAL.set(saved);
        delegate.accept(t, u);
    } finally {
        CONTEXT_THREAD_LOCAL.set(prev);
    }
}
Also used : ContextMap(io.servicetalk.context.api.ContextMap)

Example 20 with ContextMap

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

the class ContextPreservingSingleSubscriber method onSubscribe.

@Override
public final void onSubscribe(Cancellable cancellable) {
    final Thread currentThread = Thread.currentThread();
    if (currentThread instanceof ContextMapHolder) {
        final ContextMapHolder asyncContextMapHolder = (ContextMapHolder) currentThread;
        ContextMap prev = asyncContextMapHolder.context();
        try {
            asyncContextMapHolder.context(saved);
            invokeOnSubscribe(cancellable);
        } finally {
            asyncContextMapHolder.context(prev);
        }
    } else {
        onSubscribeSlowPath(cancellable);
    }
}
Also used : ContextMapHolder(io.servicetalk.context.api.ContextMapHolder) 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