View Javadoc

1   /*
2    * Jour - java profiler and monitoring library
3    *
4    * Copyright (C) 2004 Jour team
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Library General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Library General Public License for more details.
15   *
16   * You should have received a copy of the GNU Library General Public
17   * License along with this library; if not, write to the
18   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19   * Boston, MA  02111-1307, USA.
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 }