1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.jour.rt.agent;
22
23 import org.apache.log4j.Logger;
24
25 import net.sf.jour.util.PropertiesBase;
26 import net.sf.jour.rt.swingmonitor.SwingMonitor;
27 import net.sf.jour.rt.RtProperties;
28 import net.sf.jour.util.FileUtil;
29
30 /***
31 * TODO Add docs
32 * Created on 05.12.2004
33 *
34 * Contributing Author(s):
35 *
36 * Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
37 * Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
38 *
39 * @author vlads
40 * @version $Revision: 1.9 $ ($Author: vlads $) $Date: 2004/12/16 05:35:51 $
41 */
42 public class Monitor {
43
44 protected static final Logger log = Logger.getLogger(Monitor.class);
45
46 private static SwingMonitor monitor;
47 private static Monitor instance;
48 private static BulkEventJMSConsumer jmsConsumer;
49
50 private Monitor(boolean runtime) {
51 if (runtime) {
52 startRuntime();
53 }
54 }
55
56 public static Monitor getInstance() {
57 if (instance == null) {
58 instance = new Monitor(true);
59 }
60 return instance;
61 }
62
63 private void loadInstrumentationMap() {
64 String mapFile = RtProperties.getInstance().getProperty("imap");
65 InstrumentationMap map = InstrumentationMap.instance();
66 if (mapFile != null) {
67 map.load(FileUtil.getFile(mapFile));
68 }
69 }
70
71 private void startRuntime() {
72 try {
73
74 loadInstrumentationMap();
75
76 if (RtProperties.getInstance().getProperty("swingMonitor", false)) {
77 monitor = new SwingMonitor(null, true);
78 }
79
80 log.info("Jour Started");
81 log.info("Elog.ON=" + Elog.ON);
82 log.info("java.class.path = " + System.getProperty("java.class.path"));
83
84 } catch (NoClassDefFoundError e) {
85 e.printStackTrace();
86 } catch (RuntimeException e) {
87 e.printStackTrace();
88 }
89 }
90
91 public static void reset() {
92 BulkEventFileReader.reset();
93 }
94
95 private void runMonitor() {
96 loadInstrumentationMap();
97
98 String title = "Monitor";
99
100 if (RtProperties.getInstance().getProperty("BulkEventFileReader", false)) {
101 BulkEventFileReader.start();
102 title = "File " + title;
103 }
104
105 if (RtProperties.getInstance().getProperty("BulkEventJMSConsumer", false)) {
106 jmsConsumer = BulkEventJMSConsumer.start();
107 title = "JMS " + title;
108 }
109
110 monitor = new SwingMonitor(title, false);
111
112 log.info("java.class.path = " + System.getProperty("java.class.path"));
113 }
114
115 public static void main(String[] args) {
116 if (args.length < 0) {
117 System.out.println("Usage: net.sf.jour.rt.agent.Monitor "
118 + " \n"
119 + " "
120 + " ");
121 System.exit(1);
122 }
123
124 try {
125 RtProperties.getInstance().loadArgs(args);
126
127 instance = new Monitor(false);
128 instance.runMonitor();
129
130 } catch (Exception e) {
131 e.printStackTrace();
132 System.exit(1);
133 }
134 }
135
136 }