X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Freactor%2Fstates%2FAbstractState.java;h=31a1d1873aab991aed761b98236e788a7e9c73e1;hb=fb6252bcb9e3689b3320fb6a0ff2805fd2465e2a;hp=e35c933ec28fbae79ba69acfeeca08ef1adb9c94;hpb=dce4ee6592d33854cb118014f8ff0fc2fd5e1124;p=rhynodge.git diff --git a/src/main/java/net/pterodactylus/reactor/states/AbstractState.java b/src/main/java/net/pterodactylus/reactor/states/AbstractState.java index e35c933..31a1d18 100644 --- a/src/main/java/net/pterodactylus/reactor/states/AbstractState.java +++ b/src/main/java/net/pterodactylus/reactor/states/AbstractState.java @@ -19,20 +19,31 @@ package net.pterodactylus.reactor.states; 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 David ‘Bombe’ Roden */ +@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. */ @@ -71,6 +82,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 +95,14 @@ public abstract class AbstractState implements State { * {@inheritDoc} */ @Override + public long time() { + return time; + } + + /** + * {@inheritDoc} + */ + @Override public boolean success() { return success; } @@ -91,6 +111,22 @@ public abstract class AbstractState implements State { * {@inheritDoc} */ @Override + public int failCount() { + return failCount; + } + + /** + * {@inheritDoc} + */ + @Override + public void setFailCount(int failCount) { + this.failCount = failCount; + } + + /** + * {@inheritDoc} + */ + @Override public Throwable exception() { return exception; }