From e5a3f0f0500c9ef27e5c7c8726b73aa04c358e9b Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 6 Jan 2013 11:54:37 +0100 Subject: [PATCH] Includes the time in the state. --- src/main/java/net/pterodactylus/reactor/State.java | 8 ++++++++ .../java/net/pterodactylus/reactor/states/AbstractState.java | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/net/pterodactylus/reactor/State.java b/src/main/java/net/pterodactylus/reactor/State.java index 9e2face..cc37909 100644 --- a/src/main/java/net/pterodactylus/reactor/State.java +++ b/src/main/java/net/pterodactylus/reactor/State.java @@ -25,6 +25,14 @@ package net.pterodactylus.reactor; public interface State { /** + * Returns the time when this state was retrieved. + * + * @return The time when this state was retrieved (in millseconds since Jan + * 1, 1970 UTC) + */ + long time(); + + /** * Whether the state was successfully retrieved. This method should only * return {@code true} if a meaningful result could be retrieved; if e. g. a * service is currently not reachable, this method should return false diff --git a/src/main/java/net/pterodactylus/reactor/states/AbstractState.java b/src/main/java/net/pterodactylus/reactor/states/AbstractState.java index e35c933..f8d6f69 100644 --- a/src/main/java/net/pterodactylus/reactor/states/AbstractState.java +++ b/src/main/java/net/pterodactylus/reactor/states/AbstractState.java @@ -27,6 +27,9 @@ import net.pterodactylus.reactor.State; */ public abstract class AbstractState implements State { + /** The time of this state. */ + private final long time; + /** Whether the state was successfully retrieved. */ private final boolean success; @@ -71,6 +74,7 @@ public abstract class AbstractState implements State { * The exception that occured while retrieving the state */ protected AbstractState(boolean success, Throwable exception) { + this.time = System.currentTimeMillis(); this.success = success; this.exception = exception; } @@ -83,6 +87,14 @@ public abstract class AbstractState implements State { * {@inheritDoc} */ @Override + public long time() { + return time; + } + + /** + * {@inheritDoc} + */ + @Override public boolean success() { return success; } -- 2.7.4