本文整理匯總了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;
}