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">&lt;<a href="mailto:[email protected]">[email protected]</a>&gt;</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&#39;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>
 &nbsp; &nbsp; &nbsp; &nbsp;private static final long TIME = 2500;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;private int count = 0;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;public static void main(String args[]){<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;new Server().start();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp;void start(){<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try{<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;Mock server running ...&quot;);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while(true){<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;new Thread().sleep(TIME);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;count();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;count:&quot;+count);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}catch(Exception e){<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;private void count(){<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;count++;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<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>
 &nbsp; &nbsp; &nbsp; &nbsp;public void beforeCount(JoinPoint jp){<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;before count ...&quot;);<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp;public void afterCount(JoinPoint jp){<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;after count ...&quot;);<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
}<br>
<br>
aop.xml content<br>
<br>
&lt;aspectwerkz&gt;<br>
&lt;system id=&quot;Mock Server&quot;&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;package name=&quot;aspect&quot;&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;aspect class=&quot;Observer&quot;&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;pointcut name=&quot;count&quot; expression=&quot;execution(*<br>
sys.Server.count(..))&quot;/&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;advice name=&quot;beforeCount&quot; type=&quot;before&quot;<br>
bind-to=&quot;count&quot;/&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;advice name=&quot;afterCount&quot; type=&quot;after&quot;<br>
bind-to=&quot;count&quot;/&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/aspect&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;/package&gt;<br>
&lt;/system&gt;<br>
&lt;/aspectwerkz&gt;<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>
 &nbsp; &nbsp;<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--