[jboss-dev-forums] [Design of AOP on JBoss (Aspects/JBoss)] - Re: AOP ClassLoader/Scoping for the VFSClassLoader
adrian@jboss.org
do-not-reply at jboss.com
Wed Jul 18 11:59:47 EDT 2007
Looks like there is lot more work to this.
The original refactoring just dealt with the aop project (AspectManager).
There's also a lot of deep integration in the asintegration project (AspectManagerService).
I've manged to come up with an alternate integration interface that encapsulates all this:
| package org.jboss.aop.deployment;
|
| import java.io.File;
|
| import javassist.scopedpool.ScopedClassPoolFactory;
|
| import org.jboss.aop.ClassLoaderValidation;
| import org.jboss.aop.classpool.AOPClassLoaderScopingPolicy;
|
| /**
| * AOPIntegration.<p>
| *
| * This class is intended to identify all the integration
| * points AOP is making with the JBoss appserver.
| *
| * @author <a href="adrian at jboss.com">Adrian Brock</a>
| * @version $Revision: 1.1 $
| */
| public interface JBossIntegration extends ClassLoaderValidation, ScopedClassPoolFactory
| {
| /**
| * Create the AOPClassLoaderScopingPolicy
| *
| * @return the policy
| */
| AOPClassLoaderScopingPolicy createAOPClassLoaderScopingPolicy();
|
| /**
| * Create a scoped classpool factory
| *
| * TODO JBAOP-??? need to review whether ScopedClassPool should also be replaced with
| * some other policy, e.g. javassist ClassPath notion is closer to new classloader?
| * @param tmpDir the temporary directory for classes
| * @return the factory
| * @throws Exception for any error
| */
| ScopedClassPoolFactory createScopedClassPoolFactory(File tmpDir) throws Exception;
|
| /**
| * Attach the depreacted translator
| */
| void attachDeprecatedTranslator();
|
| /**
| * Detach the deprecated translator
| */
| void detachDeprecatedTranslator();
| }
|
And an implementation for the old stuff
| package org.jboss.aop.deployment;
|
| import java.io.File;
|
| import javax.management.Attribute;
| import javax.management.AttributeNotFoundException;
| import javax.management.InstanceNotFoundException;
| import javax.management.InvalidAttributeValueException;
| import javax.management.MBeanException;
| import javax.management.MBeanServer;
| import javax.management.ReflectionException;
|
| import javassist.ClassPool;
| import javassist.scopedpool.ScopedClassPool;
| import javassist.scopedpool.ScopedClassPoolFactory;
| import javassist.scopedpool.ScopedClassPoolRepository;
|
| import org.jboss.aop.AspectManager;
| import org.jboss.aop.classpool.AOPClassLoaderScopingPolicy;
| import org.jboss.aop.classpool.AOPScopedClassLoaderHelper;
| import org.jboss.aop.classpool.AOPScopedClassLoaderHelperBridge;
| import org.jboss.mx.loading.RepositoryClassLoader;
| import org.jboss.mx.util.MBeanServerLocator;
|
| /**
| * JBoss4Integration.<p>
| *
| * This class and its associated classes are
| * for the old JBoss4 integration with the LoaderRepository<p>
| *
| * <ul>Related Classes:
| * <li> {@link JBossClassPool}
| * <li> {@link JBossClassPoolFactory}
| * <li> {@link JBossScopedClassLoaderHelper}
| * <li> {@link LoaderRepositoryUrlUtil}
| * <li> {@link ScopedClassLoaderDomain}
| * <li> {@link ScopedJBossClassPool}
| * </ul>
| *
| * @deprecated TODO JBAOP-??? need to write a JBoss5 version
| * @author <a href="adrian at jboss.com">Adrian Brock</a>
| * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
| * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
| * @version $Revision: 1.1 $
| */
| @Deprecated
| public class JBoss4Integration implements JBossIntegration
| {
| /** The delegate classpool factory */
| private ScopedClassPoolFactory delegateClassPoolFactory;
|
| public boolean isValidClassLoader(ClassLoader loader)
| {
| if (!(loader instanceof RepositoryClassLoader)) return false;
| return ((RepositoryClassLoader) loader).getLoaderRepository() != null;
| }
|
| public AOPClassLoaderScopingPolicy createAOPClassLoaderScopingPolicy()
| {
| AOPScopedClassLoaderHelper helper = new JBossScopedClassLoaderHelper();
| return new AOPScopedClassLoaderHelperBridge(helper);
| }
|
| public ScopedClassPoolFactory createScopedClassPoolFactory(File tmpDir) throws Exception
| {
| delegateClassPoolFactory = new JBossClassPoolFactory(tmpDir);
| return this;
| }
|
| public ScopedClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
| {
| return delegateClassPoolFactory.create(cl, src, repository);
| }
|
| public ScopedClassPool create(ClassPool src, ScopedClassPoolRepository repository)
| {
| return delegateClassPoolFactory.create(src, repository);
| }
|
| public void attachDeprecatedTranslator()
| {
| AspectManager mgr = AspectManager.instance();
| MBeanServer server = MBeanServerLocator.locateJBoss();
| try
| {
| server.setAttribute(AspectManagerService.DEFAULT_LOADER_REPOSITORY, new Attribute("Translator", mgr));
| }
| catch (InstanceNotFoundException e)
| {
| throw new RuntimeException(e);
| }
| catch (AttributeNotFoundException e)
| {
| throw new RuntimeException(e);
| }
| catch (InvalidAttributeValueException e)
| {
| throw new RuntimeException(e);
| }
| catch (MBeanException e)
| {
| throw new RuntimeException(e);
| }
| catch (ReflectionException e)
| {
| throw new RuntimeException(e);
| }
| }
|
| public void detachDeprecatedTranslator()
| {
| MBeanServer server = MBeanServerLocator.locateJBoss();
| try
| {
| server.setAttribute(AspectManagerService.DEFAULT_LOADER_REPOSITORY, new Attribute("Translator", null));
| }
| catch (InstanceNotFoundException e)
| {
| throw new RuntimeException(e);
| }
| catch (AttributeNotFoundException e)
| {
| throw new RuntimeException(e);
| }
| catch (InvalidAttributeValueException e)
| {
| throw new RuntimeException(e);
| }
| catch (MBeanException e)
| {
| throw new RuntimeException(e);
| }
| catch (ReflectionException e)
| {
| throw new RuntimeException(e);
| }
| }
|
This is just an FYI warning, since I've committed it yet (not tested it).
The main work will be in writing a JBoss5 version that uses the new
jboss-classloading-spi instead so it can work with both the
RepositoryClassLoader and the VFSClassLoader.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4065456#4065456
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4065456
More information about the jboss-dev-forums
mailing list