/** * Updates timestamp for a received event * * @param ts Object that implements Timestamped interface * @return updated timestamp */ public long update(HybridTimestamp ts) { return update(ts.getLogicalTime(), ts.getLogicalCounter()); }
/** * Updates timestamp for local or send events * * @return updated timestamp */ public long update() { long physicalTime = physicalTimeProvider.getPhysicalTime(); if (compare(logicalTime, physicalTime) < 0) { logicalTime = physicalTime; logicalCounter = 0; } else { logicalCounter++; } return timestamp(); }
@Override protected void runOneIteration() throws Exception { update(); }
/** * Creates a new instance of HybridTimestamp with the same data * * @return a new object instance */ public HybridTimestamp clone() { return new HybridTimestamp(physicalTimeProvider, logicalTime, logicalCounter); }
@Override public boolean equals(Object obj) { return obj instanceof HybridTimestamp && compareTo((HybridTimestamp) obj) == 0; }
@Override public int compareTo(HybridTimestamp o) { int ntpComparison = compare(logicalTime, o.logicalTime); if (ntpComparison == 0) { return new Long(logicalCounter).compareTo(o.logicalCounter); } else { return ntpComparison; } }
@Override protected void doStop() { notifyStopped(); } }
@Override protected void doStart() { notifyStarted(); }
@BeforeClass public void setup() { physicalTimeProvider = new TestPhysicalTimeProvider(); }
/** * Updates timestamp for a received event * * @param ts Object that implements Timestamped interface * @return updated timestamp */ public long update(HybridTimestamp ts) { return update(ts.getLogicalTime(), ts.getLogicalCounter()); }
/** * Updates timestamp for local or send events * * @return updated timestamp */ public long update() { long physicalTime = physicalTimeProvider.getPhysicalTime(); if (compare(logicalTime, physicalTime) < 0) { logicalTime = physicalTime; logicalCounter = 0; } else { logicalCounter++; } return timestamp(); }
/** * Creates a new instance of HybridTimestamp with the same data * * @return a new object instance */ public HybridTimestamp clone() { return new HybridTimestamp(physicalTimeProvider, logicalTime, logicalCounter); }
@Override protected void startUp() throws Exception { update(); }
@Override public int compareTo(HybridTimestamp o) { int ntpComparison = compare(logicalTime, o.logicalTime); if (ntpComparison == 0) { return new Long(logicalCounter).compareTo(o.logicalCounter); } else { return ntpComparison; } }
/** * Updates timestamp for a received event * * @param eventLogicalTime Received event logical time * @param eventLogicalCounter Received event logical counter * @return updated timestamp */ public long update(long eventLogicalTime, long eventLogicalCounter) { long physicalTime = physicalTimeProvider.getPhysicalTime(); if (compare(physicalTime, eventLogicalTime) > 0 && compare(physicalTime, logicalTime) > 0) { logicalTime = physicalTime; logicalCounter = 0; } else if (compare(eventLogicalTime, logicalTime) > 0) { logicalTime = eventLogicalTime; logicalCounter++; } else if (compare(logicalTime, eventLogicalTime) > 0) { logicalCounter++; } else { if (eventLogicalCounter > logicalCounter) { logicalCounter = eventLogicalCounter; } logicalCounter++; } return timestamp(); }
@Override protected void startUp() throws Exception { update(); }
/** * Compares two NTP timestamps (non-numerically) * * @param time1 * @param time2 * @return 0 if equal, less than 0 if time1 < time2, more than 0 if time1 > time2 */ public static int compare(long time1, long time2) { TimeStamp t1 = new TimeStamp(time1); TimeStamp t2 = new TimeStamp(time2); return compare(t1, t2); }
@Override protected void runOneIteration() throws Exception { update(); }