use of io.servicetalk.context.api.ContextMapHolder in project servicetalk by apple.
the class ContextPreservingCancellable method cancel.
@Override
public void cancel() {
final Thread currentThread = Thread.currentThread();
if (currentThread instanceof ContextMapHolder) {
final ContextMapHolder asyncContextMapHolder = (ContextMapHolder) currentThread;
ContextMap prev = asyncContextMapHolder.context();
try {
asyncContextMapHolder.context(saved);
delegate.cancel();
} finally {
asyncContextMapHolder.context(prev);
}
} else {
slowPath();
}
}
use of io.servicetalk.context.api.ContextMapHolder in project servicetalk by apple.
the class ContextPreservingBiConsumer method accept.
@Override
public void accept(T t, U u) {
final Thread currentThread = Thread.currentThread();
if (currentThread instanceof ContextMapHolder) {
final ContextMapHolder asyncContextMapHolder = (ContextMapHolder) currentThread;
ContextMap prev = asyncContextMapHolder.context();
try {
asyncContextMapHolder.context(saved);
delegate.accept(t, u);
} finally {
asyncContextMapHolder.context(prev);
}
} else {
slowPath(t, u);
}
}
use of io.servicetalk.context.api.ContextMapHolder in project servicetalk by apple.
the class ContextPreservingCallable method call.
@Override
public V call() throws Exception {
final Thread currentThread = Thread.currentThread();
if (currentThread instanceof ContextMapHolder) {
final ContextMapHolder asyncContextMapHolder = (ContextMapHolder) currentThread;
ContextMap prev = asyncContextMapHolder.context();
try {
asyncContextMapHolder.context(saved);
return delegate.call();
} finally {
asyncContextMapHolder.context(prev);
}
} else {
return slowPath();
}
}
use of io.servicetalk.context.api.ContextMapHolder in project servicetalk by apple.
the class AsyncContextMapThreadLocal method get.
ContextMap get() {
final Thread t = Thread.currentThread();
if (t instanceof ContextMapHolder) {
final ContextMapHolder contextMapHolder = (ContextMapHolder) t;
ContextMap map = contextMapHolder.context();
if (map == null) {
map = newContextMap();
contextMapHolder.context(map);
}
return map;
} else {
return CONTEXT_THREAD_LOCAL.get();
}
}
use of io.servicetalk.context.api.ContextMapHolder in project servicetalk by apple.
the class ContextPreservingCompletableSubscriber method onSubscribe.
@Override
public final void onSubscribe(final 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);
}
}
Aggregations