Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Runtime Configuration

> Is there any way to configure AspectJ to “enable/disable” aspects at runtime

> using an XML configuration file or something similar?

 
There are many ways to do something like that, depending on whether you
want to enable/disable on (pull) loading, first-use, or each-use; or (push) via
active runtime configuration (JMX...), etc.  Two dominant approaches:
 
(1) load-time weaving, disabled on launch
 
(2) a variety of run-time flags during advice execution or pointcut
evaluation.  Flags could be driven by a JMX bean, in the aspect
or otherwise.  Depends on binding time and locus.
 
e.g.,
 
aspect A {
   static final boolean RUN = Boolean.getBoolean("my.flag");
   before() : MyPointcuts.logging() && if(RUN) {
       System.out.println("here");
   }
 
   boolean run;
   public void setRun(boolean run) { // can access via JMX...
       this.run = run;
   }
 
   before() : MyPointcuts.tracing() && if(A.aspectOf().run) {
       System.out.println("there");
   }
 
   before(Target t) : MyPointcuts.tracing() && target(t) && if(t.run()) {
       System.out.println("everywhere");
   }
}
 
Using configuration splits the crosscutting specification between the aspect
and the configuration file, which re-scatters the code and reduces the utility of
the tool support.  That's why so far there's been no explicit mechanism in the
AspectJ language itself for doing this.
 
Wes
 
 
------------Original Message------------
From: "Jeff Kunkle" <jeff.kunkle@xxxxxxxxxxxxxxxx>
To: aspectj-users@xxxxxxxxxxx
Date: Mon, Jul-19-2004 12:21 PM
Subject: [aspectj-users] Runtime Configuration

Is there any way to configure AspectJ to “enable/disable” aspects at runtime using an XML configuration file or something similar?

 

Jeff


Back to the top