[Design the new POJO MicroContainer] - Annotations scanning part 2
by alesj
I'm slowly adding more and more tests to this (resolved) issue:
- http://www.jboss.com/index.html?module=bb&op=viewtopic&t=134098
I've added a deployer that knows how to scan newly added @Bean and @BeanFactory annotations - corresponding to MC beans and beanfactories.
The code that does this is pretty simple:
| public void deploy(DeploymentUnit unit, AnnotationEnvironment env) throws DeploymentException
| {
| Set<Class<?>> beans = env.classIsAnnotatedWith(Bean.class);
|
then you can do what ever you like with that information. ;-)
This is what I do in my case (create new BeanMetaData if it doesn't exist yet):
| for (Class<?> beanClass : beans)
| {
| Bean bean = beanClass.getAnnotation(Bean.class);
| String name = bean.name();
| if (name == null)
| throw new IllegalArgumentException("Null bean name: " + beanClass);
|
| DeploymentUnit component = components.get(name);
| BeanMetaData bmd = null;
| if (component != null)
| bmd = component.getAttachment(BeanMetaData.class);
|
| if (bmd == null)
| {
| BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(name, beanClass.getName());
| String[] aliases = bean.aliases();
| if (aliases != null && aliases.length > 0)
| builder.setAliases(new HashSet<Object>(Arrays.asList(aliases)));
| builder.setMode(bean.mode())
| .setAccessMode(bean.accessMode())
| .setAutowireType(bean.autowireType())
| .setErrorHandlingMode(bean.errorHandlingMode())
| .setAutowireCandidate(bean.autowireCandidate());
|
| addBeanComponent(unit, builder.getBeanMetaData());
| }
|
For all those who missed recent annotations scanning work, this is the class that should be of interest - AnnotationEnvironment - simply pull it out from the right DeploymentUnit as attachment:
| /**
| * Information holder about annotation processing.
| *
| * @author <a href="mailto:ales.justin@jboss.com">Ales Justin</a>
| */
| public interface AnnotationEnvironment
| {
| /**
| * Get all classes annotated with annotation param.
| *
| * @param annotation the annotation we're querying for
| * @return set of matching classes
| */
| Set<Class<?>> classIsAnnotatedWith(Class<? extends Annotation> annotation);
|
| /**
| * Get all classes who have some constructor annotated with annotation param.
| *
| * @param annotation the annotation we're querying for
| * @return set of matching classes
| */
| <A extends Annotation> Set<Element<A, Constructor>> classHasConstructorAnnotatedWith(Class<A> annotation);
|
| /**
| * Get all classes who have some field annotated with annotation param.
| *
| * @param annotation the annotation we're querying for
| * @return set of matching classes
| */
| <A extends Annotation> Set<Element<A, Field>> classHasFieldAnnotatedWith(Class<A> annotation);
|
| /**
| * Get all classes who have some method annotated with annotation param.
| *
| * @param annotation the annotation we're querying for
| * @return set of matching classes
| */
| <A extends Annotation> Set<Element<A, Method>> classHasMethodAnnotatedWith(Class<A> annotation);
|
| /**
| * Get all classes who have some method's/constructor's parameter annotated with annotation param.
| *
| * @param annotation the annotation we're querying for
| * @return set of matching classes
| */
| <A extends Annotation> Set<Element<A, AccessibleObject>> classHasParameterAnnotatedWith(Class<A> annotation);
| }
|
The code handles class loading lazily (Javassist + keeping weak ref to classloader from unit), meaning class won't get loaded until you actually need the information, e.g. AOP could modify it before.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4151776#4151776
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4151776
17 years, 10 months
[Design of JBoss Profiler] - Re: JBoss Profiler 2
by scolombara00
Hi All,
I'm having problem starting jboss with profiler enabled. I've followed the readme instruction, but something is going wrong:
===============================================================================
JBoss Bootstrap Environment
JBOSS_HOME: C:\jboss-4.2.1.GA
JAVA: C:\Programmi\Java\jdk1.5.0_11\bin\java
JAVA_OPTS: -javaagent:jboss-profiler.jar -Djboss-profiler.properties=jboss-profiler.properties -Djava.library.path="C:
\jboss-4.2.1.GA\bin\native;....
===============================================================================
JBoss Profiler 2.0.Beta1 (Sun Microsystems Inc. 1.5.0_11)
Failed to initalize plugin: org.jboss.logging.Log4jLoggerPlugin@133796
Failed to initalize plugin: org.jboss.logging.Log4jLoggerPlugin@8a0d5d
Failed to initalize plugin: org.jboss.logging.Log4jLoggerPlugin@13caecd
Failed to initalize plugin: org.jboss.logging.Log4jLoggerPlugin@f84386
Failed to initalize plugin: org.jboss.logging.Log4jLoggerPlugin@1194a4e
Failed to initalize plugin: org.jboss.logging.Log4jLoggerPlugin@19dfbff
Failed to initalize plugin: org.jboss.logging.Log4jLoggerPlugin@750159
Failed to initalize plugin: org.jboss.logging.Log4jLoggerPlugin@1c39a2d
Failed to initalize plugin: org.jboss.logging.Log4jLoggerPlugin@1e97676
Failed to initalize plugin: org.jboss.logging.Log4jLoggerPlugin@60420f
.. .. .. ..
Failed to initalize plugin: org.jboss.logging.Log4jLoggerPlugin@19c0bd6
Failed to boot JBoss:
org.jboss.deployment.DeploymentException: - nested throwable: (java.lang.reflect.UndeclaredThrowableException)
at org.jboss.system.ServiceConfigurator.install(ServiceConfigurator.java:196)
at org.jboss.system.ServiceController.install(ServiceController.java:226)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy4.install(Unknown Source)
at org.jboss.deployment.SARDeployer.create(SARDeployer.java:249)
at org.jboss.deployment.MainDeployer.create(MainDeployer.java:969)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:818)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:766)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy5.deploy(Unknown Source)
at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:482)
at org.jboss.system.server.ServerImpl.start(ServerImpl.java:362)
at org.jboss.Main.boot(Main.java:200)
at org.jboss.Main$1.run(Main.java:508)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.reflect.UndeclaredThrowableException
at org.jboss.system.ServiceCreator.install(ServiceCreator.java:236)
at org.jboss.system.ServiceConfigurator.internalInstall(ServiceConfigurator.java:449)
at org.jboss.system.ServiceConfigurator.install(ServiceConfigurator.java:171)
... 36 more
Caused by: java.lang.NoClassDefFoundError: org/jboss/mx/util/JBossNotificationBroadcasterSupport
at org.jboss.remoting.network.NetworkRegistry.(NetworkRegistry.java:55)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at org.jboss.mx.server.MBeanServerImpl.instantiate(MBeanServerImpl.java:1233)
at org.jboss.mx.server.MBeanServerImpl.instantiate(MBeanServerImpl.java:286)
at org.jboss.mx.server.MBeanServerImpl.createMBean(MBeanServerImpl.java:344)
at org.jboss.system.ServiceCreator.install(ServiceCreator.java:157)
... 38 more
Shutdown complete
Halting VM
Any help ?
thanks, simone.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4151757#4151757
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4151757
17 years, 10 months