Re: AspectWerkz questions: hot deployment of advices

Jonas BonĂ©r <[email protected]> Sat, 12 Apr 2003 08:06:24 +0200
Newsgroups gmane.comp.java.aspectwerkz
Message-ID <[email protected]>
Hi Ray.

I'll try to answer your questions:

1. You can run it with the java command only, the aspectwerkz script is 
basically just a wrapper around the normal call to the JVM.
I think the easiest way to figure out exactly what you want to feed the 
java command with is remove the @ECHO OFF in the top of the script (if  
you are running it on windows, similar work on UNIX of course) and see 
what the actual command string looks like. Otherwise if you take a look 
at the script you should get a pretty good idea how it works.
You know that you have to feed the aspectwerkz script with the | 
-Daspectwerkz.definition.file=<path_to_definition_file> | command line 
option.
If you set the ASPECT_HOME variable correctly I then you should be able 
to run it from anywhere. (Otherwise there is a bug hiding).

2. Thanks for pointing this out. You a correct, the documentation only 
covers adding existing advices to a pointcut. But it is actually 
possible to add completely new ones. Then you have to register the new 
advice first. And since I have missed this in the API, it is not so 
straightforward as it should be, I will definitely make it easier in the 
future. Anyway this is what you have to do now (before you the new 
advice to the pointcut):

                Advice advice = new MyNewAdvice();
                advice.setDeploymentModel(deploymentModel);
                advice.setName(adviceName);
                advice.setAdviceClass(adviceClass);

                 // if your advice should be persistent
                if (isPersistent) {
                      advice.setMemoryStrategy(new 
PersistableAdviceMemoryStrategy(adviceName, adviceClass));

                    AspectWerkz.getAspect(adviceClass.getName()).
                            
createSetFieldPointcut(DirtyFieldCheckAdvice.PATTERN).
                            addPostAdvice(DirtyFieldCheckAdvice.NAME);

                    PersistenceManagerFactory.getFactory(
                        
PersistenceManagerFactory.getPersistenceManagerType()).
                            
createPersistenceManager()..register(advice.getName());
                }
                else {
                    advice.setMemoryStrategy(new 
TransientAdviceMemoryStrategy(adviceClass));
                }

                // register the advice
                AspectWerkz.register(advice.getName(), advice);

                // create an aspect for the advice as well, needed for 
internal use
                AspectWerkz.register(new Aspect(adviceClass.getName()));

I have not tested this code but it should work.

I hope it works out for you.

Sincerely, Jonas.

>Ray Grieselhuber wrote:
>

>I'm new to both AOP and AspectWerkz, but so far I like
>very much what I see. 
>
>Ok, here are my questions:
>
>1. 
>I'm trying to figure out the best way to use it in my
>development environment, which is Eclipse. As an
>example I created my class file, the advice, and the
>descriptor file in a directory called "a". 
>
>In order to run this code, are there command line
>parameters that I can just send to Java or do I have
>to use the AspectWerkz command. If I can just send it
>to the Java command, then what format should this
>command be?
>
>If running from the AspectWerkz command line is the
>only option, then it seems to be haning trouble
>finding the conf files. do I need to be running from
>the AspectWerkz directory?
>
>2. I was reading about Hot Deployment, and I
>originally got the impression that it could only be
>used to reorder advices, etc., not add new ones. But
>elsewhere, the documentation states that they can be
>added "hot". Can you eleborate on this?
>
>Also, using this approach, there doesn't seem to be a
>way to define the deployment model (jvm, perClass,
>etc.) Is this correct?
>
>Thanks for answering my very basic questions.
>
>Ray
>
>__________________________________________________
>Do you Yahoo!?
>Yahoo! Tax Center - File online, calculators, forms, and more
>http://tax.yahoo.com
>
>
>-------------------------------------------------------
>This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger 
>for complex code. Debugging C/C++ programs can leave you feeling lost and 
>disoriented. TotalView can help you find your way. Available on major UNIX 
>and Linux platforms. Try it free. www.etnus.com
>_______________________________________________
>aspectwerkz-developer mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/aspectwerkz-developer
>
>
>  
>




-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger 
for complex code. Debugging C/C++ programs can leave you feeling lost and 
disoriented. TotalView can help you find your way. Available on major UNIX 
and Linux platforms. Try it free. www.etnus.com