You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@edgent.apache.org by dlaboss <gi...@git.apache.org> on 2016/04/19 20:03:47 UTC

[GitHub] incubator-quarks pull request: [QUARKS-150] add Valve Predicate

GitHub user dlaboss opened a pull request:

    https://github.com/apache/incubator-quarks/pull/93

    [QUARKS-150] add Valve Predicate

    Q: quarks.analytics.sensors or quarks.topology.plumbing?
    
    Note: there's no benefit to a Filters.valve(State initialState) because in order for the app to change the state of the valve the app needs to new the Valve itself so that it can eventually do valve.setState(newState).  That could change if Valve supports a control mbean but that's a more general discussion for functions an mbeans.
    
    TODO unit test and recipe

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/dlaboss/incubator-quarks quarks-150-addValve

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-quarks/pull/93.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #93
    
----

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-quarks pull request: [QUARKS-150] add Valve Predicate

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-quarks/pull/93


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-quarks pull request: [QUARKS-150] add Valve Predicate

Posted by ddebrunner <gi...@git.apache.org>.
Github user ddebrunner commented on a diff in the pull request:

    https://github.com/apache/incubator-quarks/pull/93#discussion_r60313992
  
    --- 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.
    --- End diff --
    
    maybe discards or ignores tuples, it doesn't really 'reject' them.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-quarks pull request: [QUARKS-150] add Valve Predicate

Posted by ddebrunner <gi...@git.apache.org>.
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.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---