FileDocCategorySizeDatePackage
AspectManagerService.javaAPI DocJBoss 4.2.116542Fri Jul 13 21:02:24 BST 2007org.jboss.aop.deployment

AspectManagerService

public class AspectManagerService extends org.jboss.system.ServiceMBeanSupport implements AspectManagerServiceMBean, org.jboss.aop.AspectNotificationHandler
author
Bill Burke
version
$Revision: 60554 $
jmx:mbean
extends="org.jboss.system.ServiceMBean"

Fields Summary
public static final ObjectName
DEFAULT_LOADER_REPOSITORY
boolean
created
protected File
tmpClassesDir
protected boolean
enableTransformer
protected boolean
enableLoadtimeWeaving
protected boolean
suppressTransformationErrors
protected boolean
suppressReferenceErrors
protected String
exclude
protected String
include
protected String
ignore
Constructors Summary
public AspectManagerService()


   // Static -------------------------------------------------------

   // Constructors -------------------------------------------------
    
   
   
Methods Summary
public java.lang.StringaspectDefinitions()
The temporary directory to which dyn class files are written

jmx:managed-operation

      Map factories = AspectManager.instance().getAspectDefinitions();
      Iterator it = factories.keySet().iterator();
      StringBuffer buffer = new StringBuffer("");
      while (it.hasNext())
      {
         buffer.append(it.next() + "<br>");
      }
      return buffer.toString();
   
public voidattachClass(java.lang.String classname)

      Notification msg = new Notification("AOP class attached", this, getNextNotificationSequenceNumber());
      msg.setUserData(classname);
      sendNotification(msg);
   
protected voidattachDeprecatedTranslator()

      log.warn("EnableTransformer has been deprecated, please use EnableLoadtimeWeaving.  See docs for more details");
      AspectManager mgr = AspectManager.instance();
      try
      {
         server.setAttribute(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);
      }
   
protected voidattachTranslator()

      JDK14TransformerManager.transformer = new JDK14Transformer()
      {
         public byte[] transform(ClassLoader loader, String classname, byte[] classBytes)
         {
            try
            {
               //Make sure that we use the correct classloader, in order to get the correct domain if it is a scoped loader
               return AspectManager.instance(loader).translate(classname, loader, classBytes);
            }
            catch (Exception e)
            {
               throw new RuntimeException("Error converting " + classname + " on " + loader, e);
            }
         }
      };
   
protected voidbaseAop()

      try
      {
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
         URL base = cl.getResource("base-aop.xml");
         AspectXmlLoader.deployXML(base);
      }
      catch (Exception ex)
      {
         ex.printStackTrace();
      }
   
public java.lang.Stringbindings()
The temporary directory to which dyn class files are written

jmx:managed-operation

      Map factories = AspectManager.instance().getBindings();
      Iterator it = factories.keySet().iterator();
      StringBuffer buffer = new StringBuffer("");
      while (it.hasNext())
      {
         buffer.append(it.next() + "<br>");
      }
      return buffer.toString();
   
protected org.jboss.aop.ClassLoaderValidationcreateClassLoaderValidation()

      return new JBossClassLoaderValidator();
   
protected javassist.scopedpool.ScopedClassPoolFactorycreateFactory()

      return new JBossClassPoolFactory(tmpClassesDir);
   
protected voidcreateService()

      // Set a default tmp classes dir to the jboss tmp dir/aopclasses
      if (tmpClassesDir == null)
      {
         String jbossTmpDir = System.getProperty(ServerConfig.SERVER_TEMP_DIR);
         if (jbossTmpDir == null)
            jbossTmpDir = System.getProperty("java.io.tmpdir");
         tmpClassesDir = new File(jbossTmpDir, "aopdynclasses");
      }
      // Validate the the tmp dir exists
      if (tmpClassesDir.exists() == false && tmpClassesDir.mkdirs() == false)
         throw new FileNotFoundException("Failed to create tmpClassesDir: " + tmpClassesDir.getAbsolutePath());
      AspectManager.setClassPoolFactory(createFactory());

      AspectManager.classLoaderValidator = createClassLoaderValidation();
      // Add the tmp classes dir to our UCL classpath

      Deployment.searchClasspath = false; // turn off dynamic finding of DDs
      AspectManager.suppressTransformationErrors = suppressTransformationErrors;
      if (enableTransformer && enableLoadtimeWeaving) throw new RuntimeException("Cannot set both EnableTransformer and EnableLoadtimeWeaving");
      if (enableTransformer)
      {
         attachDeprecatedTranslator();
      }
      if (enableLoadtimeWeaving)
      {
         attachTranslator();
      }
      created = true;
      AspectManager.notificationHandler = this;

      AspectManager.scopedCLHelper = new JBossScopedClassLoaderHelper();

      baseAop();
   
protected voiddetachDeprecatedTranslator()

      try
      {
         server.setAttribute(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);
      }
   
protected voiddetachTranslator()

      JDK14TransformerManager.transformer = null;
   
public booleangetEnableLoadtimeWeaving()

      return enableLoadtimeWeaving;
   
public booleangetEnableTransformer()
The temporary directory to which dyn class files are written

jmx:managed-attribute

      return enableTransformer;
   
public java.lang.StringgetExclude()

      return exclude;
   
public java.lang.StringgetIgnore()

      return ignore;
   
public java.lang.StringgetInclude()

      return include;
   
public java.lang.StringgetInstrumentor()

      return InstrumentorFactory.getInstrumentorName();
   
public booleangetOptimized()
Use aop optimizations. Optional just in case there is a bug

jmx:managed-attribute

      return AspectManager.optimize;
   
public booleangetPrune()

      return AspectManager.getPrune();
   
public booleangetSuppressReferenceErrors()

jmx:managed-attribute

      return suppressReferenceErrors;
   
public booleangetSuppressTransformationErrors()

jmx:managed-attribute

      return suppressTransformationErrors;
   
public java.io.FilegetTmpClassesDir()
The temporary directory to which dyn class files are written

jmx:managed-attribute

      return tmpClassesDir;
   
public booleangetVerbose()
Set the verbosity of aop logging. It doesn't use log4j

jmx:managed-attribute

      return AspectManager.verbose;
   
public java.lang.StringinterceptorFactories()
The temporary directory to which dyn class files are written

jmx:managed-operation

      Map factories = AspectManager.instance().getInterceptorFactories();
      Iterator it = factories.keySet().iterator();
      StringBuffer buffer = new StringBuffer("");
      while (it.hasNext())
      {
         buffer.append(it.next() + "<br>");
      }
      return buffer.toString();
   
public java.lang.Stringintroductions()

jmx:managed-operation

      Map factories = AspectManager.instance().getInterfaceIntroductions();
      Iterator it = factories.keySet().iterator();
      StringBuffer buffer = new StringBuffer("");
      while (it.hasNext())
      {
         buffer.append(it.next() + "<br>");
      }
      return buffer.toString();
   
public java.lang.StringregisteredClassLoaders()
The temporary directory to which dyn class files are written

jmx:managed-operation

      Map factories = AspectManager.instance().getRegisteredCLs();
      Iterator it = factories.keySet().iterator();
      StringBuffer buffer = new StringBuffer("");
      while (it.hasNext())
      {
         buffer.append(it.next() + "<br>");
      }
      return buffer.toString();
   
public voidsetEnableLoadtimeWeaving(boolean enableTransformer)
The temporary directory to which dyn class files are written

jmx:managed-attribute

      if (this.enableLoadtimeWeaving == enableTransformer) return;
      if (this.getState() == STARTED)
      {
         if (enableTransformer)
         {
            attachTranslator();
         }
         else
         {
            detachTranslator();
         }
      }
      this.enableLoadtimeWeaving = enableTransformer;
   
public voidsetEnableTransformer(boolean enableTransformer)
The temporary directory to which dyn class files are written

jmx:managed-attribute

      // Testsuite uses enableTransformer, we may be testing new loadtime features though.

      if (enableLoadtimeWeaving)
      {
         log.warn("enabledLoadtimeWeaving alread set");
         return;
      }
      if (this.enableTransformer == enableTransformer) return;
      if (this.getState() == STARTED)
      {
         if (enableTransformer)
         {
            attachDeprecatedTranslator();
         }
         else
         {
            detachDeprecatedTranslator();
         }
      }
      this.enableTransformer = enableTransformer;
   
public voidsetExclude(java.lang.String exclude)

      this.exclude = exclude;
      ArrayList list = new ArrayList();
      if (exclude != null)
      {
         StringTokenizer tokenizer = new StringTokenizer(exclude, ",");
         while (tokenizer.hasMoreTokens())
         {
            list.add(tokenizer.nextToken().trim());
         }
      }
      AspectManager.instance().setExclude(list);
   
public voidsetIgnore(java.lang.String ignore)

      this.ignore = ignore;
      ArrayList list = new ArrayList();
      if (ignore != null)
      {
         StringTokenizer tokenizer = new StringTokenizer(ignore, ",");
         while (tokenizer.hasMoreTokens())
         {
            list.add(tokenizer.nextToken().trim());
         }
      }
      AspectManager.instance().setIgnore(list);
   
public voidsetInclude(java.lang.String include)

      this.include = include;
      ArrayList list = new ArrayList();
      if (include != null)
      {
         StringTokenizer tokenizer = new StringTokenizer(include, ",");
         while (tokenizer.hasMoreTokens())
         {
            list.add(tokenizer.nextToken().trim());
         }
      }
      AspectManager.instance().setInclude(list);
   
public voidsetInstrumentor(java.lang.String instrumentor)

      InstrumentorFactory.initialise(instrumentor);
   
public voidsetOptimized(boolean verbose)
Use aop optimizations. Optional just in case there is a bug

jmx:managed-attribute

      AspectManager.optimize = verbose;
   
public voidsetPrune(boolean prune)

      AspectManager.setPrune(prune);
   
public voidsetSuppressReferenceErrors(boolean suppressReferenceErrors)

jmx:managed-attribute

      this.suppressReferenceErrors = suppressReferenceErrors;
      AspectManager.suppressReferenceErrors = suppressReferenceErrors;
   
public voidsetSuppressTransformationErrors(boolean suppressTransformationErrors)

jmx:managed-attribute

      this.suppressTransformationErrors = suppressTransformationErrors;
      AspectManager.suppressTransformationErrors = suppressTransformationErrors;
   
public voidsetTmpClassesDir(java.io.File tmpClassesDir)
The temporary directory to which dyn class files are written

jmx:managed-attribute

      this.tmpClassesDir = tmpClassesDir;
   
public voidsetVerbose(boolean verbose)
Set the verbosity of aop logging. It doesn't use log4j

jmx:managed-attribute

      AspectManager.verbose = verbose;
   
public java.lang.Stringstacks()
The temporary directory to which dyn class files are written

jmx:managed-operation

      Map factories = AspectManager.instance().getInterceptorStacks();
      Iterator it = factories.keySet().iterator();
      StringBuffer buffer = new StringBuffer("");
      while (it.hasNext())
      {
         buffer.append(it.next() + "<br>");
      }
      return buffer.toString();
   
protected voidstartService()

   
protected voidstopService()