[aspectwerkz-user] Runtime weaving question

neo anderson <[email protected]> Fri, 17 Oct 2008 15:39:18 -0700 (PDT)
Newsgroups gmane.comp.java.aspectwerkz.user
Message-ID <[email protected]>
I've got runtime weaving worked now. However one question arises. How can I
inject the aspect code to a running process? 

For instance, I have a mock server as below:

package sys;

public class Server{
        private static final long TIME = 2500;
        private int count = 0;
        public static void main(String args[]){
                new Server().start();
        }
        void start(){
                try{
                        System.out.println("Mock server running ...");
                        while(true){
                                new Thread().sleep(TIME);
                                count();
                                System.out.println("count:"+count);
                        }
                }catch(Exception e){
                        e.printStackTrace();
                }
        }

        private void count(){
                count++;
        }
}
 
And my aspect is as below:

package aspect;

import org.codehaus.aspectwerkz.joinpoint.JoinPoint;

public class Observer{
        public void beforeCount(JoinPoint jp){
                System.out.println("before count ...");
        }
        public void afterCount(JoinPoint jp){
                System.out.println("after count ...");
        }
}

aop.xml content 

<aspectwerkz>
<system id="Mock Server">
        <package name="aspect">
                <aspect class="Observer">
                        <pointcut name="count" expression="execution(*
sys.Server.count(..))"/>
                        <advice name="beforeCount" type="before"
bind-to="count"/>
                        <advice name="afterCount" type="after"
bind-to="count"/>
                </aspect>
        </package>
</system>
</aspectwerkz>

Runtime weaving works, but the way to achieve it is by starting server with
aspect at the same time, like `$ASPECTWERKZ_HOME/bin/aspectwerkz
-Daspectwerkz.definition.file=aop.xml -cp target sys.Server`

My question thus is - how can I get my aspect (aspect/Observer.java)
executed after mock server (sys/Server.java) has been already running?

Many thanks,

-- 
View this message in context: http://www.nabble.com/Runtime-weaving-question-tp20042123p20042123.html
Sent from the AspectWerkz - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email