Java Code Examples for com.netflix.hystrix.strategy.concurrency.HystrixRequestContext#isCurrentThreadInitialized()

The following examples show how to use com.netflix.hystrix.strategy.concurrency.HystrixRequestContext#isCurrentThreadInitialized() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HystrixGrayTrackWebConfiguration.java    From spring-cloud-gray with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnProperty(value = "gray.client.runenv", havingValue = "web", matchIfMissing = true)
public GrayTrackFilter grayTrackFilter(
        GrayTrackHolder grayTrackHolder,
        RequestLocalStorage requestLocalStorage) {
    return new GrayTrackFilter(grayTrackHolder, requestLocalStorage) {
        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
            if (!HystrixRequestContext.isCurrentThreadInitialized()) {
                HystrixRequestContext.initializeContext();
            }
            try {
                super.doFilter(request, response, chain);
            } finally {
                if (HystrixRequestContext.isCurrentThreadInitialized()) {
                    HystrixRequestContext.getContextForCurrentThread().shutdown();
                }
            }
        }
    };
}
 
Example 2
Source File: HystrixLocalStorageCycle.java    From spring-cloud-gray with Apache License 2.0 5 votes vote down vote up
@Override
public void initContext() {
    if (!HystrixRequestContext.isCurrentThreadInitialized()) {
        HystrixRequestContext.initializeContext();
        hystrixRequestContextInitialized.set(true);
    }
}
 
Example 3
Source File: HystrixLocalStorageCycle.java    From spring-cloud-gray with Apache License 2.0 5 votes vote down vote up
@Override
public void closeContext() {
    Boolean hystrixReqCxtInited = hystrixRequestContextInitialized.get();
    if (hystrixReqCxtInited != null) {
        hystrixRequestContextInitialized.remove();
        if (hystrixReqCxtInited && HystrixRequestContext.isCurrentThreadInitialized()) {
            HystrixRequestContext.getContextForCurrentThread().shutdown();
        }

    }
}
 
Example 4
Source File: CoreHeaderInterceptor.java    From paascloud-master with Apache License 2.0 5 votes vote down vote up
private static void initHystrixRequestContext(String labels) {
	log.info("LABEL={}", labels);
	if (!HystrixRequestContext.isCurrentThreadInitialized()) {
		HystrixRequestContext.initializeContext();
	}

	if (!StringUtils.isEmpty(labels)) {
		CoreHeaderInterceptor.LABEL.set(Arrays.asList(labels.split(CoreHeaderInterceptor.HEADER_LABEL_SPLIT)));
	} else {
		CoreHeaderInterceptor.LABEL.set(Collections.emptyList());
	}
}
 
Example 5
Source File: BizkeeperCommand.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
protected String getCacheKey() {
  if (HystrixRequestContext.isCurrentThreadInitialized()) {
    StringBuilder sb = new StringBuilder();
    sb.append(this.getCommandGroup().name());
    sb.append("-");
    sb.append(this.getCommandKey().name());
    return sb.toString();
  } else {
    return super.getCacheKey();
  }
}
 
Example 6
Source File: SWHystrixLifecycleForwardingRequestVariable.java    From skywalking with Apache License 2.0 5 votes vote down vote up
/**
 * Return null if the {@link HystrixRequestContext} has not been initialized for the current thread.
 * <p>
 * If {@link HystrixRequestContext} has been initialized then call method in superclass:
 * {@link HystrixRequestVariableDefault#get()}
 */
@Override
public T get() {
    if (!HystrixRequestContext.isCurrentThreadInitialized()) {
        return null;
    }
    return super.get();
}
 
Example 7
Source File: CoreHeaderInterceptor.java    From paascloud-master with Apache License 2.0 4 votes vote down vote up
private static void shutdownHystrixRequestContext() {
	if (HystrixRequestContext.isCurrentThreadInitialized()) {
		HystrixRequestContext.getContextForCurrentThread().shutdown();
	}
}