2 * Reactor - Reaction.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.reactor;
20 import java.util.Collections;
21 import java.util.List;
23 import com.google.common.collect.Lists;
26 * A {@code Reaction} binds together {@link Query}s, {@link Trigger}s, and
27 * {@link Action}s, and it stores the intermediary {@link State}s.
29 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
31 public class Reaction {
33 /** The query to run. */
34 private final Query query;
36 /** The filters to run. */
37 private final List<Filter> filters = Lists.newArrayList();
39 /** The trigger to detect changes. */
40 private final Trigger trigger;
42 /** The action to perform. */
43 private final Action action;
45 /** The interval in which to run queries (in milliseconds). */
46 private long updateInterval;
49 * Creates a new reaction.
54 * The trigger to detect changes
56 * The action to perform
58 public Reaction(Query query, Trigger trigger, Action action) {
59 this(query, Collections.<Filter> emptyList(), trigger, action);
63 * Creates a new reaction.
70 * The trigger to detect changes
72 * The action to perform
74 public Reaction(Query query, List<Filter> filters, Trigger trigger, Action action) {
76 this.filters.addAll(filters);
77 this.trigger = trigger;
86 * Returns the query to run.
88 * @return The query to run
90 public Query query() {
95 * Returns the filters to run.
97 * @return The filters to run
99 public Iterable<Filter> filters() {
104 * Returns the trigger to detect changes.
106 * @return The trigger to detect changes
108 public Trigger trigger() {
113 * Returns the action to perform.
115 * @return The action to perform
117 public Action action() {
122 * Returns the update interval of this reaction.
124 * @return The update interval of this reaction (in milliseconds)
126 public long updateInterval() {
127 return updateInterval;
131 * Sets the update interval of this reaction.
133 * @param updateInterval
134 * The update interval of this reaction (in milliseconds)
135 * @return This reaction
137 public Reaction setUpdateInterval(long updateInterval) {
138 this.updateInterval = updateInterval;