[
https://issues.apache.org/jira/browse/QUARKS-150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15248680#comment-15248680
]
ASF GitHub Bot commented on QUARKS-150:
---------------------------------------
Github user ddebrunner commented on a diff in the pull request:
https://github.com/apache/incubator-quarks/pull/93#discussion_r60314136
--- Diff:
analytics/sensors/src/main/java/quarks/analytics/sensors/Valve.java ---
@@ -0,0 +1,91 @@
+package quarks.analytics.sensors;
+
+import java.util.Objects;
+
+import quarks.function.Predicate;
+
+/**
+ * A generic "valve" {@link Predicate}.
+ * <p>
+ * A valve predicate accepts tuples when its state is {@link State#OPEN},
+ * otherwise it rejects tuples.
+ * </p><p>
+ * A valve is typically used to dynamically control whether or not
+ * some downstream tuple processing is enabled. A decision to change the
+ * state of the valve may be a result of local analytics or an external
+ * command.
+ * <br>
+ * E.g., a Valve might be used to control whether or not logging
+ * of tuples is enabled.
+ * <pre>{@code
+ * TStream<JsonObject> stream = ...;
+ *
+ * Valve<JsonObject> valve = new Valve<>(Valve.State.CLOSED);
+ * stream.filter(valve).sink(someTupleLoggingConsumer);
+ *
+ * // from some analytic or device command handler...
+ * valve.setState(Valve.State.OPEN);
+ * }</pre>
+ * </p>
+ *
+ * @param <T> tuple type
+ */
+public class Valve<T> implements Predicate<T> {
+ private static final long serialVersionUID = 1L;
+ private transient State state = State.OPEN;
+
+ /**
+ * The valve state.
+ */
+ public enum State {
--- End diff --
Is there value to an enum as opposed to just a boolean? It seems to be
extra (minimal) footprint for little benefit.
> add Valve Predicate
> -------------------
>
> Key: QUARKS-150
> URL: https://issues.apache.org/jira/browse/QUARKS-150
> Project: Quarks
> Issue Type: New Feature
> Reporter: Dale LaBossiere
> Assignee: Dale LaBossiere
>
> A Valve Predicate accepts tuples when its state is {@link State#OPEN},
> otherwise it rejects tuples.
> A valve is typically used to dynamically control whether or not
> some downstream tuple processing is enabled. A decision to change the
> state of the valve may be a result of local analytics or an external
> device command.
> [ fwiw, this is known as a 'Switch' utility operator in IBM Streams ]
> Maybe this belongs in quarks.topology.plumbing/PlumbingStreams, not
> quarks.analytics.sensors/Filters like Deadband and Deadtime, since there's
> not really much "analytic" about it?
> E.g., a Valve might be used to control whether or not logging of tuples is
> enabled.
> ```
> TStream<JsonObject> stream = ...;
>
> Valve<JsonObject> valve = new Valve<>(Valve.State.CLOSED);
> stream.filter(valve).sink(someTupleLoggingConsumer);
> // from some analytic or device command handler...
> valve.setState(Valve.State.OPEN);
> ```
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)