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 java.net.InetAddress;
24 import java.net.UnknownHostException;
25 import java.text.SimpleDateFormat;
26 import java.util.Date;
27
28 import net.sf.jour.rt.RtProperties;
29
30 import org.apache.log4j.Logger;
31
32 /***
33 * Provide SystemInfo information.
34 *
35 * Dual role to be stored in log and to be able to access global SystemInfo
36 *
37 * Created on 05.12.2004
38 * Contributing Author(s):
39 *
40 * Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
41 * Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
42 *
43 * @author vlads
44 * @version $Revision: 1.1 $ ($Author: vlads $) $Date: 2004/12/06 17:11:48 $
45 */
46 public class SystemInfoEvent implements Event {
47
48 protected static final Logger log = Logger.getLogger(SystemInfoEvent.class);
49
50 /***
51 * Stable <code>serialVersionUID</code>.
52 */
53 private static final long serialVersionUID = 29132125L;
54
55 private static SystemInfoEvent instance = instance();
56
57 private long startTime;
58 private String runID;
59 private String hostID;
60 private String hostIP;
61 private String description;
62
63 public SystemInfoEvent() {
64 }
65
66 public static SystemInfoEvent instance() {
67 if (instance == null) {
68 instance = new SystemInfoEvent();
69 instance.getStartTime();
70 instance.getHostID();
71 instance.getRunID();
72 }
73 return instance;
74 }
75
76 boolean isStatic() {
77 return (this == instance);
78 }
79
80 public String getHostID() {
81 if ((this.hostID == null) && (this.isStatic())) {
82 try {
83 this.hostIP = InetAddress.getLocalHost().getHostAddress();
84 this.hostID = RtProperties.getInstance().getProperty("hostIP.map." + this.hostIP, this.hostIP);
85 } catch (UnknownHostException e) {
86 log.error("Error", e);
87 this.hostID = "host";
88 }
89 }
90 return this.hostID;
91 }
92
93 public String getRunID() {
94 if ((this.runID == null) && (this.isStatic())) {
95 SimpleDateFormat fmt = new SimpleDateFormat("DDD_HH_mm");
96 this.runID = getHostID() + "_" + fmt.format(new Date());
97 }
98 return this.runID;
99 }
100
101 /***
102 * @return Returns the System start Time in Millis.
103 */
104 public long getStartTime() {
105 if ((this.startTime == 0) && (this.isStatic())) {
106 this.startTime = System.currentTimeMillis();
107 }
108 return this.startTime;
109 }
110 }