Re: [aspectwerkz-user] Runtime weaving question
"Alexandre Vasseur" <[email protected]> Sat, 18 Oct 2008 10:33:33 +0200
| Newsgroups | gmane.comp.java.aspectwerkz.user |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_77317_10679322.1224318813263 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 <[email protected] > 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 > > > ------=_Part_77317_10679322.1224318813263 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline <div dir="ltr">bin/aspectwerkz is actually loat time weaving<br>for runtime weaving ie swapping in/out aspects and joinpoints - see <a href="http://aspectwerkz.codehaus.org/dynamic_aop.html">http://aspectwerkz.codehaus.org/dynamic_aop.html</a><br> (the trick is to declare a scope of possible future joinpoints)<br>Alex<br><br><div class="gmail_quote">On Sat, Oct 18, 2008 at 12:39 AM, neo anderson <span dir="ltr"><<a href="mailto:[email protected]">[email protected]</a>></span> wrote:<br> <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br> I've got runtime weaving worked now. However one question arises. How can I<br> inject the aspect code to a running process?<br> <br> For instance, I have a mock server as below:<br> <br> package sys;<br> <br> public class Server{<br> private static final long TIME = 2500;<br> private int count = 0;<br> public static void main(String args[]){<br> new Server().start();<br> }<br> void start(){<br> try{<br> System.out.println("Mock server running ...");<br> while(true){<br> new Thread().sleep(TIME);<br> count();<br> System.out.println("count:"+count);<br> }<br> }catch(Exception e){<br> e.printStackTrace();<br> }<br> }<br> <br> private void count(){<br> count++;<br> }<br> }<br> <br> And my aspect is as below:<br> <br> package aspect;<br> <br> import org.codehaus.aspectwerkz.joinpoint.JoinPoint;<br> <br> public class Observer{<br> public void beforeCount(JoinPoint jp){<br> System.out.println("before count ...");<br> }<br> public void afterCount(JoinPoint jp){<br> System.out.println("after count ...");<br> }<br> }<br> <br> aop.xml content<br> <br> <aspectwerkz><br> <system id="Mock Server"><br> <package name="aspect"><br> <aspect class="Observer"><br> <pointcut name="count" expression="execution(*<br> sys.Server.count(..))"/><br> <advice name="beforeCount" type="before"<br> bind-to="count"/><br> <advice name="afterCount" type="after"<br> bind-to="count"/><br> </aspect><br> </package><br> </system><br> </aspectwerkz><br> <br> Runtime weaving works, but the way to achieve it is by starting server with<br> aspect at the same time, like `$ASPECTWERKZ_HOME/bin/aspectwerkz<br> -Daspectwerkz.definition.file=aop.xml -cp target sys.Server`<br> <br> My question thus is - how can I get my aspect (aspect/Observer.java)<br> executed after mock server (sys/Server.java) has been already running?<br> <br> Many thanks,<br> <br> --<br> View this message in context: <a href="http://www.nabble.com/Runtime-weaving-question-tp20042123p20042123.html" target="_blank">http://www.nabble.com/Runtime-weaving-question-tp20042123p20042123.html</a><br> Sent from the AspectWerkz - User mailing list archive at Nabble.com.<br> <br> <br> ---------------------------------------------------------------------<br> To unsubscribe from this list, please visit:<br> <br> <a href="http://xircles.codehaus.org/manage_email" target="_blank">http://xircles.codehaus.org/manage_email</a><br> <br> <br> </blockquote></div><br></div> ------=_Part_77317_10679322.1224318813263--