Search in sources :

Example 16 with ContextMapHolder

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

the class ContextPreservingCompletableSubscriber 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 17 with ContextMapHolder

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

the class ContextPreservingCompletableSubscriber 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 18 with ContextMapHolder

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

the class ContextPreservingConsumer method accept.

@Override
public void accept(T t) {
    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);
        } finally {
            asyncContextMapHolder.context(prev);
        }
    } else {
        slowPath(t);
    }
}
Also used : ContextMapHolder(io.servicetalk.context.api.ContextMapHolder) ContextMap(io.servicetalk.context.api.ContextMap)

Example 19 with ContextMapHolder

use of io.servicetalk.context.api.ContextMapHolder 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 20 with ContextMapHolder

use of io.servicetalk.context.api.ContextMapHolder 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)

Aggregations

ContextMap (io.servicetalk.context.api.ContextMap)20 ContextMapHolder (io.servicetalk.context.api.ContextMapHolder)20