3 Replies Latest reply on Mar 15, 2007 1:59 PM by Clebert Suconic

    AspectFactory and classloading

    Ovidiu Feodorov Master

      I was wondering why GenericAspectFactory uses the thread context class loader by default to load aspect classes?

       public Class getClazz()
       {
       ....
       {
       clazz = Thread.currentThread().getContextClassLoader().loadClass(classname);
       }
       catch (ClassNotFoundException e)
       ....
       }
      


      This is causing me some trouble when I deploy an MDB that needs to use a scoped Messaging instance (and there can only be a scoped Messaging instance with JBoss 4.x), because the MDB deployment is done by a "ScannerThread" whose thread context class loader is a UCL associated with the main loader repository. This UCL cannot access scoped Messaging interceptor classes and the MDB deployment fails with ClassNotFoundException.

      I fixed this by temporarily replacing the ScannerThread's (and any thread's that touches the AOP stack during deployment) context class loader during deployment, but I don't like at all this solution since I don't know what else this may break due to lateral effects.

      How about allowing for a pluggable classloader to use for aspect loading?

      An AspectXmlLoader.deployXML(Document, URL, ClassLoader) method would help me. Does this make sense?

        • 1. Re: AspectFactory and classloading
          Clebert Suconic Master

          I tested using this method Ovidiu mentioned and it worked.. my scoping problem was fixed after using this.

          • 2. Re: AspectFactory and classloading
            Clebert Suconic Master

            I had a problem with this, when loading a perVM Aspect:

            java.lang.ExceptionInInitializerError
             at org.jboss.jms.server.endpoint.ServerConnectionFactoryEndpoint.createConnectionDelegateInternal(ServerConnectionFactoryEndpoint.java:238)
             at org.jboss.jms.server.endpoint.ServerConnectionFactoryEndpoint.createConnectionDelegate(ServerConnectionFactoryEndpoint.java:137)
             at org.jboss.jms.server.endpoint.advised.ConnectionFactoryAdvised.org$jboss$jms$server$endpoint$advised$ConnectionFactoryAdvised$createConnectionDelegate$aop(ConnectionFactoryAdvised.java:88)
             at org.jboss.jms.server.endpoint.advised.ConnectionFactoryAdvised.createConnectionDelegate(ConnectionFactoryAdvised.java)
             at org.jboss.jms.wireformat.ConnectionFactoryCreateConnectionDelegateRequest.serverInvoke(ConnectionFactoryCreateConnectionDelegateRequest.java:103)
             at org.jboss.jms.server.remoting.JMSServerInvocationHandler.invoke(JMSServerInvocationHandler.java:125)
             at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:734)
             at org.jboss.remoting.transport.local.LocalClientInvoker.invoke(LocalClientInvoker.java:101)
             at org.jboss.remoting.Client.invoke(Client.java:1513)
             at org.jboss.remoting.Client.invoke(Client.java:527)
             at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate.org$jboss$jms$client$delegate$ClientConnectionFactoryDelegate$createConnectionDelegate$aop(ClientConnectionFactoryDelegate.java:159)
             at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate$createConnectionDelegate_4579211046834694258.invokeNext(ClientConnectionFactoryDelegate$createConnectionDelegate_4579211046834694258.java)
             at org.jboss.jms.client.container.StateCreationAspect.handleCreateConnectionDelegate(StateCreationAspect.java:83)
             at org.jboss.aop.advice.org.jboss.jms.client.container.StateCreationAspect0.invoke(StateCreationAspect0.java)
             at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate$createConnectionDelegate_4579211046834694258.invokeNext(ClientConnectionFactoryDelegate$createConnectionDelegate_4579211046834694258.java)
             at org.jboss.jms.client.container.ExceptionInterceptor.invoke(ExceptionInterceptor.java:71)
             at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate$createConnectionDelegate_4579211046834694258.invokeNext(ClientConnectionFactoryDelegate$createConnectionDelegate_4579211046834694258.java)
             at org.jboss.jms.client.container.ClientLogInterceptor.invoke(ClientLogInterceptor.java:107)
             at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate$createConnectionDelegate_4579211046834694258.invokeNext(ClientConnectionFactoryDelegate$createConnectionDelegate_4579211046834694258.java)
             at org.jboss.jms.client.delegate.ClientConnectionFactoryDelegate.createConnectionDelegate(ClientConnectionFactoryDelegate.java)
             at org.jboss.jms.client.JBossConnectionFactory.createConnectionInternal(JBossConnectionFactory.java:205)
             at org.jboss.jms.client.JBossConnectionFactory.createQueueConnection(JBossConnectionFactory.java:101)
             at org.jboss.jms.client.JBossConnectionFactory.createQueueConnection(JBossConnectionFactory.java:95)
             at org.jboss.resource.adapter.jms.inflow.dlq.AbstractDLQHandler.setupDLQConnection(AbstractDLQHandler.java:137)
             at org.jboss.resource.adapter.jms.inflow.dlq.AbstractDLQHandler.setup(AbstractDLQHandler.java:83)
             at org.jboss.resource.adapter.jms.inflow.dlq.JBossMQDLQHandler.setup(JBossMQDLQHandler.java:48)
             at org.jboss.resource.adapter.jms.inflow.JmsActivation.setupDLQ(JmsActivation.java:359)
             at org.jboss.resource.adapter.jms.inflow.JmsActivation.setup(JmsActivation.java:305)
             at org.jboss.resource.adapter.jms.inflow.JmsActivation$SetupActivation.run(JmsActivation.java:589)
             at org.jboss.resource.work.WorkWrapper.execute(WorkWrapper.java:204)
             at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:275)
             at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:743)
             at java.lang.Thread.run(Thread.java:595)
            Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: No ClassLoaders found for: org.jboss.jms.server.container.ServerLogInterceptor
             at org.jboss.aop.advice.GenericAspectFactory.getClazz(GenericAspectFactory.java:141)
             at org.jboss.aop.advice.GenericAspectFactory.createPerVM(GenericAspectFactory.java:152)
             at org.jboss.aop.AspectManager.createPerVmAspect(AspectManager.java:1744)
             at org.jboss.aop.AspectManager.getPerVMAspect(AspectManager.java:1726)
             at org.jboss.aop.AspectManager.getPerVMAspect(AspectManager.java:1716)
             at org.jboss.aop.advice.ScopedInterceptorFactory.create(ScopedInterceptorFactory.java:66)
             at org.jboss.aop.Advisor.createInterceptorChain(Advisor.java:613)
             at org.jboss.aop.Advisor.pointcutResolved(Advisor.java:883)
             at org.jboss.aop.Advisor.resolveMethodPointcut(Advisor.java:645)
             at org.jboss.aop.ClassAdvisor.createInterceptorChains(ClassAdvisor.java:604)
             at org.jboss.aop.ClassAdvisor.access$300(ClassAdvisor.java:82)
             at org.jboss.aop.ClassAdvisor$1.run(ClassAdvisor.java:299)
             at java.security.AccessController.doPrivileged(Native Method)
             at org.jboss.aop.ClassAdvisor.attachClass(ClassAdvisor.java:271)
             at org.jboss.aop.AspectManager.initialiseClassAdvisor(AspectManager.java:590)
             at org.jboss.aop.AspectManager.getAdvisor(AspectManager.java:578)
             at org.jboss.jms.server.endpoint.advised.ConnectionAdvised.<clinit>(ConnectionAdvised.java)
             ... 33 more
            Caused by: java.lang.ClassNotFoundException: No ClassLoaders found for: org.jboss.jms.server.container.ServerLogInterceptor
             at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:212)
             at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:511)
             at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:405)
             at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
             at org.jboss.aop.advice.AspectFactoryWithClassLoaderSupport.loadClass(AspectFactoryWithClassLoaderSupport.java:80)
             at org.jboss.aop.advice.GenericAspectFactory.getClazz(GenericAspectFactory.java:137)
             ... 49 more
            


            • 3. Re: AspectFactory and classloading
              Clebert Suconic Master

              NM... I had another point where I was deploying ServerSide aspects.. just setting the classLoader fixed it.