Hi,
I've been looking a bit more into AspectJ and in the
way aspects can be woven into the existing code.
There are two ways:
- load time weaving, where a Java Agent loaded into
the JVM at startup time applies the aspect during
classloading
- compile time weaving, where classes are modified
in a post-compilation step
Gabriel suggested to use load time weaving. I'm however
quite worried about the use of the agent.
Using an agent means passing the entire JVM a parameter
like:
–javaagent:<path-to>/aspectjweaver-<version>.jar
that will will perform the classes transformations.
What worries me is that the agent loading is global,
affects not only GeoServer but all of the other applications
deployed alongside GeoServer. The main issues are:
- cautious admin will may refuse to change the JVM
configuration and attach something that might actively
perform changes on loaded classes. However, if they
don't to it monitoring won't be enabled
- even if rarely used in practice, other applications
might be using AspectJ as well, and a different version
from us (older, newer)
Compile time weaving on the other side works at
build time and the webapp admin won't even know AspectJ.
The downside is that we have to apply aspects contained
into a plugin into the "main" jar. We cannot do so by
default.
However, it seems it's possible to generated a weaved
jar starting from a plain one using a maven plugin:
http://mojo.codehaus.org/aspectj-maven-plugin/weaveJars.html
If this works we could instruct the adminstrator to remove
the normal GeoServer main jar and install the woven
one in its place when adding the monitoring plugin,
and on uninstall, swap back the normal one (but never have
both in the classpath).
Development wise things might get a little hairy though,
as main is a basic dependency for... everything.
I guess development wise we could just run with load
time weaving instead?
Cheers
Andrea