本文整理汇总了Java中org.glassfish.hk2.api.ActiveDescriptor类的典型用法代码示例。如果您正苦于以下问题:Java ActiveDescriptor类的具体用法?Java ActiveDescriptor怎么用?Java ActiveDescriptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ActiveDescriptor类属于org.glassfish.hk2.api包,在下文中一共展示了ActiveDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: activate
import org.glassfish.hk2.api.ActiveDescriptor; //导入依赖的package包/类
@Override
protected void activate(ActiveDescriptor<?> handle, Object service, Method method, CachedGauge annotation) {
if (method.getParameterCount() != 0) {
log.error("@CachedGauge placed on method {} which must have zero parameters, but has {}", method, method.getParameterCount());
return;
}
com.codahale.metrics.CachedGauge<?> gauge = new com.codahale.metrics.CachedGauge<Object>(annotation.timeout(),
annotation.timeoutUnit()
) {
@Override
protected Object loadValue() {
try {
return method.invoke(service);
} catch (Exception e) {
throw new RuntimeException("Failed to read gauge value from " + method, e instanceof InvocationTargetException ? (
(InvocationTargetException) e
).getTargetException() : e);
}
}
};
String name = metricNameService.getFormattedMetricName(method, com.codahale.metrics.CachedGauge.class);
log.debug("Activating cached gauge {} monitoring {}", name, method);
metricRegistry.register(name, gauge);
}
示例2: activate
import org.glassfish.hk2.api.ActiveDescriptor; //导入依赖的package包/类
@Override
protected void activate(ActiveDescriptor<?> handle, Object service, Method method, Gauge annotation) {
if (method.getParameterCount() != 0) {
log.error("@Gauge placed on method {} which must have zero parameters, but has {}", method, method.getParameterCount());
return;
}
com.codahale.metrics.Gauge<?> gauge = () -> {
try {
return method.invoke(service);
} catch (Exception e) {
throw new RuntimeException("Failed to read gauge value from " + method, e instanceof InvocationTargetException ? (
(InvocationTargetException) e
).getTargetException() : e);
}
};
String name = metricNameService.getFormattedMetricName(method, com.codahale.metrics.Gauge.class);
log.debug("Activating gauge {} monitoring {}", name, method);
metricRegistry.register(name, gauge);
}
示例3: resolve
import org.glassfish.hk2.api.ActiveDescriptor; //导入依赖的package包/类
@Override
public Object resolve(Injectee injectee, ServiceHandle<?> root) {
ActiveDescriptor<?> descriptor = locator.getInjecteeDescriptor(injectee);
if (descriptor == null) {
// Is it OK to return null?
if (isNullable(injectee)) {
return null;
}
throw new MultiException(new UnsatisfiedDependencyException(injectee));
}
return locator.getService(descriptor, root, injectee);
}
示例4: newActiveDescriptor
import org.glassfish.hk2.api.ActiveDescriptor; //导入依赖的package包/类
/**
* @see #newThreeThirtyInjectionResolverDescriptor(ServiceLocator)
* @see #newGuiceInjectionResolverDescriptor(ServiceLocator, ActiveDescriptor)
*/
private static <T extends Annotation> ActiveDescriptor<InjectionResolver<T>> newActiveDescriptor(ServiceLocator locator,
InjectionResolver<T> resolver, Set<Annotation> qualifiers, String name, Class<? extends T> clazz) {
Set<Type> contracts = Collections.<Type>singleton(
new ParameterizedTypeImpl(InjectionResolver.class, clazz));
ActiveDescriptor<InjectionResolver<T>> descriptor =
new ConstantActiveDescriptor<InjectionResolver<T>>(
resolver, contracts, Singleton.class,
name, qualifiers, DescriptorVisibility.NORMAL,
0, (Boolean)null, (Boolean)null, (String)null,
locator.getLocatorId(), (Map<String, List<String>>)null);
return descriptor;
}
示例5: init
import org.glassfish.hk2.api.ActiveDescriptor; //导入依赖的package包/类
/**
* Scan the requested packages on the classpath for HK2 'Service' and 'Contract' annotated classes.
* Load the metadata for those classes into the HK2 Service Locator.
*
* This implementation should support all Annotations that are supported by HK2 - however - if you are using
* HK2 older than 2.3.0 - note that it is impacted by this bug: https://java.net/jira/browse/HK2-187
*
* For an implementation that is not impacted by that bug, see {@link HK2RuntimeInitializerCustom}
*
* @see org.glassfish.hk2.api.ServiceLocatorFactory#create(String)
* @see ServiceLocatorUtilities#createAndPopulateServiceLocator(String)
*
* @param serviceLocatorName - The name of the ServiceLocator to find (or create if it doesn't yet exist)
* @param readInhabitantFiles - Read and process inhabitant files before doing the classpath scan. Annotated items
* found during the scan will override items found in the inhabitant files, if they collide.
* @param packageNames -- The set of package names to scan recursively - for example - new String[]{"org.foo", "com.bar"}
* If not provided, the entire classpath is scanned
* @return - The created ServiceLocator (but in practice, you can lookup this ServiceLocator by doing:
* <pre>
* {@code
* ServiceLocatorFactory.getInstance().create("SomeName");
* }
* </pre>
* @throws IOException
* @throws ClassNotFoundException
*/
public static ServiceLocator init(String serviceLocatorName, boolean readInhabitantFiles, String ... packageNames) throws IOException, ClassNotFoundException
{
AnnotatedClasses ac = new AnnotatedClasses();
@SuppressWarnings("unchecked")
AnnotationDetector cf = new AnnotationDetector(new AnnotationReporter(ac, new Class[]{Service.class}));
if (packageNames == null || packageNames.length == 0)
{
cf.detect();
}
else
{
cf.detect(packageNames);
}
ServiceLocator locator = null;
if (readInhabitantFiles)
{
locator = ServiceLocatorUtilities.createAndPopulateServiceLocator(serviceLocatorName);
}
else
{
ServiceLocatorFactory factory = ServiceLocatorFactory.getInstance();
locator = factory.create(serviceLocatorName);
}
for (ActiveDescriptor<?> ad : ServiceLocatorUtilities.addClasses(locator, ac.getAnnotatedClasses()))
{
log.debug("Added " + ad.toString());
}
return locator;
}
示例6: listInjected
import org.glassfish.hk2.api.ActiveDescriptor; //导入依赖的package包/类
private void listInjected(ServiceLocator locator) {
LOGGER.trace("registered injectables [{}]:", locator.getName());
for (ActiveDescriptor<?> descriptor : locator.getDescriptors(d -> true)) {
LOGGER.trace("registered c:{} s:{} r:{} d:{}", descriptor.getImplementation(), descriptor.getScope(), descriptor.isReified(), descriptor);
}
}
示例7: newThreeThirtyInjectionResolverDescriptor
import org.glassfish.hk2.api.ActiveDescriptor; //导入依赖的package包/类
/**
* Creates and returns a {@link InjectionResolver} for {@link javax.inject.Inject}.
*
* @see javax.inject.Inject
* @see InjectionResolver
*/
public static ActiveDescriptor<InjectionResolver<javax.inject.Inject>> newThreeThirtyInjectionResolverDescriptor(ServiceLocator locator) {
GuiceThreeThirtyResolver resolver
= new GuiceThreeThirtyResolver(locator);
Set<Annotation> qualifiers = Collections.<Annotation>singleton(
new NamedImpl(SYSTEM_RESOLVER_NAME));
return newActiveDescriptor(locator, resolver, qualifiers, SYSTEM_RESOLVER_NAME, javax.inject.Inject.class);
}
示例8: newGuiceInjectionResolverDescriptor
import org.glassfish.hk2.api.ActiveDescriptor; //导入依赖的package包/类
/**
* Creates and returns a {@link InjectionResolver} for {@link com.google.inject.Inject}
*
* @see #newThreeThirtyInjectionResolverDescriptor(ServiceLocator)
* @see com.google.inject.Inject
* @see InjectionResolver
*/
public static ActiveDescriptor<InjectionResolver<com.google.inject.Inject>> newGuiceInjectionResolverDescriptor(ServiceLocator locator,
ActiveDescriptor<? extends InjectionResolver<?>> threeThirtyResolver) {
GuiceInjectionResolver resolver = new GuiceInjectionResolver(threeThirtyResolver);
Set<Annotation> qualifiers = Collections.emptySet();
return newActiveDescriptor(locator, resolver, qualifiers, GUICE_RESOLVER_NAME, com.google.inject.Inject.class);
}
示例9: getInterceptors
import org.glassfish.hk2.api.ActiveDescriptor; //导入依赖的package包/类
protected <T extends Executable, I extends Interceptor, F> List<I> getInterceptors(
T interceptee,
IterableProvider<? extends F> factoryProviders,
Class<F> interceptorType,
InterceptorFactory<F, T, Annotation, I> interceptorProvider
) {
List<I> interceptors = Lists.newArrayList();
factoryProviders.handleIterator().forEach(handle -> {
// Make sure descriptor is fully reified
ActiveDescriptor<?> descriptor = handle.getActiveDescriptor();
if (!descriptor.isReified()) {
descriptor = locator.reifyDescriptor(descriptor);
}
// Check the type of annotation supported by the factory
for (Type contract : descriptor.getContractTypes()) {
if (ReflectionHelper.getRawClass(contract) == interceptorType) {
Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) ReflectionHelper.getRawClass(
ReflectionHelper.getFirstTypeArgument(contract));
// Might be Object.class if getRawClass found an unbound type variable or wildcard
if (!Annotation.class.isAssignableFrom(annotationClass)) {
log.warn("Unable to determine annotation binder from contract type {}", annotationClass);
return;
}
Annotation ann = interceptee.getAnnotation(annotationClass);
if (ann == null) {
ann = interceptee.getDeclaringClass().getAnnotation(annotationClass);
}
if (ann != null) {
// Create the factory and produce an interceptor
F factory = handle.getService();
I interceptor = interceptorProvider.apply(factory, interceptee, ann);
if (interceptor != null) {
interceptors.add(interceptor);
}
}
return;
}
}
});
return interceptors;
}
示例10: activate
import org.glassfish.hk2.api.ActiveDescriptor; //导入依赖的package包/类
@Override
protected void activate(ActiveDescriptor<?> descriptor, Object service, ManagedObject annotation) {
container.beanAdded(null, service);
}
示例11: deactivate
import org.glassfish.hk2.api.ActiveDescriptor; //导入依赖的package包/类
@Override
protected void deactivate(ActiveDescriptor<?> descriptor, Object service, ManagedObject annotation) {
container.beanRemoved(null, service);
}
示例12: getDescriptors
import org.glassfish.hk2.api.ActiveDescriptor; //导入依赖的package包/类
@Override
public List<ActiveDescriptor<?>> getDescriptors(Filter filter) {
throw new UnsupportedOperationException("Will not be supported!");
}
示例13: getBestDescriptor
import org.glassfish.hk2.api.ActiveDescriptor; //导入依赖的package包/类
@Override
public ActiveDescriptor<?> getBestDescriptor(Filter filter) {
throw new UnsupportedOperationException("Will not be supported!");
}
示例14: reifyDescriptor
import org.glassfish.hk2.api.ActiveDescriptor; //导入依赖的package包/类
@Override
public ActiveDescriptor<?> reifyDescriptor(Descriptor descriptor, Injectee injectee) throws MultiException {
throw new UnsupportedOperationException("Will not be supported!");
}
示例15: getInjecteeDescriptor
import org.glassfish.hk2.api.ActiveDescriptor; //导入依赖的package包/类
@Override
public ActiveDescriptor<?> getInjecteeDescriptor(Injectee injectee) throws MultiException {
throw new UnsupportedOperationException("Will not be supported!");
}