Runtime weaving question

View: New views
2 Messages — Rating Filter:   Alert me  

Runtime weaving question

by neo anderson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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,

Re: Runtime weaving question

by Alexandre Vasseur :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

bin/aspectwerkz is actually loat time weaving
for runtime weaving ie swapping in/out aspects and joinpoints - see http://aspectwerkz.codehaus.org/dynamic_aop.html
(the trick is to declare a scope of possible future joinpoints)
Alex

On Sat, Oct 18, 2008 at 12:39 AM, neo anderson <javadeveloper999@...> wrote:

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