e3cfb866aa06deabf7d202cc7a14ef01d3ff59dc
[rhynodge.git] / src / main / java / net / pterodactylus / reactor / Reaction.java
1 /*
2  * Reactor - Reaction.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.reactor;
19
20 /**
21  * A {@code Reaction} binds together {@link Query}s, {@link Trigger}s, and
22  * {@link Action}s, and it stores the intermediary {@link State}s.
23  *
24  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
25  */
26 public class Reaction {
27
28         /** The query to run. */
29         private final Query query;
30
31         /** The trigger to detect changes. */
32         private final Trigger trigger;
33
34         /** The action to perform. */
35         private final Action action;
36
37         /** The interval in which to run queries (in milliseconds). */
38         private long updateInterval;
39
40         /**
41          * Creates a new reaction.
42          *
43          * @param query
44          *            The query to run
45          * @param trigger
46          *            The trigger to detect changes
47          * @param action
48          *            The action to perform
49          */
50         public Reaction(Query query, Trigger trigger, Action action) {
51                 this.query = query;
52                 this.trigger = trigger;
53                 this.action = action;
54         }
55
56         //
57         // ACCESSORS
58         //
59
60         /**
61          * Returns the query to run.
62          *
63          * @return The query to run
64          */
65         public Query query() {
66                 return query;
67         }
68
69         /**
70          * Returns the trigger to detect changes.
71          *
72          * @return The trigger to detect changes
73          */
74         public Trigger trigger() {
75                 return trigger;
76         }
77
78         /**
79          * Returns the action to perform.
80          *
81          * @return The action to perform
82          */
83         public Action action() {
84                 return action;
85         }
86
87         /**
88          * Returns the update interval of this reaction.
89          *
90          * @return The update interval of this reaction (in milliseconds)
91          */
92         public long updateInterval() {
93                 return updateInterval;
94         }
95
96         /**
97          * Sets the update interval of this reaction.
98          *
99          * @param updateInterval
100          *            The update interval of this reaction (in milliseconds)
101          * @return This reaction
102          */
103         public Reaction setUpdateInterval(long updateInterval) {
104                 this.updateInterval = updateInterval;
105                 return this;
106         }
107
108 }