use of com.netflix.hystrix.HystrixObservable in project Hystrix by Netflix.
the class CommandExecutor method execute.
/**
* Calls a method of {@link HystrixExecutable} in accordance with specified execution type.
*
* @param invokable {@link HystrixInvokable}
* @param metaHolder {@link MetaHolder}
* @return the result of invocation of specific method.
* @throws RuntimeException
*/
public static Object execute(HystrixInvokable invokable, ExecutionType executionType, MetaHolder metaHolder) throws RuntimeException {
Validate.notNull(invokable);
Validate.notNull(metaHolder);
switch(executionType) {
case SYNCHRONOUS:
{
return castToExecutable(invokable, executionType).execute();
}
case ASYNCHRONOUS:
{
HystrixExecutable executable = castToExecutable(invokable, executionType);
if (metaHolder.hasFallbackMethodCommand() && ExecutionType.ASYNCHRONOUS == metaHolder.getFallbackExecutionType()) {
return new FutureDecorator(executable.queue());
}
return executable.queue();
}
case OBSERVABLE:
{
HystrixObservable observable = castToObservable(invokable);
return ObservableExecutionMode.EAGER == metaHolder.getObservableExecutionMode() ? observable.observe() : observable.toObservable();
}
default:
throw new RuntimeException("unsupported execution type: " + executionType);
}
}
use of com.netflix.hystrix.HystrixObservable in project java-chassis by ServiceComb.
the class BizkeeperHandlerDelegate method forceFallbackCommand.
protected HystrixObservable<Response> forceFallbackCommand(Invocation invocation) {
return new HystrixObservable<Response>() {
@Override
public Observable<Response> observe() {
ReplaySubject<Response> subject = ReplaySubject.create();
final Subscription sourceSubscription = toObservable().subscribe(subject);
return subject.doOnUnsubscribe(new Action0() {
@Override
public void call() {
sourceSubscription.unsubscribe();
}
});
}
@Override
public Observable<Response> toObservable() {
return Observable.create(f -> {
try {
if (Configuration.FALLBACKPOLICY_POLICY_RETURN.equals(Configuration.INSTANCE.getFallbackPolicyPolicy(handler.groupname, invocation.getMicroserviceName(), invocation.getOperationMeta().getMicroserviceQualifiedName()))) {
f.onNext(Response.succResp(null));
} else {
f.onNext(Response.failResp(invocation.getInvocationType(), BizkeeperExceptionUtils.createBizkeeperException(BizkeeperExceptionUtils.CSE_HANDLER_BK_FALLBACK, null, invocation.getOperationMeta().getMicroserviceQualifiedName())));
}
} catch (Exception e) {
f.onError(e);
}
});
}
;
};
}
Aggregations