import net.pterodactylus.reactor.State;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+
/**
* Abstract implementation of a {@link State} that knows about the basic
* attributes of a {@link State}.
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
+@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class")
public abstract class AbstractState implements State {
+ /** The time of this state. */
+ @JsonProperty
+ private final long time;
+
/** Whether the state was successfully retrieved. */
private final boolean success;
/** The optional exception that occured while retrieving the state. */
private final Throwable exception;
+ /** The number of consecutive failures. */
+ private int failCount;
+
/**
* Creates a new successful 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;
}
* {@inheritDoc}
*/
@Override
+ public long time() {
+ return time;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean success() {
return success;
}
* {@inheritDoc}
*/
@Override
+ public int failCount() {
+ return failCount;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setFailCount(int failCount) {
+ this.failCount = failCount;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public Throwable exception() {
return exception;
}