use of org.glassfish.hk2.api.Descriptor in project jersey by jersey.
the class BeanParamMemoryLeakTest method testBeanParam.
@Test
public void testBeanParam() throws Exception {
initiateWebApplication(BeanParamInjectionResource.class);
final InjectionManager injectionManager = app().getInjectionManager();
if (!(injectionManager instanceof HK2InjectionManager)) {
throw new RuntimeException("Bean Manager is not an injection manager");
}
HK2InjectionManager hk2BeanManager = (HK2InjectionManager) injectionManager;
ServiceLocator serviceLocator = hk2BeanManager.getServiceLocator();
// we do not expect any descriptor registered yet
assertEquals(0, serviceLocator.getDescriptors(new ParameterBeanFilter()).size());
// now make one registered via this call
assertEquals("one", resource("/jaxrs?q=one").getEntity());
// make sure it got registered
assertEquals(1, serviceLocator.getDescriptors(new ParameterBeanFilter()).size());
// make another call
assertEquals("two", resource("/jaxrs?q=two").getEntity());
assertEquals(1, serviceLocator.getDescriptors(new ParameterBeanFilter()).size());
// and some more
for (int i = 0; i < 20; i++) {
assertEquals(Integer.toString(i), resource("/jaxrs?q=" + i).getEntity());
assertEquals(1, serviceLocator.getDescriptors(new ParameterBeanFilter()).size());
}
}
use of org.glassfish.hk2.api.Descriptor in project Payara by payara.
the class SJSASFactory method postConstruct.
@SuppressWarnings({ "unused", "unchecked" })
@PostConstruct
private void postConstruct() {
if (systemProcessor != null && systemProcessorMetaDataComplete != null)
return;
// initialize our system annotation processor...
systemProcessor = new AnnotationProcessorImpl();
systemProcessorMetaDataComplete = new AnnotationProcessorImpl();
for (ActiveDescriptor<?> i : locator.getDescriptors(BuilderHelper.createContractFilter(AnnotationHandler.class.getName()))) {
ActiveDescriptor<AnnotationHandler> descriptor = (ActiveDescriptor<AnnotationHandler>) i;
String annotationTypeName = getAnnotationHandlerForStringValue(descriptor);
if (annotationTypeName == null)
continue;
systemProcessor.pushAnnotationHandler(annotationTypeName, new LazyAnnotationHandler(descriptor));
annotationClassNames.add("L" + annotationTypeName.replace('.', '/') + ";");
// falling in this category in the future, add them to this list
if (annotationTypeName.equals("javax.annotation.ManagedBean")) {
systemProcessorMetaDataComplete.pushAnnotationHandler(annotationTypeName, new LazyAnnotationHandler(descriptor));
annotationClassNamesMetaDataComplete.add("L" + annotationTypeName.replace('.', '/') + ";");
}
}
}
use of org.glassfish.hk2.api.Descriptor in project Payara by payara.
the class WeldUtils method hasCDIEnablingAnnotations.
/**
* Determine whether there are any beans annotated with annotations that should enable CDI
* processing even in the absence of a beans.xml descriptor.
*
* @param context The DeploymentContext
* @param paths The paths to check for annotated beans
*
* @return true, if there is at least one bean annotated with a qualified annotation in the specified paths
*/
public static boolean hasCDIEnablingAnnotations(DeploymentContext context, Collection<URI> paths) {
List<String> result = new ArrayList<String>();
Types types = getTypes(context);
if (types != null) {
Iterator<Type> typesIter = types.getAllTypes().iterator();
while (typesIter.hasNext()) {
Type type = typesIter.next();
if (!(type instanceof AnnotationType)) {
Iterator<AnnotationModel> annotations = type.getAnnotations().iterator();
while (annotations.hasNext()) {
AnnotationModel am = annotations.next();
AnnotationType at = am.getType();
if (isCDIEnablingAnnotation(at) && type.wasDefinedIn(paths)) {
if (!result.contains(at.getName())) {
result.add(at.getName());
}
}
}
}
}
}
return !(result.isEmpty());
}
use of org.glassfish.hk2.api.Descriptor in project Payara by payara.
the class WeldUtils method getCDIAnnotatedClassNames.
/**
* Get the names of any classes that are annotated with bean-defining annotations, which should
* enable CDI processing even in the absence of a beans.xml descriptor.
*
* @param context The DeploymentContext
*
* @return A collection of class names; The collection could be empty if none are found.
*/
public static Collection<String> getCDIAnnotatedClassNames(DeploymentContext context) {
Set<String> result = new HashSet<String>();
Types types = getTypes(context);
if (types != null) {
Iterator<Type> typesIter = types.getAllTypes().iterator();
while (typesIter.hasNext()) {
Type type = typesIter.next();
if (!(type instanceof AnnotationType)) {
Iterator<AnnotationModel> annotations = type.getAnnotations().iterator();
while (annotations.hasNext()) {
AnnotationModel am = annotations.next();
AnnotationType at = am.getType();
if (isCDIEnablingAnnotation(at)) {
if (!result.contains(at.getName())) {
result.add(type.getName());
}
}
}
}
}
}
return result;
}
use of org.glassfish.hk2.api.Descriptor in project Payara by payara.
the class TransactionLifecycleService method postConstruct.
@Override
public void postConstruct() {
EventListener glassfishEventListener = new EventListener() {
@Override
public void event(Event event) {
if (event.is(EventTypes.SERVER_READY)) {
_logger.fine("TM LIFECYCLE SERVICE - ON READY");
onReady();
} else if (event.is(EventTypes.PREPARE_SHUTDOWN)) {
_logger.fine("TM LIFECYCLE SERVICE - ON SHUTDOWN");
onShutdown();
}
}
};
events.register(glassfishEventListener);
if (nm != null) {
try {
nm.publishObject(USER_TX_NO_JAVA_COMP, new NamingObjectProxy.InitializationNamingObjectProxy() {
@Override
public Object create(Context ic) throws NamingException {
ActiveDescriptor<?> descriptor = habitat.getBestDescriptor(BuilderHelper.createContractFilter("javax.transaction.UserTransaction"));
if (descriptor == null)
return null;
return habitat.getServiceHandle(descriptor).getService();
}
}, false);
} catch (NamingException e) {
_logger.warning("Can't bind \"UserTransaction\" in JNDI");
}
}
}
Aggregations