Skip to content

Commit

Permalink
Rename Clock getter to adhere to naming standards.
Browse files Browse the repository at this point in the history
  • Loading branch information
kuujo committed Jan 11, 2018
1 parent e758d3d commit 76c9238
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 25 deletions.
Expand Up @@ -204,7 +204,7 @@ protected boolean anoint(Commit<? extends Anoint> commit) {
if (newLeader != null) { if (newLeader != null) {
this.leader = newLeader; this.leader = newLeader;
this.term = termCounter.incrementAndGet(); this.term = termCounter.incrementAndGet();
this.termStartTime = context().wallClock().time().unixTimestamp(); this.termStartTime = context().wallClock().getTime().unixTimestamp();
} }
Leadership<byte[]> newLeadership = leadership(); Leadership<byte[]> newLeadership = leadership();
if (!Objects.equal(oldLeadership, newLeadership)) { if (!Objects.equal(oldLeadership, newLeadership)) {
Expand Down Expand Up @@ -278,7 +278,7 @@ protected void evict(Commit<? extends Evict> commit) {
this.registrations = updatedRegistrations; this.registrations = updatedRegistrations;
this.leader = updatedRegistrations.get(0); this.leader = updatedRegistrations.get(0);
this.term = termCounter.incrementAndGet(); this.term = termCounter.incrementAndGet();
this.termStartTime = context().wallClock().time().unixTimestamp(); this.termStartTime = context().wallClock().getTime().unixTimestamp();
} else { } else {
this.registrations = updatedRegistrations; this.registrations = updatedRegistrations;
this.leader = null; this.leader = null;
Expand Down Expand Up @@ -364,7 +364,7 @@ protected void cleanup(byte[] id) {
this.registrations = updatedRegistrations; this.registrations = updatedRegistrations;
this.leader = updatedRegistrations.get(0); this.leader = updatedRegistrations.get(0);
this.term = termCounter.incrementAndGet(); this.term = termCounter.incrementAndGet();
this.termStartTime = context().wallClock().time().unixTimestamp(); this.termStartTime = context().wallClock().getTime().unixTimestamp();
} else { } else {
this.registrations = updatedRegistrations; this.registrations = updatedRegistrations;
this.leader = null; this.leader = null;
Expand All @@ -388,7 +388,7 @@ protected void cleanup(Session session) {
this.registrations = updatedRegistrations; this.registrations = updatedRegistrations;
this.leader = updatedRegistrations.get(0); this.leader = updatedRegistrations.get(0);
this.term = termCounter.incrementAndGet(); this.term = termCounter.incrementAndGet();
this.termStartTime = context().wallClock().time().unixTimestamp(); this.termStartTime = context().wallClock().getTime().unixTimestamp();
} else { } else {
this.registrations = updatedRegistrations; this.registrations = updatedRegistrations;
this.leader = null; this.leader = null;
Expand Down Expand Up @@ -421,7 +421,7 @@ protected void addRegistration(Registration registration) {
if (newLeader) { if (newLeader) {
this.leader = registration; this.leader = registration;
this.term = termCounter.incrementAndGet(); this.term = termCounter.incrementAndGet();
this.termStartTime = context().wallClock().time().unixTimestamp(); this.termStartTime = context().wallClock().getTime().unixTimestamp();
} }
} }
} }
Expand Down
Expand Up @@ -73,7 +73,7 @@ public void restore(BufferInput<?> reader) {
timers.clear(); timers.clear();
for (LockHolder holder : queue) { for (LockHolder holder : queue) {
if (holder.expire > 0) { if (holder.expire > 0) {
timers.put(holder.index, scheduler().schedule(Duration.ofMillis(holder.expire - context().wallClock().time().unixTimestamp()), () -> { timers.put(holder.index, scheduler().schedule(Duration.ofMillis(holder.expire - context().wallClock().getTime().unixTimestamp()), () -> {
timers.remove(holder.index); timers.remove(holder.index);
queue.remove(holder); queue.remove(holder);
Session session = sessions().getSession(holder.session); Session session = sessions().getSession(holder.session);
Expand Down Expand Up @@ -113,7 +113,7 @@ protected void lock(Commit<Lock> commit) {
commit.value().id(), commit.value().id(),
commit.index(), commit.index(),
commit.session().sessionId().id(), commit.session().sessionId().id(),
context().wallClock().time().unixTimestamp() + commit.value().timeout()); context().wallClock().getTime().unixTimestamp() + commit.value().timeout());
queue.add(holder); queue.add(holder);
timers.put(commit.index(), scheduler().schedule(Duration.ofMillis(commit.value().timeout()), () -> { timers.put(commit.index(), scheduler().schedule(Duration.ofMillis(commit.value().timeout()), () -> {
timers.remove(commit.index()); timers.remove(commit.index());
Expand Down
Expand Up @@ -155,7 +155,7 @@ public void restore(BufferInput<?> reader) {
currentVersion = reader.readLong(); currentVersion = reader.readLong();
map.forEach((key, value) -> { map.forEach((key, value) -> {
if (value.ttl() > 0) { if (value.ttl() > 0) {
value.timer = scheduler().schedule(Duration.ofMillis(value.ttl() - (wallClock().time().unixTimestamp() - value.created())), () -> { value.timer = scheduler().schedule(Duration.ofMillis(value.ttl() - (wallClock().getTime().unixTimestamp() - value.created())), () -> {
entries().remove(key, value); entries().remove(key, value);
publish(new MapEvent<>(MapEvent.Type.REMOVE, "", key, null, toVersioned(value))); publish(new MapEvent<>(MapEvent.Type.REMOVE, "", key, null, toVersioned(value)));
}); });
Expand Down
Expand Up @@ -87,13 +87,13 @@ public class PrimaryBackupServiceContext implements ServiceContext {
private OperationType currentOperation = OperationType.COMMAND; private OperationType currentOperation = OperationType.COMMAND;
private final LogicalClock logicalClock = new LogicalClock() { private final LogicalClock logicalClock = new LogicalClock() {
@Override @Override
public LogicalTimestamp time() { public LogicalTimestamp getTime() {
return new LogicalTimestamp(operationIndex); return new LogicalTimestamp(operationIndex);
} }
}; };
private final WallClock wallClock = new WallClock() { private final WallClock wallClock = new WallClock() {
@Override @Override
public WallClockTimestamp time() { public WallClockTimestamp getTime() {
return WallClockTimestamp.from(currentTimestamp); return WallClockTimestamp.from(currentTimestamp);
} }
}; };
Expand Down
Expand Up @@ -82,13 +82,13 @@ public class RaftServiceContext implements ServiceContext {
private OperationType currentOperation; private OperationType currentOperation;
private final LogicalClock logicalClock = new LogicalClock() { private final LogicalClock logicalClock = new LogicalClock() {
@Override @Override
public LogicalTimestamp time() { public LogicalTimestamp getTime() {
return new LogicalTimestamp(currentIndex); return new LogicalTimestamp(currentIndex);
} }
}; };
private final WallClock wallClock = new WallClock() { private final WallClock wallClock = new WallClock() {
@Override @Override
public WallClockTimestamp time() { public WallClockTimestamp getTime() {
return new WallClockTimestamp(currentTimestamp); return new WallClockTimestamp(currentTimestamp);
} }
}; };
Expand Down
2 changes: 1 addition & 1 deletion utils/src/main/java/io/atomix/utils/time/Clock.java
Expand Up @@ -25,6 +25,6 @@ public interface Clock<T extends Timestamp> {
* *
* @return the current time * @return the current time
*/ */
T time(); T getTime();


} }
4 changes: 2 additions & 2 deletions utils/src/main/java/io/atomix/utils/time/LogicalClock.java
Expand Up @@ -32,7 +32,7 @@ public LogicalClock(LogicalTimestamp currentTimestamp) {
} }


@Override @Override
public LogicalTimestamp time() { public LogicalTimestamp getTime() {
return currentTimestamp; return currentTimestamp;
} }


Expand Down Expand Up @@ -75,7 +75,7 @@ public LogicalTimestamp incrementAndUpdate(LogicalTimestamp timestamp) {
@Override @Override
public String toString() { public String toString() {
return toStringHelper(this) return toStringHelper(this)
.add("time", time()) .add("time", getTime())
.toString(); .toString();
} }
} }
6 changes: 3 additions & 3 deletions utils/src/main/java/io/atomix/utils/time/VectorClock.java
Expand Up @@ -50,7 +50,7 @@ public VectorClock(VectorTimestamp<T> localTimestamp, Collection<VectorTimestamp
} }


@Override @Override
public VectorTimestamp<T> time() { public VectorTimestamp<T> getTime() {
return vector.get(localIdentifier); return vector.get(localIdentifier);
} }


Expand All @@ -60,7 +60,7 @@ public VectorTimestamp<T> time() {
* @return the logical timestamp for the local identifier * @return the logical timestamp for the local identifier
*/ */
public LogicalTimestamp getLocalTimestamp() { public LogicalTimestamp getLocalTimestamp() {
return time(); return getTime();
} }


/** /**
Expand Down Expand Up @@ -108,7 +108,7 @@ public void update(VectorClock<T> clock) {
@Override @Override
public String toString() { public String toString() {
return toStringHelper(this) return toStringHelper(this)
.add("time", time()) .add("time", getTime())
.add("vector", getTimestamps()) .add("vector", getTimestamps())
.toString(); .toString();
} }
Expand Down
4 changes: 2 additions & 2 deletions utils/src/main/java/io/atomix/utils/time/WallClock.java
Expand Up @@ -22,14 +22,14 @@
*/ */
public class WallClock implements Clock<WallClockTimestamp> { public class WallClock implements Clock<WallClockTimestamp> {
@Override @Override
public WallClockTimestamp time() { public WallClockTimestamp getTime() {
return new WallClockTimestamp(); return new WallClockTimestamp();
} }


@Override @Override
public String toString() { public String toString() {
return toStringHelper(this) return toStringHelper(this)
.add("time", time()) .add("time", getTime())
.toString(); .toString();
} }
} }
Expand Up @@ -27,11 +27,11 @@ public class LogicalClockTest {
public void testLogicalClock() throws Exception { public void testLogicalClock() throws Exception {
LogicalClock clock = new LogicalClock(); LogicalClock clock = new LogicalClock();
assertEquals(1, clock.increment().value()); assertEquals(1, clock.increment().value());
assertEquals(1, clock.time().value()); assertEquals(1, clock.getTime().value());
assertEquals(2, clock.increment().value()); assertEquals(2, clock.increment().value());
assertEquals(2, clock.time().value()); assertEquals(2, clock.getTime().value());
assertEquals(5, clock.update(LogicalTimestamp.of(5)).value()); assertEquals(5, clock.update(LogicalTimestamp.of(5)).value());
assertEquals(5, clock.time().value()); assertEquals(5, clock.getTime().value());
assertEquals(5, clock.update(LogicalTimestamp.of(3)).value()); assertEquals(5, clock.update(LogicalTimestamp.of(3)).value());
} }
} }
4 changes: 2 additions & 2 deletions utils/src/test/java/io/atomix/utils/time/WallClockTest.java
Expand Up @@ -27,9 +27,9 @@ public class WallClockTest {
@Test @Test
public void testWallClock() throws Exception { public void testWallClock() throws Exception {
WallClock clock = new WallClock(); WallClock clock = new WallClock();
WallClockTimestamp time = clock.time(); WallClockTimestamp time = clock.getTime();
assertNotNull(time); assertNotNull(time);
Thread.sleep(5); Thread.sleep(5);
assertTrue(clock.time().unixTimestamp() > time.unixTimestamp()); assertTrue(clock.getTime().unixTimestamp() > time.unixTimestamp());
} }
} }

0 comments on commit 76c9238

Please sign in to comment.