Search in sources :

Example 1 with ContextMapHolder

use of io.servicetalk.context.api.ContextMapHolder 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);
    }
}
Also used : ContextMapHolder(io.servicetalk.context.api.ContextMapHolder) ContextMap(io.servicetalk.context.api.ContextMap)

Example 2 with ContextMapHolder

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

the class ContextPreservingSubscriber method onSubscribe.

@Override
public final void onSubscribe(Subscription s) {
    final Thread currentThread = Thread.currentThread();
    if (currentThread instanceof ContextMapHolder) {
        final ContextMapHolder asyncContextMapHolder = (ContextMapHolder) currentThread;
        ContextMap prev = asyncContextMapHolder.context();
        try {
            asyncContextMapHolder.context(saved);
            invokeOnSubscribe(s);
        } finally {
            asyncContextMapHolder.context(prev);
        }
    } else {
        onSubscribeSlowPath(s);
    }
}
Also used : ContextMapHolder(io.servicetalk.context.api.ContextMapHolder) ContextMap(io.servicetalk.context.api.ContextMap)

Example 3 with ContextMapHolder

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

the class ContextPreservingSubscriber 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 4 with ContextMapHolder

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

the class ContextPreservingSubscriber 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 5 with ContextMapHolder

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

the class ContextPreservingSubscription method request.

@Override
public void request(long l) {
    final Thread currentThread = Thread.currentThread();
    if (currentThread instanceof ContextMapHolder) {
        final ContextMapHolder asyncContextMapHolder = (ContextMapHolder) currentThread;
        ContextMap prev = asyncContextMapHolder.context();
        try {
            asyncContextMapHolder.context(saved);
            subscription.request(l);
        } finally {
            asyncContextMapHolder.context(prev);
        }
    } else {
        requestSlowPath(l);
    }
}
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