/** * Gets the time the operation started. * * @return operation start time */ public UsecTimestamp getStartTime() { return new UsecTimestamp(startTimeUs); }
/** * Adds the specified UsecTimestamp to this one. * * @param other * timestamp to add to current one */ public void add(UsecTimestamp other) { add(other.msecs, other.usecs); }
/** * Purpose of this method is to make this class compatible with Groovy script standard for number operator "minus" * {@code '-'} overloading. See <a href="http://groovy-lang.org/operators.html">Groovy operators spec</a> section * "Operator overloading". * <p> * Performs same as {@link #difference(UsecTimestamp)}. * * @param other * other UsecTimestamp instance * @return difference, in microseconds, between two timestamps * * @see #difference(UsecTimestamp) */ public long minus(UsecTimestamp other) { return difference(other); } }
/** * {@inheritDoc} * * <p> * Returns {@link #getTimeUsec()}. * </p> */ @Override public long longValue() { return getTimeUsec(); }
simCurrTime = new UsecTimestamp(); simCurrTime.add(0, elapsed); curEvent.stop(simCurrTime, elapsed); TNT4JSimulator.debug(simCurrTime, "Ran event: " + name + ", elapsed.usec=" + elapsed);
/** * Returns the string representation of the timestamp based on the default format pattern, microseconds. * * @param usecs * microseconds * @return formatted date/time string based on pattern */ public static String getTimeStamp(long usecs) { long msecs = usecs / 1000L; return getTimeStamp(null, msecs, (usecs - msecs * 1000)); }
setTimestampValues(date.getTime(), 0, 0); add(0, usecs);
/** * Creates UsecTimestamp based on specified UsecTimestamp. * * @param other * timestamp to copy * @throws NullPointerException * if timestamp is {@code null} */ public UsecTimestamp(UsecTimestamp other) { this(other.msecs, other.usecs, other.getLamportClock()); }
@Override public long getTime() { return timeStamp.getTimeMillis(); }
/** * Creates UsecTimestamp based on specified Timestamp, providing time in seconds resolution, and fractional * microsecond. * * @param timestamp * database timestamp, seconds resolution * @param usecs * fraction microseconds * @throws NullPointerException * if timestamp is {@code null} * @throws IllegalArgumentException * if usecs is greater than 999999 */ public UsecTimestamp(Timestamp timestamp, long usecs) { initFromTimestamp(timestamp, usecs); }
@Override public int hashCode() { int prime = 31; int result = 1; UsecTimestamp ts = getStartTime(); result = prime * result + ((opName == null) ? 0 : opName.hashCode()); if (ts != null) { result = prime * result + ts.hashCode(); } return result; }
/** * Creates UsecTimestamp based on specified millisecond timestamp and fractional microsecond. * * @param msecs * timestamp, in milliseconds * @param usecs * fraction microseconds * @param recvdLamportClock * received Lamport clock * @throws IllegalArgumentException * if any arguments are negative, or if usecs is greater than 999 */ protected void setTimestampValues(long msecs, long usecs, long recvdLamportClock) { if (msecs < 0) { throw new IllegalArgumentException("msecs must be non-negative"); } if (usecs < 0 || usecs > 999) { throw new IllegalArgumentException("usecs must be in the range [0,999], inclusive"); } this.msecs = msecs; this.usecs = usecs; assignLamportClock(recvdLamportClock); }
/** * {@inheritDoc} * * <p> * Returns {@link #getTimeUsec()} as a double. * </p> */ @Override public double doubleValue() { return getTimeUsec(); }
/** * {@inheritDoc} * <p> * Returns the string representation of this timestamp in the default timezone. * </p> */ @Override public String toString() { return getTimeStamp(msecs, usecs); }
/** * {@inheritDoc} * * <p> * Returns {@link #getTimeUsec()} as an int, possibly truncated. * </p> */ @Override public int intValue() { return (int) getTimeUsec(); }
/** * Returns UsecTimestamp based on current time with microsecond precision/accuracy * * @return UsecTimestamp for current time * @see com.jkoolcloud.tnt4j.utils.Utils#currentTimeUsec */ public static UsecTimestamp now() { return new UsecTimestamp(); }
/** * Returns the string representation of this timestamp in the specified timezone. * * @param tz * timezone * @return formatted date/time string in specified timezone */ public String toString(TimeZone tz) { return getTimeStamp(null, tz, msecs, usecs); }
/** * Purpose of this method is to make this class compatible with Groovy script standard for number operator "plus" * {@code '+'} overloading. See <a href="http://groovy-lang.org/operators.html">Groovy operators spec</a> section * "Operator overloading". * <p> * Performs same as {@link #add(UsecTimestamp)}. * * @param other * timestamp to add to current one * @return current UsecTimestamp instance * * @see #add(UsecTimestamp) */ public UsecTimestamp plus(UsecTimestamp other) { add(other); return this; }
private void stopActivity() throws SAXException { long elapsed = simCurrTime.difference(curActivity.getStartTime()); curActivity.stop(simCurrTime, elapsed); TNT4JSimulator.debug(simCurrTime, "Stopped activity " + curActivity.getName() + ", elapsed.usec: " + elapsed); if (curActivity.getStatus() == ActivityStatus.BEGIN) { curActivity.setStatus(ActivityStatus.END); } Tracker tracker = trackers.get(curActivity.getSource().getFQName()); if (tracker != null) { tracker.tnt(curActivity); try { tracker.getEventSink().flush(); } catch (IOException e) { TNT4JSimulator.warn("Failed flushing event sink on stop of activity " + curActivity.getName(), e); } } curActivity = activeActivities.pop(); curActivityStart = null; curTracker = null; }
/** * {@inheritDoc} * * <p> * Returns {@link #getTimeUsec()} as a float, possibly truncated. * </p> */ @Override public float floatValue() { return getTimeUsec(); }