当前位置: 首页>>代码示例>>Java>>正文


Java FallbackHandler类代码示例

本文整理汇总了Java中org.eclipse.microprofile.faulttolerance.FallbackHandler的典型用法代码示例。如果您正苦于以下问题:Java FallbackHandler类的具体用法?Java FallbackHandler怎么用?Java FallbackHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FallbackHandler类属于org.eclipse.microprofile.faulttolerance包,在下文中一共展示了FallbackHandler类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFallback

import org.eclipse.microprofile.faulttolerance.FallbackHandler; //导入依赖的package包/类
Supplier<Object> getFallback(ExecutionContextWithInvocationContext ctx) {
    if (!hasFallback()) {
        return null;
    } else if (unmanaged != null) {
        return () -> {
            Unmanaged.UnmanagedInstance<FallbackHandler<?>> unmanagedInstance = unmanaged.newInstance();
            FallbackHandler<?> handler = unmanagedInstance.produce().inject().postConstruct().get();
            try {
                return handler.handle(ctx);
            } finally {
                // The instance exists to service a single invocation only
                unmanagedInstance.preDestroy().dispose();
            }
        };
    } else {
        return () -> {
            try {
                return fallbackMethod.invoke(ctx.getTarget(), ctx.getParameters());
            } catch (IllegalAccessException | InvocationTargetException e) {
                throw new FaultToleranceException("Error during fallback method invocation", e);
            }
        };
    }
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:25,代码来源:HystrixCommandInterceptor.java

示例2: validate

import org.eclipse.microprofile.faulttolerance.FallbackHandler; //导入依赖的package包/类
@Override
public void validate() {
    if (!"".equals(get(FALLBACK_METHOD))) {
        if (!Fallback.DEFAULT.class.equals(get(VALUE))) {
            throw new FaultToleranceDefinitionException("Fallback configuration can't contain an handler class and method at the same time");
        }
        Method fallbackMethod;
        try {
            fallbackMethod = SecurityActions.getDeclaredMethod(method.getDeclaringClass(), get(FALLBACK_METHOD), method.getParameterTypes());
        } catch (NoSuchMethodException | PrivilegedActionException e) {
            throw new FaultToleranceDefinitionException(
                    "Fallback method " + get(FALLBACK_METHOD) + " with same parameters as " + method.getName() + " not found", e);
        }
        if (!isAssignableFrom(method.getGenericReturnType(), fallbackMethod.getGenericReturnType())) {
            throw new FaultToleranceDefinitionException(
                    "Fallback method " + get(FALLBACK_METHOD) + " must have a return type assignable to " + method.getName());
        }
    }
    if (!Fallback.DEFAULT.class.equals(get(VALUE))) {
        Class<?> fbhc = get(VALUE);
        Type fallbackType = null;
        for (Type genericInterface : fbhc.getGenericInterfaces()) {
            if (genericInterface instanceof ParameterizedType) {
                ParameterizedType parameterizedType = (ParameterizedType) genericInterface;
                if (parameterizedType.getRawType().equals(FallbackHandler.class)) {
                    fallbackType = parameterizedType.getActualTypeArguments()[0];
                    break;
                }
            }
        }
        if (fallbackType == null || !method.getGenericReturnType().equals(fallbackType)) {
            throw new FaultToleranceDefinitionException(
                    "Fallback handler type [" + fallbackType + "] is not the same as the method return type: " + method);
        }
    }
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:37,代码来源:FallbackConfig.java

示例3: initUnmanaged

import org.eclipse.microprofile.faulttolerance.FallbackHandler; //导入依赖的package包/类
private Unmanaged<FallbackHandler<?>> initUnmanaged(FaultToleranceOperation operation) {
    if (operation.hasFallback()) {
        return new Unmanaged<>(beanManager, operation.getFallback().get(FallbackConfig.VALUE));
    }
    return null;
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:7,代码来源:HystrixCommandInterceptor.java


注:本文中的org.eclipse.microprofile.faulttolerance.FallbackHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。