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
*/
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;
* The exception that occured while retrieving the state
*/
protected AbstractState(boolean success, Throwable exception) {
+ this.time = System.currentTimeMillis();
this.success = success;
this.exception = exception;
}
* {@inheritDoc}
*/
@Override
+ public long time() {
+ return time;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean success() {
return success;
}