use of io.servicetalk.context.api.ContextMap in project servicetalk by apple.
the class ContextPreservingFunction method apply.
@Override
public U apply(T t) {
final Thread currentThread = Thread.currentThread();
if (currentThread instanceof ContextMapHolder) {
final ContextMapHolder asyncContextMapHolder = (ContextMapHolder) currentThread;
ContextMap prev = asyncContextMapHolder.context();
try {
asyncContextMapHolder.context(saved);
return delegate.apply(t);
} finally {
asyncContextMapHolder.context(prev);
}
} else {
return slowPath(t);
}
}
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);
}
}
use of io.servicetalk.context.api.ContextMap in project servicetalk by apple.
the class Completable method subscribeInternal.
/**
* A internal subscribe method similar to {@link CompletableSource#subscribe(Subscriber)} which can be used by
* different implementations to subscribe.
*
* @param subscriber {@link Subscriber} to subscribe for the result.
*/
protected final void subscribeInternal(Subscriber subscriber) {
AsyncContextProvider contextProvider = AsyncContext.provider();
ContextMap contextMap = contextForSubscribe(contextProvider);
subscribeWithContext(subscriber, contextProvider, contextMap);
}
use of io.servicetalk.context.api.ContextMap in project servicetalk by apple.
the class Single method subscribeAndReturnContext.
/**
* Subscribes to this {@link Single} and returns the {@link ContextMap} associated for this subscribe
* operation.
*
* @param subscriber the subscriber.
* @param provider {@link AsyncContextProvider} to use.
* @return {@link ContextMap} for this subscribe operation.
*/
final ContextMap subscribeAndReturnContext(Subscriber<? super T> subscriber, AsyncContextProvider provider) {
final ContextMap contextMap = contextForSubscribe(provider);
subscribeWithContext(subscriber, provider, contextMap);
return contextMap;
}
use of io.servicetalk.context.api.ContextMap in project servicetalk by apple.
the class Publisher method subscribeInternal.
/**
* A internal subscribe method similar to {@link PublisherSource#subscribe(Subscriber)} which can be used by
* different implementations to subscribe.
*
* @param subscriber {@link Subscriber} to subscribe for the result.
*/
protected void subscribeInternal(Subscriber<? super T> subscriber) {
AsyncContextProvider contextProvider = AsyncContext.provider();
ContextMap contextMap = contextForSubscribe(contextProvider);
subscribeWithContext(subscriber, contextProvider, contextMap);
}
Aggregations