Skip to content

Commit 5846092

Browse files
committed
Improved implementation, fixed build
1 parent f8da6aa commit 5846092

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

hystrix-core/src/main/java/com/netflix/hystrix/HystrixRequestCache.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import rx.Observable;
2424

2525
import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
26+
import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;
2627
import com.netflix.hystrix.strategy.concurrency.HystrixRequestVariableDefault;
2728
import com.netflix.hystrix.strategy.concurrency.HystrixRequestVariableHolder;
2829
import com.netflix.hystrix.strategy.concurrency.HystrixRequestVariableLifecycle;
@@ -100,6 +101,9 @@ private static HystrixRequestCache getInstance(RequestCacheKey rcKey, HystrixCon
100101
/* package */<T> Observable<T> get(String cacheKey) {
101102
ValueCacheKey key = getRequestCacheKey(cacheKey);
102103
if (key != null) {
104+
if (!HystrixRequestContext.isCurrentThreadInitialized()) {
105+
throw new IllegalStateException("Failed to get HystrixRequestVariable. Maybe you need to initialize the HystrixRequestContext?");
106+
}
103107
/* look for the stored value */
104108
return (Observable<T>) requestVariableForCache.get(concurrencyStrategy).get(key);
105109
}

hystrix-core/src/main/java/com/netflix/hystrix/strategy/concurrency/HystrixRequestVariableHolder.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ public T get(HystrixConcurrencyStrategy concurrencyStrategy) {
6565
}
6666
}
6767

68-
T result = (T) requestVariableInstance.get(key).get();
69-
if (result == null) {
70-
throw new IllegalStateException("Failed to get HystrixRequestVariable. Maybe you need to initialize the HystrixRequestContext?");
71-
}
72-
return result;
68+
return (T) requestVariableInstance.get(key).get();
7369
}
7470

7571
private static class RVCacheKey {

0 commit comments

Comments
 (0)