/*
*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
// Copyright (c) 1995-96 by Cisco Systems, Inc.
package com.sun.jmx.snmp;
// java imports
//
import java.util.Date;
/**
* This class is used by the {@link com.sun.jmx.snmp.SnmpVarBindList SnmpVarBindList} object.
* An SnmpVarBindList
time stamp object represents the time stamp when the list was updated
* with the response variables.
*
This API is a Sun Microsystems internal API and is subject * to change without notice.
*/ public class Timestamp implements java.io.Serializable { private static final long serialVersionUID = -242456119149401823L; // PRIVATE VARIABLES //------------------ /** * The time (in hundreds of a second) since the network management portion of the system * was last re-initialized. */ private long sysUpTime ; /** * Along
representing the current date.
*/
private long crtime ;
/**
* A Date
object representing the current date.
*/
private Date dateCache = null ;
/**
* The SnmpTimeticks
object corresponding to the TimeStamp
object.
*/
private SnmpTimeticks uptimeCache = null ;
// CONSTRUCTORS
//-------------
/**
* The default constructor. Sysuptime
is 0.
* This simply indicates when this object was created.
*/
public Timestamp() {
crtime = System.currentTimeMillis() ;
}
/**
* Creates a TimeStamp
object using the user parameters.
* @param uptime The time (in hundredths of a second) since the
* network management portion of the system was last re-initialized.
* @param when The current time.
*/
public Timestamp(long uptime, long when) {
sysUpTime = uptime ;
crtime = when ;
}
/**
* Creates a TimeStamp
object using the user parameters.
* @param uptime The time (in hundredths of a second) since the
* network management portion of the system was last re-initialized.
*/
public Timestamp(long uptime) {
sysUpTime = uptime ;
crtime = System.currentTimeMillis() ;
}
// GETTER/SETTER
//--------------
/**
* Gets the SnmpTimeticks
object corresponding to the TimeStamp
object.
* @return The SnmpTimeticks
object.
*/
final public synchronized SnmpTimeticks getTimeTicks() {
if (uptimeCache == null)
uptimeCache = new SnmpTimeticks((int)sysUpTime) ;
return uptimeCache ;
}
/**
* Gets the time (in hundredths of a second) since the network management portion of the system
* was last re-initialized.
* @return The sysUpTime
.
*/
final public long getSysUpTime() {
return sysUpTime ;
}
/**
* Gets the current date.
* @return A Date
object representing the current date.
*/
final public synchronized Date getDate() {
if (dateCache == null)
dateCache = new Date(crtime) ;
return dateCache ;
}
/**
* Gets the current date.
* @return A long
representing the current date.
*/
final public long getDateTime() {
return crtime ;
}
/**
* Returns a String
representation of the TimeStamp
object.
* @return A String
representation of the TimeStamp
object.
*/
final public String toString() {
StringBuffer buf = new StringBuffer() ;
buf.append("{SysUpTime = " + SnmpTimeticks.printTimeTicks(sysUpTime)) ;
buf.append("} {Timestamp = " + getDate().toString() + "}") ;
return buf.toString() ;
}
}