本文整理汇总了Java中javax.enterprise.inject.spi.BeanManager.getExtension方法的典型用法代码示例。如果您正苦于以下问题:Java BeanManager.getExtension方法的具体用法?Java BeanManager.getExtension怎么用?Java BeanManager.getExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.enterprise.inject.spi.BeanManager
的用法示例。
在下文中一共展示了BeanManager.getExtension方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: produce
import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
@Produces
@ApplicationScoped
public JsonDataProvider produce(BeanManager beanManager) {
ProbeExtension extension = beanManager.getExtension(ProbeExtension.class);
if (extension == null) {
throw new IllegalStateException("ProbeExtension not available");
}
try {
// Unfortunately, getJsonDataProvider() is package-private
Method getProviderMethod = SecurityActions.getDeclaredMethod(ProbeExtension.class, "getJsonDataProvider");
if (getProviderMethod == null) {
throw new IllegalStateException("ProbeExtension.getJsonDataProvider() method not found or inaccessible");
}
SecurityActions.ensureAccessible(getProviderMethod);
return (JsonDataProvider) getProviderMethod.invoke(extension);
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new IllegalStateException("Unable to get JsonDataProvider", e);
}
}
示例2: HystrixCommandInterceptor
import javax.enterprise.inject.spi.BeanManager; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Inject
public HystrixCommandInterceptor(@ConfigProperty(name = "MP_Fault_Tolerance_NonFallback_Enabled", defaultValue = "true") Boolean nonFallBackEnable, @ConfigProperty(name = SYNC_CIRCUIT_BREAKER_KEY, defaultValue = "true") Boolean syncCircuitBreakerEnabled, BeanManager beanManager) {
this.nonFallBackEnable = nonFallBackEnable;
this.syncCircuitBreakerEnabled = syncCircuitBreakerEnabled;
this.beanManager = beanManager;
this.extension = beanManager.getExtension(HystrixExtension.class);
this.commandMetadataMap = new ConcurrentHashMap<>();
// WORKAROUND: Hystrix does not allow to use custom HystrixCircuitBreaker impl
// See also https://github.com/Netflix/Hystrix/issues/9
try {
Field field = SecurityActions.getDeclaredField(com.netflix.hystrix.HystrixCircuitBreaker.Factory.class, "circuitBreakersByCommand");
SecurityActions.setAccessible(field);
this.circuitBreakers = (ConcurrentHashMap<String, HystrixCircuitBreaker>) field.get(null);
} catch (Exception e) {
throw new IllegalStateException("Could not obtain reference to com.netflix.hystrix.HystrixCircuitBreaker.Factory.circuitBreakersByCommand");
}
}