KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > proceedinnewthread > TestAspect


1 /**************************************************************************************
2  * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the LGPL license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

8 package test.proceedinnewthread;
9
10 import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
11
12 /**
13  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
14  */

15 public class TestAspect {
16
17     public Object JavaDoc advice1(final JoinPoint jp) throws Throwable JavaDoc {
18         Thread JavaDoc t = new Thread JavaDoc(
19                 new Runnable JavaDoc() {
20                     public void run() {
21                         try {
22                             ProceedTest.LOG += "advice1Pre ";
23                             jp.proceed();
24                             ProceedTest.LOG += "advice1Post ";
25                         } catch (Throwable JavaDoc e) {
26                             throw new RuntimeException JavaDoc(e.toString());
27                         }
28                     }
29                 }
30         );
31         // Note: in 2.0, it happens that the context switch does not occurs and the test case reach the assertion
32
// before the new thread updates the test data LOG. We force priority just in case
33
// but it may still corrupt the test case.
34
t.setPriority(Thread.MAX_PRIORITY);
35         t.start();
36         return null;
37     }
38
39     public Object JavaDoc advice2(final JoinPoint jp) throws Throwable JavaDoc {
40         ProceedTest.LOG += "advice2Pre ";
41         jp.proceed();
42         ProceedTest.LOG += "advice2Post ";
43         return null;
44     }
45
46     public Object JavaDoc advice3(final JoinPoint jp) throws Throwable JavaDoc {
47         ProceedTest.LOG += "advice3Pre ";
48         jp.proceed();
49         ProceedTest.LOG += "advice3Post ";
50         return null;
51     }
52 }
53
Popular Tags