KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > alt > jiapi > util > HotSpotAdvice


1 package alt.jiapi.util;
2
3 /**
4  * HotSpotAdvice is an abstract base class for all of the advises
5  * used by HotSpotInstrumentor.<p>
6  *
7  * A HotSpotInstrumentor locates HotSpots according to its
8  * configuration. A HotSpot migh be an invocation, for example.
9  * Once hotspot is found <i>HotSpotInstrumentor</i> calls
10  * HotSpotAdvice.advice() method.<p>
11  *
12  * Body of the HotSpotAdvice.advice() is then copied into
13  * instrumented class.
14  */

15 public abstract class HotSpotAdvice {
16     /**
17      * Each extending class must provide advice() method.
18      * Body of this method is copied into instrumented
19      * class.<p>
20      * The exact location, where method body gets copied into,
21      * depends how developer writes the method body.<p>
22      *
23      * A call to doHotSpot() in method body, is a tagging method
24      * call indicating that current hotspot should be executed.<p>
25      *
26      * For example, of we have a method <i>foo()</i>...
27      * <pre>
28      * public void foo() {
29      * bar.doSomeThing();
30      * }
31      * </pre>
32      *
33      * ...and <i>HotSpotAdvisor.advice()</i>:
34      * <pre>
35      * public void advice() {
36      * long l1 = System.currentTimeMillis();
37      * doHotSpot();
38      * long l2 = System.currentTimeMillis();
39      * System.out.println("It took " + (l2-l1) + " ms");
40      * }
41      * </pre>
42      *
43      * ...then it would result in <i><b>instrumented</b> foo()</i> method like
44      * <pre>
45      * public void foo() {
46      * long l1 = System.currentTimeMillis();
47      * bar.doSomething();
48      * long l2 = System.currentTimeMillis();
49      * System.out.println("It took " + (l2-l1) + " ms");
50      * }
51      *
52      * If a developer does not call <i>doHotSpot()</i> method in
53      * implementation of advice() method, corresponding hotspot
54      * gets <i>replaced<i> from instrumented class.
55      *
56      * @see #doHotSpot()
57      */

58     public abstract void advice();
59
60     /**
61      * This method should be called from advice() method, when
62      * the actual processing of hotspot is wanted.
63      */

64     protected void doHotSpot() {
65     }
66
67     /**
68      * This method should be called only from advice() method.
69      * @return name of the HotSpot
70      */

71     protected String JavaDoc getHotSpotName() {
72         return null;
73     }
74
75     /**
76      * Can be implemented with HotSpot.getArgumentList()
77      * Things to consider:
78      * - makes no sense to call after doHotSpot();
79      * - can this be used to change args
80      */

81     //protected Object[] getArguments();
82

83     /**
84      * Can be implemented with HotSpot.getArgumentList()
85      * Things to consider:
86      * - makes no sense to call before doHotSpot();
87      * - can this be used to change retval
88      */

89     //protected Object getResult();
90

91
92     // Other possible trigger methods
93
// protected Object getInstrumentedObject() {
94
// return null;
95
// }
96

97     // protected Class getInstrumentedClass();
98
// protected Object getHotSpotObject();
99
}
100
Popular Tags