🔀 Merge branch 'website/epic-games' into next
[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         boolean triggered();
59
60         /**
61          * Sets whether this state will trigger a notification.
62          */
63         void trigger();
64
65         boolean isEmpty();
66
67         /**
68          * Returns the number of consecutive failures. This method only returns a
69          * meaningful number iff {@link #success()} returns {@code false}. If
70          * {@link #success()} returns {@code false} for the first time after
71          * returning {@code true} and this method is called after {@link #success()}
72          * it will return {@code 1}.
73          *
74          * @return The number of consecutive failures
75          */
76         int failCount();
77
78         /**
79          * Sets the fail count of this state.
80          *
81          * @param failCount
82          *            The fail count of this state
83          */
84         void setFailCount(int failCount);
85
86         /**
87          * If {@link #success()} returns {@code false}, this method may return a
88          * {@link Throwable} to give some details for the reason why retrieving the
89          * state was not possible. For example, network-based {@link Query}s might
90          * return any exception that were encountered while communicating with the
91          * remote service.
92          *
93          * @return An exception that occured, may be {@code null} in case an
94          *         exception can not be meaningfully returned
95          */
96         Throwable exception();
97
98         @Nonnull
99         Output output(Reaction reaction);
100
101 }