[jboss-dev-forums] [Design of AOP on JBoss (Aspects/JBoss)] - Re: AOP asintegration WITHOUT the integration :-)

kabir.khan@jboss.com do-not-reply at jboss.com
Tue Sep 18 13:59:01 EDT 2007


"adrian at jboss.org" wrote : 
  | It's not work in progress, at least not yet. 
  | I only added the deployments scope a week ago.
  | 
  | I'd suggest you try it yourself with a mock test, e.g. write an aspect
  | that pushes the metadata from the advisor onto the stack and test it using
  | the aop proxy where you can pass in the metadata.

I've created some simple tests on my machine emulating what I think will happen at deployer level.

  |    public void testDomain() throws Exception
  |    {
  |       URL url = null;
  |       Domain domain = null;
  |       try
  |       {
  |          //Create our instance to be proxied before we start deploying stuff
  |          TestIntercepted test = new TestIntercepted();
  |          
  |          //Deployer creates metadata and populates that with the necessary domain
  |          createAndPushMetaData(createScopedDomain("xxx"));
  |          
  |          //We get the domain out of the metadata and deploy into that
  |          MetaData md = MetaDataStack.peek();
  |          domain = md.getMetaData(Domain.class);
  |          assertNotNull(domain);
  |          url = deploy("1", Thread.currentThread().getContextClassLoader(), domain);
  |          
  |          //create the proxy, the scoped manger is taken from the metadata stack
  |          AOPProxyFactoryParameters params = new AOPProxyFactoryParameters();
  |          params.setTarget(test);
  |          params.setMetaData(md);
  |          
  |          AOPProxyFactory factory = new GeneratedAOPProxyFactory();
  |          TestIntercepted proxy = (TestIntercepted)factory.createAdvisedProxy(params);
  |          assertFalse(proxy.getClass() == TestIntercepted.class);
  |                   
  |          TestInterceptor.intercepted = null;
  |          proxy.doSomething();
  |          assertNotNull(TestInterceptor.intercepted);
  |          assertEquals("First", TestInterceptor.intercepted);
  |       }
  |       finally
  |       {
  |          if (MetaDataStack.peek() != null)
  |          {
  |             MetaDataStack.pop();
  |          }
  |          undeploy(url, domain);
  |       }
  |    }
  | 
  |    private ScopeKey createScope(String app, String dep)
  |    {
  |       ScopeKey result = ScopeKey.DEFAULT_SCOPE.clone();
  |       result.addScope(CommonLevels.APPLICATION, app);
  |       result.addScope(CommonLevels.DEPLOYMENT, dep);
  |       return result;
  |    }
  |    
  |    private void createAndPushMetaData(Domain scopedDomain)
  |    {
  |       //Deployer creates Domain depending on classloader rules, and adds it to metadata for deployment
  |       ScopeKey scopeKey = createScope("Test", scopedDomain.getDomainName());
  |       MutableMetaDataRepository repository = new BasicMetaDataRepository();
  |       MetaDataRetrieval retrieval = new MemoryMetaDataLoader(scopeKey);
  |       repository.addMetaDataRetrieval(retrieval);
  |       
  |       if (scopedDomain != null)
  |       {
  |          ((MutableMetaData)retrieval).addMetaData(scopedDomain, Domain.class);
  |       }
  |       MetaData metadata = repository.getMetaData(scopeKey);
  |       MetaDataStack.push(metadata);
  |    }
  |    
  |    private Domain createScopedDomain(String name)
  |    {
  |       AspectManager manager = AspectManager.getTopLevelAspectManager();
  |       Domain scopedDomain = new Domain(manager, name, false);
  |       return scopedDomain;
  |    }
  | 
  | 

I think I am missing a part in the metadata stuff. What I have pasted in above works fine for generating the proxies, but I don't see how this will work when doing weaving? What if there is no metadata on the stack? Or would that be a bug when running within JBoss. Alternatively, we would need something to map from the classloader passed in to AspectManager.translate() to the metadata, but that sounds suspiciously like a variation of what we have at the moment (classloader=>ScopedClassLoaderDomain)?

The second part of this is that the metadata is currently only really used at weaving/advisor population time. i.e we use the metadata to get the domain, and the annotations etc. to be used for the bindings etc. I think you have in mind something for the same class to have different interceptor chains invoked depending on the MetaData on the stack? 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4085664#4085664

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4085664



More information about the jboss-dev-forums mailing list