本文整理汇总了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);
}
};
}
}
示例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);
}
}
}
示例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;
}