2 * Rhynodge - AbstractState.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.rhynodge.states;
20 import net.pterodactylus.rhynodge.State;
22 import com.fasterxml.jackson.annotation.JsonProperty;
23 import com.fasterxml.jackson.annotation.JsonTypeInfo;
26 * Abstract implementation of a {@link State} that knows about the basic
27 * attributes of a {@link State}.
29 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
31 @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class")
32 public abstract class AbstractState implements State {
34 /** The time of this state. */
36 private final long time;
38 /** Whether the state was successfully retrieved. */
39 private final boolean success;
41 /** The optional exception that occured while retrieving the state. */
42 private final Throwable exception;
44 /** The number of consecutive failures. */
46 private int failCount;
49 * Creates a new successful state.
51 protected AbstractState() {
56 * Creates a new state.
59 * {@code true} if the state is successful, {@code false}
62 protected AbstractState(boolean success) {
67 * Creates a new non-successful state with the given exception.
70 * The exception that occured while retrieving the state
72 protected AbstractState(Throwable exception) {
73 this(false, exception);
77 * Creates a new state.
80 * {@code true} if the state is successful, {@code false}
83 * The exception that occured while retrieving the state
85 protected AbstractState(boolean success, Throwable exception) {
86 this.time = System.currentTimeMillis();
87 this.success = success;
88 this.exception = exception;
107 public boolean success() {
115 public int failCount() {
123 public void setFailCount(int failCount) {
124 this.failCount = failCount;
131 public Throwable exception() {