當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。