1. /*
  2. * @(#)file Timestamp.java
  3. * @(#)author Sun Microsystems, Inc.
  4. * @(#)version 1.4
  5. * @(#)date 04/09/15
  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. package com.sun.jmx.snmp;
  13. // java imports
  14. //
  15. import java.util.Date;
  16. /**
  17. * This class is used by the {@link com.sun.jmx.snmp.SnmpVarBindList SnmpVarBindList} object.
  18. * An <CODE>SnmpVarBindList</CODE> time stamp object represents the time stamp when the list was updated
  19. * with the response variables.
  20. * <p><b>This API is a Sun Microsystems internal API and is subject
  21. * to change without notice.</b></p>
  22. */
  23. public class Timestamp implements java.io.Serializable {
  24. // PRIVATE VARIABLES
  25. //------------------
  26. /**
  27. * The time (in hundreds of a second) since the network management portion of the system
  28. * was last re-initialized.
  29. */
  30. private long sysUpTime ;
  31. /**
  32. * A <CODE>long</CODE> representing the current date.
  33. */
  34. private long crtime ;
  35. /**
  36. * A <CODE>Date</CODE> object representing the current date.
  37. */
  38. private Date dateCache = null ;
  39. /**
  40. * The <CODE>SnmpTimeticks</CODE> object corresponding to the <CODE>TimeStamp</CODE> object.
  41. */
  42. private SnmpTimeticks uptimeCache = null ;
  43. // CONSTRUCTORS
  44. //-------------
  45. /**
  46. * The default constructor. <CODE>Sysuptime</CODE> is 0.
  47. * This simply indicates when this object was created.
  48. */
  49. public Timestamp() {
  50. crtime = System.currentTimeMillis() ;
  51. }
  52. /**
  53. * Creates a <CODE>TimeStamp</CODE> object using the user parameters.
  54. * @param uptime The time (in hundredths of a second) since the
  55. * network management portion of the system was last re-initialized.
  56. * @param when The current time.
  57. */
  58. public Timestamp(long uptime, long when) {
  59. sysUpTime = uptime ;
  60. crtime = when ;
  61. }
  62. /**
  63. * Creates a <CODE>TimeStamp</CODE> object using the user parameters.
  64. * @param uptime The time (in hundredths of a second) since the
  65. * network management portion of the system was last re-initialized.
  66. */
  67. public Timestamp(long uptime) {
  68. sysUpTime = uptime ;
  69. crtime = System.currentTimeMillis() ;
  70. }
  71. // GETTER/SETTER
  72. //--------------
  73. /**
  74. * Gets the <CODE>SnmpTimeticks</CODE> object corresponding to the <CODE>TimeStamp</CODE> object.
  75. * @return The <CODE>SnmpTimeticks</CODE> object.
  76. */
  77. final public synchronized SnmpTimeticks getTimeTicks() {
  78. if (uptimeCache == null)
  79. uptimeCache = new SnmpTimeticks((int)sysUpTime) ;
  80. return uptimeCache ;
  81. }
  82. /**
  83. * Gets the time (in hundredths of a second) since the network management portion of the system
  84. * was last re-initialized.
  85. * @return The <CODE>sysUpTime</CODE>.
  86. */
  87. final public long getSysUpTime() {
  88. return sysUpTime ;
  89. }
  90. /**
  91. * Gets the current date.
  92. * @return A <CODE>Date</CODE> object representing the current date.
  93. */
  94. final public synchronized Date getDate() {
  95. if (dateCache == null)
  96. dateCache = new Date(crtime) ;
  97. return dateCache ;
  98. }
  99. /**
  100. * Gets the current date.
  101. * @return A <CODE>long</CODE> representing the current date.
  102. */
  103. final public long getDateTime() {
  104. return crtime ;
  105. }
  106. /**
  107. * Returns a <CODE>String</CODE> representation of the <CODE>TimeStamp</CODE> object.
  108. * @return A <CODE>String</CODE> representation of the <CODE>TimeStamp</CODE> object.
  109. */
  110. final public String toString() {
  111. StringBuffer buf = new StringBuffer() ;
  112. buf.append("{SysUpTime = " + SnmpTimeticks.printTimeTicks(sysUpTime)) ;
  113. buf.append("} {Timestamp = " + getDate().toString() + "}") ;
  114. return buf.toString() ;
  115. }
  116. }