Skip to content

Commit

Permalink
Rename state machine context clock to time.
Browse files Browse the repository at this point in the history
  • Loading branch information
kuujo committed Aug 13, 2015
1 parent 09ca102 commit c3d2be0
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 20 deletions.
Expand Up @@ -132,7 +132,7 @@ protected Object get(Commit<ReferenceCommands.Get> commit) {
* Applies a set commit. * Applies a set commit.
*/ */
protected void set(Commit<ReferenceCommands.Set> commit) { protected void set(Commit<ReferenceCommands.Set> commit) {
if (!isActive(commit, context().clock().instant())) { if (!isActive(commit, context().time().instant())) {
commit.clean(); commit.clean();
} else { } else {
if (current != null) { if (current != null) {
Expand All @@ -148,7 +148,7 @@ protected void set(Commit<ReferenceCommands.Set> commit) {
* Handles a compare and set commit. * Handles a compare and set commit.
*/ */
protected boolean compareAndSet(Commit<ReferenceCommands.CompareAndSet> commit) { protected boolean compareAndSet(Commit<ReferenceCommands.CompareAndSet> commit) {
if (!isActive(commit, context().clock().instant())) { if (!isActive(commit, context().time().instant())) {
commit.clean(); commit.clean();
return false; return false;
} else if (isActive(current, commit.time())) { } else if (isActive(current, commit.time())) {
Expand Down Expand Up @@ -178,7 +178,7 @@ protected boolean compareAndSet(Commit<ReferenceCommands.CompareAndSet> commit)
* Handles a get and set commit. * Handles a get and set commit.
*/ */
protected Object getAndSet(Commit<ReferenceCommands.GetAndSet> commit) { protected Object getAndSet(Commit<ReferenceCommands.GetAndSet> commit) {
if (!isActive(commit, context().clock().instant())) { if (!isActive(commit, context().time().instant())) {
commit.clean(); commit.clean();


} }
Expand Down
Expand Up @@ -88,7 +88,7 @@ protected boolean containsKey(Commit<MapCommands.ContainsKey> commit) {
} }


Commit<? extends MapCommands.TtlCommand> command = map.get(commit.operation().key()); Commit<? extends MapCommands.TtlCommand> command = map.get(commit.operation().key());
if (!isActive(command, context().clock().instant())) { if (!isActive(command, context().time().instant())) {
map.remove(commit.operation().key()); map.remove(commit.operation().key());
return false; return false;
} }
Expand All @@ -109,7 +109,7 @@ protected Object get(Commit<MapCommands.Get> commit) {
try { try {
Commit<? extends MapCommands.TtlCommand> command = map.get(commit.operation().key()); Commit<? extends MapCommands.TtlCommand> command = map.get(commit.operation().key());
if (command != null) { if (command != null) {
if (!isActive(command, context().clock().instant())) { if (!isActive(command, context().time().instant())) {
map.remove(commit.operation().key()); map.remove(commit.operation().key());
} else { } else {
return command.operation().value(); return command.operation().value();
Expand All @@ -133,7 +133,7 @@ protected Object getOrDefault(Commit<MapCommands.GetOrDefault> commit) {
Commit<? extends MapCommands.TtlCommand> previous = map.get(commit.operation().key()); Commit<? extends MapCommands.TtlCommand> previous = map.get(commit.operation().key());
if (previous == null) { if (previous == null) {
return commit.operation().defaultValue(); return commit.operation().defaultValue();
} else if (isActive(previous, context().clock().instant())) { } else if (isActive(previous, context().time().instant())) {
return previous.operation().value(); return previous.operation().value();
} }
return commit.operation().defaultValue(); return commit.operation().defaultValue();
Expand All @@ -152,7 +152,7 @@ protected Object put(Commit<MapCommands.Put> commit) {


Commit<? extends MapCommands.TtlCommand> previous = map.get(commit.operation().key()); Commit<? extends MapCommands.TtlCommand> previous = map.get(commit.operation().key());
if (previous == null) { if (previous == null) {
if (!isActive(commit, context().clock().instant())) { if (!isActive(commit, context().time().instant())) {
commit.clean(); commit.clean();
} else { } else {
map.put(commit.operation().key(), commit); map.put(commit.operation().key(), commit);
Expand All @@ -175,7 +175,7 @@ protected Object putIfAbsent(Commit<MapCommands.PutIfAbsent> commit) {


Commit<? extends MapCommands.TtlCommand> previous = map.get(commit.operation().key()); Commit<? extends MapCommands.TtlCommand> previous = map.get(commit.operation().key());
if (previous == null) { if (previous == null) {
if (!isActive(commit, context().clock().instant())) { if (!isActive(commit, context().time().instant())) {
commit.clean(); commit.clean();
} else { } else {
map.put(commit.operation().key(), commit); map.put(commit.operation().key(), commit);
Expand Down
Expand Up @@ -104,7 +104,7 @@ protected boolean add(Commit<SetCommands.Add> commit) {
} }


Commit<? extends SetCommands.TtlCommand> previous = map.get(commit.operation().value()); Commit<? extends SetCommands.TtlCommand> previous = map.get(commit.operation().value());
if (!isActive(commit, context().clock().instant())) { if (!isActive(commit, context().time().instant())) {
commit.clean(); commit.clean();
return false; return false;
} else if (!isActive(previous, commit.time())) { } else if (!isActive(previous, commit.time())) {
Expand Down
Expand Up @@ -64,7 +64,7 @@ protected void unlock(Commit<LockCommands.Unlock> commit) {
throw new IllegalStateException("not the lock holder"); throw new IllegalStateException("not the lock holder");


lock = queue.poll(); lock = queue.poll();
while (lock != null && (lock.operation().timeout() != -1 && lock.time().toEpochMilli() + lock.operation().timeout() < context().clock().instant().toEpochMilli())) { while (lock != null && (lock.operation().timeout() != -1 && lock.time().toEpochMilli() + lock.operation().timeout() < context().time().instant().toEpochMilli())) {
lock.clean(); lock.clean();
lock = queue.poll(); lock = queue.poll();
} }
Expand Down
Expand Up @@ -33,11 +33,11 @@ public interface StateMachineContext {
long version(); long version();


/** /**
* Returns the deterministic state machine clock. * Returns the deterministic state machine time.
* *
* @return The deterministic state machine clock. * @return The deterministic state machine time.
*/ */
Clock clock(); Clock time();


/** /**
* Returns the state machine sessions. * Returns the state machine sessions.
Expand Down
Expand Up @@ -45,7 +45,7 @@ public long version() {
} }


@Override @Override
public Clock clock() { public Clock time() {
return clock; return clock;
} }


Expand All @@ -56,7 +56,7 @@ public SessionManager sessions() {


@Override @Override
public String toString() { public String toString() {
return String.format("%s[version=%d, clock=%s]", getClass().getSimpleName(), version, clock); return String.format("%s[version=%d, time=%s]", getClass().getSimpleName(), version, clock);
} }


} }
Expand Up @@ -30,7 +30,6 @@
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.function.BiFunction;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;


Expand Down Expand Up @@ -232,7 +231,7 @@ private ServerScheduledTask(long delay, long interval, Runnable callback) {
this.delay = delay; this.delay = delay;
this.interval = interval; this.interval = interval;
this.callback = callback; this.callback = callback;
this.time = context.clock().instant().toEpochMilli() + delay; this.time = context.time().instant().toEpochMilli() + delay;
} }


/** /**
Expand Down Expand Up @@ -275,7 +274,7 @@ private ScheduledTask schedule() {
*/ */
private void reschedule() { private void reschedule() {
if (interval > 0) { if (interval > 0) {
time = context.clock().instant().toEpochMilli() + delay; time = context.time().instant().toEpochMilli() + delay;
schedule(); schedule();
} }
} }
Expand Down
Expand Up @@ -21,7 +21,7 @@
import java.time.ZoneId; import java.time.ZoneId;


/** /**
* State machine clock. * State machine time.
* *
* @author <a href="http://github.com/kuujo>Jordan Halterman</a> * @author <a href="http://github.com/kuujo>Jordan Halterman</a>
*/ */
Expand All @@ -30,7 +30,7 @@ public class StateClock extends Clock {
private Instant instant; private Instant instant;


/** /**
* Sets the state machine clock instant. * Sets the state machine time instant.
*/ */
void set(Instant instant) { void set(Instant instant) {
this.instant = instant; this.instant = instant;
Expand Down

0 comments on commit c3d2be0

Please sign in to comment.