forked from Netflix/Hystrix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:Netflix/Hystrix
- Loading branch information
Showing
16 changed files
with
1,976 additions
and
520 deletions.
There are no files selected for viewing
231 changes: 108 additions & 123 deletions
231
hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommandResponseFromCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.netflix.hystrix; | ||
|
||
import rx.Observable; | ||
import rx.functions.Action0; | ||
import rx.functions.Action1; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
public class HystrixCommandResponseFromCache<R> extends HystrixCachedObservable<R> { | ||
private final AbstractCommand<R> originalCommand; | ||
|
||
/* package-private */ HystrixCommandResponseFromCache(Observable<R> originalObservable, final AbstractCommand<R> originalCommand) { | ||
super(originalObservable); | ||
this.originalCommand = originalCommand; | ||
} | ||
|
||
public Observable<R> toObservableWithStateCopiedInto(final AbstractCommand<R> commandToCopyStateInto) { | ||
final AtomicBoolean completionLogicRun = new AtomicBoolean(false); | ||
|
||
return cachedObservable | ||
.doOnError(new Action1<Throwable>() { | ||
@Override | ||
public void call(Throwable throwable) { | ||
if (!completionLogicRun.get()) { | ||
commandCompleted(commandToCopyStateInto); | ||
completionLogicRun.set(true); | ||
} | ||
} | ||
}) | ||
.doOnCompleted(new Action0() { | ||
@Override | ||
public void call() { | ||
if (!completionLogicRun.get()) { | ||
commandCompleted(commandToCopyStateInto); | ||
completionLogicRun.set(true); | ||
} | ||
} | ||
}) | ||
.doOnUnsubscribe(new Action0() { | ||
@Override | ||
public void call() { | ||
if (!completionLogicRun.get()) { | ||
commandUnsubscribed(commandToCopyStateInto); | ||
completionLogicRun.set(true); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
private void commandCompleted(final AbstractCommand<R> commandToCopyStateInto) { | ||
commandToCopyStateInto.executionResult = originalCommand.executionResult; | ||
} | ||
|
||
private void commandUnsubscribed(final AbstractCommand<R> commandToCopyStateInto) { | ||
commandToCopyStateInto.executionResult = commandToCopyStateInto.executionResult.addEvent(HystrixEventType.CANCELLED); | ||
commandToCopyStateInto.executionResult = commandToCopyStateInto.executionResult.setExecutionLatency(-1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.