public R call(R t1) {
System.out.println(">>>>>>>>>>>> fallback on thread: " + Thread.currentThread());
return executionHook.onComplete(_cmd, t1);
}
}).doOnCompleted(new Action0() {
@Override
public void call() {
// mark fallback on counter
metrics.markFallbackSuccess();
// record the executionResult
executionResult = executionResult.addEvents(HystrixEventType.FALLBACK_SUCCESS);
}
}).onErrorResumeNext(new Func1<Throwable, Observable<R>>() {
@Override
public Observable<R> call(Throwable t) {
Exception e = originalException;
Exception fe = getExceptionFromThrowable(t);
if (fe instanceof UnsupportedOperationException) {
logger.debug("No fallback for HystrixCommand. ", fe); // debug only since we're throwing the exception and someone higher will do something with it
/* executionHook for all errors */
try {
e = executionHook.onError(_cmd, failureType, e);
} catch (Exception hookException) {
logger.warn("Error calling ExecutionHook.onError", hookException);
}
return Observable.error(new HystrixRuntimeException(failureType, _cmd.getClass(), getLogMessagePrefix() + " " + message + " and no fallback available.", e, fe));
} else {
logger.debug("HystrixCommand execution " + failureType.name() + " and fallback retrieval failed.", fe);
metrics.markFallbackFailure();
// record the executionResult
executionResult = executionResult.addEvents(HystrixEventType.FALLBACK_FAILURE);
/* executionHook for all errors */
try {
e = executionHook.onError(_cmd, failureType, e);
} catch (Exception hookException) {
logger.warn("Error calling ExecutionHook.onError", hookException);
}
return Observable.error(new HystrixRuntimeException(failureType, _cmd.getClass(), getLogMessagePrefix() + " " + message + " and failed retrieving fallback.", e, fe));
}
}
}).doOnTerminate(new Action0() {
@Override
public void call() {
// record that we're completed (to handle non-successful events we do it here as well as at the end of executeCommand
isExecutionComplete.set(true);
}
}).doOnEach(new Action1<Notification<? super R>>() {
@Override
public void call(Notification<? super R> n) {
setRequestContextIfNeeded(currentRequestContext);
}
});
} else {
/* fallback is disabled so throw HystrixRuntimeException */
Exception e = originalException;
logger.debug("Fallback disabled for HystrixCommand so will throw HystrixRuntimeException. ", e); // debug only since we're throwing the exception and someone higher will do something with it
// record the executionResult
executionResult = executionResult.addEvents(eventType);
/* executionHook for all errors */
try {
e = executionHook.onError(this, failureType, e);
} catch (Exception hookException) {
logger.warn("Error calling ExecutionHook.onError", hookException);
}
return Observable.<R> error(new HystrixRuntimeException(failureType, this.getClass(), getLogMessagePrefix() + " " + message + " and fallback disabled.", e, null)).doOnTerminate(new Action0() {
@Override
public void call() {
// record that we're completed (to handle non-successful events we do it here as well as at the end of executeCommand
isExecutionComplete.set(true);