/*** * Parses the string argument as a NTP hexidecimal timestamp representation string * (e.g. "c1a089bd.fc904f6d"). * * @param s - hexstring. * @return the Timestamp represented by the argument in hexidecimal. * @throws NumberFormatException - if the string does not contain a parsable timestamp. */ public static TimeStamp parseNtpString(String s) throws NumberFormatException { return new TimeStamp(decodeNtpHexString(s)); }
/*** * Convert NTP timestamp to Java standard time. * * @return NTP Timestamp in Java time */ public long getTime() { return getTime(ntpTime); }
/*** * Constructs a NTP timestamp object and initializes it so that * it represents the time at which it was allocated, measured to the * nearest millisecond. * @return NTP timestamp object set to the current time. * @see java.lang.System#currentTimeMillis() */ public static TimeStamp getCurrentTime() { return getNtpTime(System.currentTimeMillis()); }
/*** * Helper method to convert Java time to NTP timestamp object. * Note that Java time (milliseconds) by definition has less precision * then NTP time (picoseconds) so converting Ntptime to Javatime and back * to Ntptime loses precision. For example, Tue, Dec 17 2002 09:07:24.810 * is represented by a single Java-based time value of f22cd1fc8a, but its * NTP equivalent are all values from c1a9ae1c.cf5c28f5 to c1a9ae1c.cf9db22c. * @param date the milliseconds since January 1, 1970, 00:00:00 GMT. * @return NTP timestamp object at the specified date. */ public static TimeStamp getNtpTime(long date) { return new TimeStamp(toNtpTime(date)); }
long origTime = origNtpTime.getTime(); long rcvTime = rcvNtpTime.getTime(); long xmitTime = xmitNtpTime.getTime(); if (origNtpTime.ntpValue() == 0) if (xmitNtpTime.ntpValue() != 0) _comments.add("Error: zero orig time -- cannot compute delay/offset"); } else if (rcvNtpTime.ntpValue() == 0 || xmitNtpTime.ntpValue() == 0) { _comments.add("Warning: zero rcvNtpTime or xmitNtpTime"); if (rcvNtpTime.ntpValue() != 0) } else if (xmitNtpTime.ntpValue() != 0)
@Override public BigInteger getSerializableComparable() { TimeStamp t = new TimeStamp(logicalTime); return BigInteger.valueOf(t.getSeconds()) .shiftLeft(64) .add(BigInteger.valueOf(t.getFraction()).shiftLeft(32)) .add(BigInteger.valueOf(logicalCounter)); } }
public void estimateRtt(long receiptDate, long lastSR, long delaySinceSR) { TimeStamp receiptNtp = TimeStamp.getNtpTime(receiptDate); long receiptNtpTime = NtpUtils.calculateLastSrTimestamp(receiptNtp.getSeconds(), receiptNtp.getFraction()); long delay = receiptNtpTime - lastSR - delaySinceSR; this.roundTripDelay = (delay > 4294967L) ? RTP_SEQ_MOD : (int) ((delay * 1000L) >> 16); if(logger.isTraceEnabled()) { logger.trace("rtt=" + receiptNtpTime + " - " + lastSR + " - " + delaySinceSR + " = " + delay + " => " + this.roundTripDelay + "ms"); } }
/** * Get NTP Timestamp at specified starting index. * * @param index index into data array * @return TimeStamp object for 64 bits starting at index */ private TimeStamp getTimestamp(int index) { return new TimeStamp(getLong(index)); }
@Override public Long getSerializableComparable() { return TimeStamp.getNtpTime(timestamp()).getDate().getTime(); } }
/*** * Sets the NTP timestamp at the given array index. * * @param index index into the byte array. * @param t TimeStamp. */ private void setTimestamp(int index, TimeStamp t) { long ntpTime = (t == null) ? 0 : t.ntpValue(); // copy 64-bits from Long value into 8 x 8-bit bytes of array // one byte at a time shifting 8-bits for each position. for (int i = 7; i >= 0; i--) { buf[index + i] = (byte) (ntpTime & 0xFF); ntpTime >>>= 8; // shift to next byte } // buf[index] |= 0x80; // only set if 1900 baseline.... }
public String toString() { String logical = new TimeStamp(logicalTime).toUTCString(); String timeStamp = new TimeStamp(timestamp()).toUTCString(); return "<HybridTimestamp logical=" + logical + "@" + logicalCounter + " NTP=" + timeStamp + "/" + timestamp () + ">"; }
/*** * Converts this <code>TimeStamp</code> object to a <code>String</code> * of the form: * <blockquote><pre> * EEE, MMM dd yyyy HH:mm:ss.SSS</pre></blockquote> * See java.text.SimpleDataFormat for code descriptions. * * @return a string representation of this date. */ public String toDateString() { if (simpleFormatter == null) { simpleFormatter = new SimpleDateFormat(NTP_DATE_FORMAT, Locale.US); simpleFormatter.setTimeZone(TimeZone.getDefault()); } Date ntpDate = getDate(); return simpleFormatter.format(ntpDate); }
public static int compare(TimeStamp t1, TimeStamp t2) { if (t1.getSeconds() == t2.getSeconds() && t1.getFraction() == t2.getFraction()) { return 0; } if (t1.getSeconds() == t2.getSeconds()) { return t1.getFraction() < t2.getFraction() ? -1 : 1; } return t1.getSeconds() < t2.getSeconds() ? -1 : 1; }
private void test(HashMap<String, HashMap<String, Set<PairXMLData>>> data, String model) { // write the data to a file to be passed as an argument to the EOPRunner ExperimenterFileUtils.writeDataToFile(data, tmpTestFile, language); // replace the name of the model in the configuration file ExperimenterFileUtils.writeModelInConfig(options.config,options.model); String outFileStem = options.output + TimeStamp.getCurrentTime().toString(); // make the list of arguments for the EOPRunner String[] args = new String[] {"-config", options.config, "-test", "-testFile", tmpTestFile, "-output", outFileStem, "-score"}; logger.info("Running the EOP with arguments: " + StringUtils.join(args," ")); if (! options.fakeRun) { EOPRunner runner = new EOPRunner(args); runner.run(); } }
/*** * Converts this <code>TimeStamp</code> object to a <code>String</code>. * The NTP timestamp 64-bit long value is represented as hex string with * seconds separated by fractional seconds by a decimal point; * e.g. c1a089bd.fc904f6d == Tue, Dec 10 2002 10:41:49.986 * * @return NTP timestamp 64-bit long value as hex string with seconds * separated by fractional seconds. */ @Override public String toString() { return toString(ntpTime); }
TimeStamp now = TimeStamp.getCurrentTime();
/*** * Converts 64-bit NTP timestamp value to a <code>String</code>. * The NTP timestamp value is represented as hex string with * seconds separated by fractional seconds by a decimal point; * e.g. c1a089bd.fc904f6d == Tue, Dec 10 2002 10:41:49.986 * @param ntpTime the 64 bit timestamp * * @return NTP timestamp 64-bit long value as hex string with seconds * separated by fractional seconds. */ public static String toString(long ntpTime) { StringBuilder buf = new StringBuilder(); // high-order second bits (32..63) as hexstring appendHexString(buf, (ntpTime >>> 32) & 0xffffffffL); // low-order fractional seconds bits (0..31) as hexstring buf.append('.'); appendHexString(buf, ntpTime & 0xffffffffL); return buf.toString(); }
TimeStamp ntpTs = new TimeStamp(new Date(currentTime)); long ntpSec = ntpTs.getSeconds(); long ntpFrac = ntpTs.getFraction(); long elapsedTime = statistics.getCurrentTime() - statistics.getRtpSentOn(); long rtpTs = statistics.getRtpTimestamp() + statistics.getRtpTime(elapsedTime);