KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > snmp > Timestamp


1 /*
2  * @(#)file Timestamp.java
3  * @(#)author Sun Microsystems, Inc.
4  * @(#)version 1.4
5  * @(#)date 08/02/09
6  *
7  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
8  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
9  *
10  */

11 // Copyright (c) 1995-96 by Cisco Systems, Inc.
12

13 package com.sun.jmx.snmp;
14
15 // java imports
16
//
17
import java.util.Date JavaDoc;
18
19 /**
20  * This class is used by the {@link com.sun.jmx.snmp.SnmpVarBindList SnmpVarBindList} object.
21  * An <CODE>SnmpVarBindList</CODE> time stamp object represents the time stamp when the list was updated
22  * with the response variables.
23  * <p><b>This API is a Sun Microsystems internal API and is subject
24  * to change without notice.</b></p>
25  */

26
27 public class Timestamp implements java.io.Serializable JavaDoc {
28
29     
30     // PRIVATE VARIABLES
31
//------------------
32

33     /**
34      * The time (in hundreds of a second) since the network management portion of the system
35      * was last re-initialized.
36      */

37     private long sysUpTime ;
38     
39     /**
40      * A <CODE>long</CODE> representing the current date.
41      */

42     private long crtime ;
43     
44     /**
45      * A <CODE>Date</CODE> object representing the current date.
46      */

47     private Date JavaDoc dateCache = null ;
48     
49     /**
50      * The <CODE>SnmpTimeticks</CODE> object corresponding to the <CODE>TimeStamp</CODE> object.
51      */

52     private SnmpTimeticks uptimeCache = null ;
53     
54     
55     // CONSTRUCTORS
56
//-------------
57

58     /**
59      * The default constructor. <CODE>Sysuptime</CODE> is 0.
60      * This simply indicates when this object was created.
61      */

62     public Timestamp() {
63         crtime = System.currentTimeMillis() ;
64     }
65
66     /**
67      * Creates a <CODE>TimeStamp</CODE> object using the user parameters.
68      * @param uptime The time (in hundredths of a second) since the
69      * network management portion of the system was last re-initialized.
70      * @param when The current time.
71      */

72     public Timestamp(long uptime, long when) {
73         sysUpTime = uptime ;
74         crtime = when ;
75     }
76
77     /**
78      * Creates a <CODE>TimeStamp</CODE> object using the user parameters.
79      * @param uptime The time (in hundredths of a second) since the
80      * network management portion of the system was last re-initialized.
81      */

82     public Timestamp(long uptime) {
83         sysUpTime = uptime ;
84         crtime = System.currentTimeMillis() ;
85     }
86     
87     
88     // GETTER/SETTER
89
//--------------
90

91     /**
92      * Gets the <CODE>SnmpTimeticks</CODE> object corresponding to the <CODE>TimeStamp</CODE> object.
93      * @return The <CODE>SnmpTimeticks</CODE> object.
94      */

95     final public synchronized SnmpTimeticks getTimeTicks() {
96         if (uptimeCache == null)
97             uptimeCache = new SnmpTimeticks((int)sysUpTime) ;
98         return uptimeCache ;
99     }
100
101     /**
102      * Gets the time (in hundredths of a second) since the network management portion of the system
103      * was last re-initialized.
104      * @return The <CODE>sysUpTime</CODE>.
105      */

106     final public long getSysUpTime() {
107         return sysUpTime ;
108     }
109
110     /**
111      * Gets the current date.
112      * @return A <CODE>Date</CODE> object representing the current date.
113      */

114     final public synchronized Date JavaDoc getDate() {
115         if (dateCache == null)
116             dateCache = new Date JavaDoc(crtime) ;
117         return dateCache ;
118     }
119
120     /**
121      * Gets the current date.
122      * @return A <CODE>long</CODE> representing the current date.
123      */

124     final public long getDateTime() {
125         return crtime ;
126     }
127
128     /**
129      * Returns a <CODE>String</CODE> representation of the <CODE>TimeStamp</CODE> object.
130      * @return A <CODE>String</CODE> representation of the <CODE>TimeStamp</CODE> object.
131      */

132     final public String JavaDoc toString() {
133         StringBuffer JavaDoc buf = new StringBuffer JavaDoc() ;
134         buf.append("{SysUpTime = " + SnmpTimeticks.printTimeTicks(sysUpTime)) ;
135         buf.append("} {Timestamp = " + getDate().toString() + "}") ;
136         return buf.toString() ;
137     }
138 }
139
Popular Tags