🐛 Fix broken change detection
[rhynodge.git] / src / main / java / net / pterodactylus / rhynodge / State.java
1 /*
2  * Rhynodge - State.java - Copyright © 2013 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.rhynodge;
19
20 import javax.annotation.Nonnull;
21
22 import net.pterodactylus.rhynodge.output.Output;
23
24 /**
25  * Defines the current state of a system.
26  *
27  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
28  */
29 public interface State {
30
31         /**
32          * Returns the time when this state was retrieved.
33          *
34          * @return The time when this state was retrieved (in millseconds since Jan
35          *         1, 1970 UTC)
36          */
37         long time();
38
39         /**
40          * Whether the state was successfully retrieved. This method should only
41          * return {@code true} if a meaningful result could be retrieved; if e. g. a
42          * service is currently not reachable, this method should return false
43          * instead of emulating success by using empty lists or similar constructs.
44          *
45          * @return {@code true} if the state could be retrieved successfully,
46          *         {@code false} otherwise
47          */
48         boolean success();
49
50         /**
51          * Returns whether this state triggers a change notification. This can
52          * only return {@code true} if this state is the result of a
53          * {@link Merger} merging two states.
54          *
55          * @return {@code true} if this state triggers a change notification,
56          * {@code false} otherwise
57          */
58         default boolean triggered() {
59                 return false;
60         }
61
62         boolean isEmpty();
63
64         /**
65          * Returns the number of consecutive failures. This method only returns a
66          * meaningful number iff {@link #success()} returns {@code false}. If
67          * {@link #success()} returns {@code false} for the first time after
68          * returning {@code true} and this method is called after {@link #success()}
69          * it will return {@code 1}.
70          *
71          * @return The number of consecutive failures
72          */
73         int failCount();
74
75         /**
76          * Sets the fail count of this state.
77          *
78          * @param failCount
79          *            The fail count of this state
80          */
81         void setFailCount(int failCount);
82
83         /**
84          * If {@link #success()} returns {@code false}, this method may return a
85          * {@link Throwable} to give some details for the reason why retrieving the
86          * state was not possible. For example, network-based {@link Query}s might
87          * return any exception that were encountered while communicating with the
88          * remote service.
89          *
90          * @return An exception that occured, may be {@code null} in case an
91          *         exception can not be meaningfully returned
92          */
93         Throwable exception();
94
95         @Nonnull
96         Output output(Reaction reaction);
97
98 }