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