Search in sources :

Example 1 with FutureDecorator

use of com.netflix.hystrix.contrib.javanica.utils.FutureDecorator 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);
    }
}
Also used : FutureDecorator(com.netflix.hystrix.contrib.javanica.utils.FutureDecorator) HystrixExecutable(com.netflix.hystrix.HystrixExecutable) HystrixObservable(com.netflix.hystrix.HystrixObservable)

Aggregations

HystrixExecutable (com.netflix.hystrix.HystrixExecutable)1 HystrixObservable (com.netflix.hystrix.HystrixObservable)1 FutureDecorator (com.netflix.hystrix.contrib.javanica.utils.FutureDecorator)1