All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nepxion.discovery.plugin.strategy.gateway.wrapper.DefaultCallableWrapper Maven / Gradle / Ivy

package com.nepxion.discovery.plugin.strategy.gateway.wrapper;

/**
 * 

Title: Nepxion Discovery

*

Description: Nepxion Discovery

*

Copyright: Copyright (c) 2017-2050

*

Company: Nepxion

* @author Haojun Ren * @author Hao Huang * @version 1.0 */ import java.util.concurrent.Callable; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.server.ServerWebExchange; import com.nepxion.discovery.plugin.strategy.gateway.context.GatewayStrategyContext; import com.nepxion.discovery.plugin.strategy.tracer.StrategyTracerContextManager; import com.nepxion.discovery.plugin.strategy.wrapper.CallableWrapper; public class DefaultCallableWrapper implements CallableWrapper { @Autowired(required = false) private StrategyTracerContextManager strategyTracerContextManager; @Override public Callable wrapCallable(Callable callable) { ServerWebExchange exchange = GatewayStrategyContext.getCurrentContext().getExchange(); Object tracerContext = getTracerContext(); return new Callable() { @Override public T call() throws Exception { try { GatewayStrategyContext.getCurrentContext().setExchange(exchange); setTracerContext(tracerContext); return callable.call(); } finally { GatewayStrategyContext.clearCurrentContext(); clearTracerContext(); } } }; } private Object getTracerContext() { if (strategyTracerContextManager == null) { return null; } return strategyTracerContextManager.getContext(); } private void setTracerContext(Object context) { if (strategyTracerContextManager == null) { return; } strategyTracerContextManager.setContext(context); } private void clearTracerContext() { if (strategyTracerContextManager == null) { return; } strategyTracerContextManager.clearContext(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy