KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > emn > info > eaop > Monitor


1 /* ----------------------------------------------------------------------------
2  * EAOP 1.0, 2002-12-19
3  * (c) 2002 Remi Douence, Mario Sudholt; OBASCO group; EMN/INRIA; France
4  * THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY WARRANTY
5   -------------------------------------------------------------------------- */

6
7 package fr.emn.info.eaop;
8
9 import fr.emn.info.eaop.aspect.*;
10 import fr.emn.info.eaop.event.*;
11
12 import java.util.*;
13 import java.lang.reflect.*;
14 import java.io.*;
15
16 /**
17  * Class implementing the monitor to be called when an event is
18  * generated by the program execution. In this case, the event is
19  * stored, and the tree of aspects is visited in order to resume the
20  * coroutining aspects.
21  *
22  * @author RD
23  * @version 1.0
24  */

25
26 public class Monitor {
27
28     /**
29      * The global monitor
30      */

31     public static Monitor monitor = new Monitor();
32
33     /**
34      * <code>aspects</code> references the tree of aspects to be woven.
35      * It can evolve at run-time.
36      */

37     public AspectS aspects;
38
39     /**
40      * Stack to store events for the implementation of aspects of aspects.
41      */

42     public Stack currentEvent = new Stack();
43
44     /**
45      * Stack to store path taken within aspect DAG.
46      */

47     public Stack path = new Stack();
48
49     public Monitor() {
50     /*
51     System.out.println("EAOP (Event-based Aspect-Oriented Programming)");
52     System.out.println(
53         "Version 1.0, 2002-12-19, Remi Douence, Mario Sudholt\n");
54     */

55     }
56
57
58     /**
59      * This method is called by the base program.
60      */

61     public synchronized Event trace(Event e) {
62     return this.traceRecursive(e);
63     }
64
65     /**
66      * This method is called by inserts of aspects to be woven
67      * when an event is generated (recursive calls
68      * (aka aspect of aspect) require a Stack)
69      */

70     public Event traceRecursive(Event e) {
71     this.currentEvent.push(e);
72     // start traversal of aspect tree
73
this.aspects.go();
74     // trace is an event transformer
75
Event result = (Event)(this.currentEvent.peek());
76     this.currentEvent.pop();
77     return result;
78     }
79
80     /**
81      * This method is called by aspects in order to access the current
82      * event.
83      */

84     public Event currentEvent() {
85     return (Event)(this.currentEvent.peek());
86     }
87 }
88
Popular Tags