Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context Wrapping #214

Merged
merged 2 commits into from
Mar 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hystrix-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'idea'

dependencies {
compile 'com.netflix.archaius:archaius-core:0.4.1'
compile 'com.netflix.rxjava:rxjava-core:[0.14,0.15)'
compile 'com.netflix.rxjava:rxjava-core:0.16.1'
compile 'org.slf4j:slf4j-api:1.7.0'
compile 'com.google.code.findbugs:jsr305:2.0.0'
provided 'junit:junit-dep:4.10'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.util.concurrent.Callable;

import com.netflix.hystrix.strategy.HystrixPlugins;

/**
* Wrapper around {@link Callable} that manages the {@link HystrixRequestContext} initialization and cleanup for the execution of the {@link Callable}
*
Expand All @@ -30,6 +32,10 @@ public class HystrixContextCallable<K> implements Callable<K> {
private final Callable<K> actual;
private final HystrixRequestContext parentThreadState;

public HystrixContextCallable(Callable<K> actual) {
this(HystrixPlugins.getInstance().getConcurrencyStrategy(), actual);
}

public HystrixContextCallable(HystrixConcurrencyStrategy concurrencyStrategy, Callable<K> actual) {
this.actual = concurrencyStrategy.wrapCallable(actual);
this.parentThreadState = HystrixRequestContext.getContextForCurrentThread();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import rx.Subscription;
import rx.util.functions.Func2;

import com.netflix.hystrix.strategy.HystrixPlugins;

/**
* Wrapper around {@link Func2} that manages the {@link HystrixRequestContext} initialization and cleanup for the execution of the {@link Func2}
*
Expand Down Expand Up @@ -51,6 +53,10 @@ public class HystrixContextFunc2<T> implements Func2<Scheduler, T, Subscription>
private final AtomicReference<Scheduler> t1Holder = new AtomicReference<Scheduler>();
private final AtomicReference<T> t2Holder = new AtomicReference<T>();

public HystrixContextFunc2(Func2<? super Scheduler, ? super T, ? extends Subscription> action) {
this(HystrixPlugins.getInstance().getConcurrencyStrategy(), action);
}

public HystrixContextFunc2(final HystrixConcurrencyStrategy concurrencyStrategy, Func2<? super Scheduler, ? super T, ? extends Subscription> action) {
this.actual = action;
this.parentThreadState = HystrixRequestContext.getContextForCurrentThread();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.util.concurrent.Callable;

import com.netflix.hystrix.strategy.HystrixPlugins;

/**
* Wrapper around {@link Runnable} that manages the {@link HystrixRequestContext} initialization and cleanup for the execution of the {@link Runnable}
*
Expand All @@ -27,6 +29,10 @@ public class HystrixContextRunnable implements Runnable {
private final Callable<Void> actual;
private final HystrixRequestContext parentThreadState;

public HystrixContextRunnable(Runnable actual) {
this(HystrixPlugins.getInstance().getConcurrencyStrategy(), actual);
}

public HystrixContextRunnable(HystrixConcurrencyStrategy concurrencyStrategy, final Runnable actual) {
this.actual = concurrencyStrategy.wrapCallable(new Callable<Void>() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import rx.Subscription;
import rx.util.functions.Func2;

import com.netflix.hystrix.strategy.HystrixPlugins;

/**
* Wrap a {@link Scheduler} so that scheduled actions are wrapped with {@link HystrixContextFunc2} so that
* the {@link HystrixRequestContext} is properly copied across threads (if they are used by the {@link Scheduler}).
Expand All @@ -30,6 +32,10 @@ public class HystrixContextScheduler extends Scheduler {
private final HystrixConcurrencyStrategy concurrencyStrategy;
private final Scheduler actualScheduler;

public HystrixContextScheduler(Scheduler scheduler) {
this(HystrixPlugins.getInstance().getConcurrencyStrategy(), scheduler);
}

public HystrixContextScheduler(HystrixConcurrencyStrategy concurrencyStrategy, Scheduler scheduler) {
this.actualScheduler = scheduler;
this.concurrencyStrategy = concurrencyStrategy;
Expand Down