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/14 22:05:00 UTC

[GitHub] incubator-quarks pull request: [QUARKS-124] [WIP] [REVIEW] add Dea...

GitHub user dlaboss opened a pull request:

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

    [QUARKS-124] [WIP] [REVIEW] add Deadtime filter

    TODO Deadtime fvt, add support of PeriodicMXBean for control

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

    $ git pull https://github.com/dlaboss/incubator-quarks quarks-124-add-deadtime-filter

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

    https://github.com/apache/incubator-quarks/pull/91.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 #91
    
----
commit d4a1338478fe3483766f0a518851a95d7d24348b
Author: Dale LaBossiere <dl...@us.ibm.com>
Date:   2016-04-14T19:46:00Z

    [QUARKS-124] [WIP] [REVIEW] add Deadtime filter
    
    TODO Deadtime fvt, add support of PeriodicMXBean for control

----


---
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-124] [REVIEW] add Deadtime ...

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

    https://github.com/apache/incubator-quarks/pull/91#discussion_r60430928
  
    --- Diff: analytics/sensors/src/main/java/quarks/analytics/sensors/Deadtime.java ---
    @@ -0,0 +1,98 @@
    +package quarks.analytics.sensors;
    +
    +import java.util.Date;
    +import java.util.Objects;
    +import java.util.concurrent.TimeUnit;
    +
    +import quarks.function.Predicate;
    +
    +/**
    + * A generic "deadtime" {@link Predicate}.
    + * <p>
    + * After accepting a tuple ({@link #test(Object) test()} returns true),
    + * any tuples received during the "deadtime" period are rejected
    + * ({@link #test(Object) test()} returns false).
    + * Then the next tuple is accepted and a new deadtime period begun.
    + * </p><p>
    + * The deadtime period may be changed while the topology is running
    + * via {@link #setPeriod(long, TimeUnit)}.
    + * </p>
    + *
    + * @param <T> tuple type
    + */
    +public class Deadtime<T> implements Predicate<T> {
    +    private static final long serialVersionUID = 1L;
    +    private transient long deadtimePeriod;
    +    private transient TimeUnit deadtimeUnit;
    +    private transient long deadtimePeriodMillis;
    +    private transient long lastPassTimeMillis;
    +    private transient long nextPassTimeMillis;
    +
    +    /**
    +     * Create a new deadtime Predicate
    +     * <p>
    +     * Same as {@code Deadtime(0, TimeUnit.SECONDS)}
    +     */
    +    public Deadtime() {
    +        setPeriod(0, TimeUnit.SECONDS);
    +    }
    +    
    +    /**
    +     * Create a new deadtime Predicate
    +     * <p>
    +     * The first received tuple is always "accepted".
    +     * @param deadtimePeriod see {@link #setPeriod(long, TimeUnit) setDeadtimePeriod()}
    +     * @param unit {@link TimeUnit} of {@code deadtimePeriod}
    +     */
    +    public Deadtime(long deadtimePeriod, TimeUnit unit) {
    +        setPeriod(deadtimePeriod, unit);
    +    }
    +    
    +    /**
    +     * Set the deadtime period
    +     * <p>
    +     * The next time to enable a tuple to be accepted is
    +     * immediately adjusted relative to the last accepted tuple time.
    +     * </p><p>
    +     * The deadtime period behavior is subject to the accuracy
    +     * of the system's {@link System#currentTimeMillis()}.
    +     * </p>
    +     * @param deadtimePeriod the amount of to time to reject
    +     *        tuples received after the last passed tuple.
    +     *        Specify a value of 0 to pass all received tuples.
    +     *        Must be >= 0.
    +     *        A period of 0 is used if the specified period is less than 1ms.
    +     * @param unit {@link TimeUnit} of {@code deadtimePeriod}
    +     */
    +    public synchronized void setPeriod(long deadtimePeriod, TimeUnit unit) {
    +        if (deadtimePeriod < 0)
    +            throw new IllegalArgumentException("deadtimePeriod");
    +        Objects.requireNonNull(unit, "unit");
    +        this.deadtimePeriod = deadtimePeriod;
    +        this.deadtimeUnit = unit;
    +        this.deadtimePeriodMillis = unit.toMillis(deadtimePeriod);
    +        nextPassTimeMillis = lastPassTimeMillis + deadtimePeriodMillis;
    +    }
    +
    +    @Override
    +    public boolean test(T value) {
    +        long now = System.currentTimeMillis(); 
    +        if (now < nextPassTimeMillis)
    +            return false;
    +        else {
    +            lastPassTimeMillis = now;
    +            nextPassTimeMillis = lastPassTimeMillis + deadtimePeriodMillis;
    --- End diff --
    
    reworked


---
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-124] [REVIEW] add Deadtime ...

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/91#discussion_r60328712
  
    --- Diff: analytics/sensors/src/main/java/quarks/analytics/sensors/Deadtime.java ---
    @@ -0,0 +1,98 @@
    +package quarks.analytics.sensors;
    +
    +import java.util.Date;
    +import java.util.Objects;
    +import java.util.concurrent.TimeUnit;
    +
    +import quarks.function.Predicate;
    +
    +/**
    + * A generic "deadtime" {@link Predicate}.
    --- End diff --
    
    Saw this with another class, why is "deadtime" in quotes?
    
    Maybe:
    
    Predicate that discards values for a period of time after passing a value.


---
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-124] [REVIEW] add Deadtime ...

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/91#discussion_r60329187
  
    --- Diff: analytics/sensors/src/main/java/quarks/analytics/sensors/Filters.java ---
    @@ -114,4 +114,27 @@ private Filters() {}
     
             return stream.filter(new Deadband<>(value, inBand));
         }
    +    
    +    /**
    +     * A filter that discards tuples received during the "deadtime period"
    --- End diff --
    
    Not English! and too long for the summary that is seen in Javadoc.
    
    Maybe just:
    
    Deadtime filter.
    
    (c.f. Deadband filter)
    
    Then have the following sentences describe what it does.
    



---
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-124] [REVIEW] add Deadtime ...

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

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


---
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-124] [REVIEW] add Deadtime ...

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

    https://github.com/apache/incubator-quarks/pull/91#discussion_r60425714
  
    --- Diff: analytics/sensors/src/main/java/quarks/analytics/sensors/Filters.java ---
    @@ -114,4 +114,27 @@ private Filters() {}
     
             return stream.filter(new Deadband<>(value, inBand));
         }
    +    
    +    /**
    +     * A filter that discards tuples received during the "deadtime period"
    --- End diff --
    
    reworked


---
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-124] [REVIEW] add Deadtime ...

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

    https://github.com/apache/incubator-quarks/pull/91#discussion_r60439481
  
    --- Diff: analytics/sensors/src/main/java/quarks/analytics/sensors/Deadtime.java ---
    @@ -0,0 +1,98 @@
    +package quarks.analytics.sensors;
    +
    +import java.util.Date;
    +import java.util.Objects;
    +import java.util.concurrent.TimeUnit;
    +
    +import quarks.function.Predicate;
    +
    +/**
    + * A generic "deadtime" {@link Predicate}.
    + * <p>
    + * After accepting a tuple ({@link #test(Object) test()} returns true),
    + * any tuples received during the "deadtime" period are rejected
    + * ({@link #test(Object) test()} returns false).
    + * Then the next tuple is accepted and a new deadtime period begun.
    + * </p><p>
    + * The deadtime period may be changed while the topology is running
    + * via {@link #setPeriod(long, TimeUnit)}.
    + * </p>
    + *
    + * @param <T> tuple type
    + */
    +public class Deadtime<T> implements Predicate<T> {
    +    private static final long serialVersionUID = 1L;
    +    private transient long deadtimePeriod;
    +    private transient TimeUnit deadtimeUnit;
    +    private transient long deadtimePeriodMillis;
    +    private transient long lastPassTimeMillis;
    +    private transient long nextPassTimeMillis;
    +
    +    /**
    +     * Create a new deadtime Predicate
    +     * <p>
    +     * Same as {@code Deadtime(0, TimeUnit.SECONDS)}
    +     */
    +    public Deadtime() {
    +        setPeriod(0, TimeUnit.SECONDS);
    +    }
    +    
    +    /**
    +     * Create a new deadtime Predicate
    +     * <p>
    +     * The first received tuple is always "accepted".
    +     * @param deadtimePeriod see {@link #setPeriod(long, TimeUnit) setDeadtimePeriod()}
    +     * @param unit {@link TimeUnit} of {@code deadtimePeriod}
    +     */
    +    public Deadtime(long deadtimePeriod, TimeUnit unit) {
    +        setPeriod(deadtimePeriod, unit);
    +    }
    +    
    +    /**
    +     * Set the deadtime period
    +     * <p>
    +     * The next time to enable a tuple to be accepted is
    +     * immediately adjusted relative to the last accepted tuple time.
    +     * </p><p>
    +     * The deadtime period behavior is subject to the accuracy
    +     * of the system's {@link System#currentTimeMillis()}.
    +     * </p>
    +     * @param deadtimePeriod the amount of to time to reject
    +     *        tuples received after the last passed tuple.
    +     *        Specify a value of 0 to pass all received tuples.
    +     *        Must be >= 0.
    +     *        A period of 0 is used if the specified period is less than 1ms.
    +     * @param unit {@link TimeUnit} of {@code deadtimePeriod}
    +     */
    +    public synchronized void setPeriod(long deadtimePeriod, TimeUnit unit) {
    +        if (deadtimePeriod < 0)
    +            throw new IllegalArgumentException("deadtimePeriod");
    +        Objects.requireNonNull(unit, "unit");
    --- End diff --
    
    Using requireNonNull with a msg is better for the caller than just receiving a "naked" NPE a few lines down, right?  Using it also enforces the requirement even if later the code below it doesn't end up referencing ``unit``.


---
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-124] [REVIEW] add Deadtime ...

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/91#discussion_r60328414
  
    --- Diff: analytics/sensors/src/main/java/quarks/analytics/sensors/Deadtime.java ---
    @@ -0,0 +1,98 @@
    +package quarks.analytics.sensors;
    +
    +import java.util.Date;
    +import java.util.Objects;
    +import java.util.concurrent.TimeUnit;
    +
    +import quarks.function.Predicate;
    +
    +/**
    + * A generic "deadtime" {@link Predicate}.
    + * <p>
    + * After accepting a tuple ({@link #test(Object) test()} returns true),
    + * any tuples received during the "deadtime" period are rejected
    + * ({@link #test(Object) test()} returns false).
    + * Then the next tuple is accepted and a new deadtime period begun.
    + * </p><p>
    + * The deadtime period may be changed while the topology is running
    + * via {@link #setPeriod(long, TimeUnit)}.
    + * </p>
    + *
    + * @param <T> tuple type
    + */
    +public class Deadtime<T> implements Predicate<T> {
    +    private static final long serialVersionUID = 1L;
    +    private transient long deadtimePeriod;
    +    private transient TimeUnit deadtimeUnit;
    +    private transient long deadtimePeriodMillis;
    +    private transient long lastPassTimeMillis;
    +    private transient long nextPassTimeMillis;
    +
    +    /**
    +     * Create a new deadtime Predicate
    +     * <p>
    +     * Same as {@code Deadtime(0, TimeUnit.SECONDS)}
    +     */
    +    public Deadtime() {
    +        setPeriod(0, TimeUnit.SECONDS);
    +    }
    +    
    +    /**
    +     * Create a new deadtime Predicate
    +     * <p>
    +     * The first received tuple is always "accepted".
    +     * @param deadtimePeriod see {@link #setPeriod(long, TimeUnit) setDeadtimePeriod()}
    +     * @param unit {@link TimeUnit} of {@code deadtimePeriod}
    +     */
    +    public Deadtime(long deadtimePeriod, TimeUnit unit) {
    +        setPeriod(deadtimePeriod, unit);
    +    }
    +    
    +    /**
    +     * Set the deadtime period
    +     * <p>
    +     * The next time to enable a tuple to be accepted is
    +     * immediately adjusted relative to the last accepted tuple time.
    +     * </p><p>
    +     * The deadtime period behavior is subject to the accuracy
    +     * of the system's {@link System#currentTimeMillis()}.
    +     * </p>
    +     * @param deadtimePeriod the amount of to time to reject
    +     *        tuples received after the last passed tuple.
    +     *        Specify a value of 0 to pass all received tuples.
    +     *        Must be >= 0.
    +     *        A period of 0 is used if the specified period is less than 1ms.
    +     * @param unit {@link TimeUnit} of {@code deadtimePeriod}
    +     */
    +    public synchronized void setPeriod(long deadtimePeriod, TimeUnit unit) {
    +        if (deadtimePeriod < 0)
    +            throw new IllegalArgumentException("deadtimePeriod");
    +        Objects.requireNonNull(unit, "unit");
    --- End diff --
    
    technically not needed


---
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-124] [REVIEW] add Deadtime ...

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/91#discussion_r60328538
  
    --- Diff: analytics/sensors/src/main/java/quarks/analytics/sensors/Deadtime.java ---
    @@ -0,0 +1,98 @@
    +package quarks.analytics.sensors;
    +
    +import java.util.Date;
    +import java.util.Objects;
    +import java.util.concurrent.TimeUnit;
    +
    +import quarks.function.Predicate;
    +
    +/**
    + * A generic "deadtime" {@link Predicate}.
    + * <p>
    + * After accepting a tuple ({@link #test(Object) test()} returns true),
    + * any tuples received during the "deadtime" period are rejected
    + * ({@link #test(Object) test()} returns false).
    + * Then the next tuple is accepted and a new deadtime period begun.
    + * </p><p>
    + * The deadtime period may be changed while the topology is running
    + * via {@link #setPeriod(long, TimeUnit)}.
    + * </p>
    + *
    + * @param <T> tuple type
    + */
    +public class Deadtime<T> implements Predicate<T> {
    +    private static final long serialVersionUID = 1L;
    +    private transient long deadtimePeriod;
    +    private transient TimeUnit deadtimeUnit;
    +    private transient long deadtimePeriodMillis;
    --- End diff --
    
    the same info is being stored twice, it seems to be only for the toString() method, is it worth it?


---
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-124] [REVIEW] add Deadtime ...

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

    https://github.com/apache/incubator-quarks/pull/91#discussion_r60444555
  
    --- Diff: analytics/sensors/src/main/java/quarks/analytics/sensors/Deadtime.java ---
    @@ -0,0 +1,98 @@
    +package quarks.analytics.sensors;
    +
    +import java.util.Date;
    +import java.util.Objects;
    +import java.util.concurrent.TimeUnit;
    +
    +import quarks.function.Predicate;
    +
    +/**
    + * A generic "deadtime" {@link Predicate}.
    + * <p>
    + * After accepting a tuple ({@link #test(Object) test()} returns true),
    + * any tuples received during the "deadtime" period are rejected
    + * ({@link #test(Object) test()} returns false).
    + * Then the next tuple is accepted and a new deadtime period begun.
    + * </p><p>
    + * The deadtime period may be changed while the topology is running
    + * via {@link #setPeriod(long, TimeUnit)}.
    + * </p>
    + *
    + * @param <T> tuple type
    + */
    +public class Deadtime<T> implements Predicate<T> {
    +    private static final long serialVersionUID = 1L;
    +    private transient long deadtimePeriod;
    +    private transient TimeUnit deadtimeUnit;
    +    private transient long deadtimePeriodMillis;
    --- End diff --
    
    I'll toss deadtime{Period,Unit}


---
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-124] [REVIEW] add Deadtime ...

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

    https://github.com/apache/incubator-quarks/pull/91#discussion_r60430813
  
    --- Diff: analytics/sensors/src/main/java/quarks/analytics/sensors/Deadtime.java ---
    @@ -0,0 +1,98 @@
    +package quarks.analytics.sensors;
    +
    +import java.util.Date;
    +import java.util.Objects;
    +import java.util.concurrent.TimeUnit;
    +
    +import quarks.function.Predicate;
    +
    +/**
    + * A generic "deadtime" {@link Predicate}.
    --- End diff --
    
    reworked


---
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-124] [REVIEW] add Deadtime ...

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

    https://github.com/apache/incubator-quarks/pull/91#discussion_r60451209
  
    --- Diff: analytics/sensors/src/main/java/quarks/analytics/sensors/Deadtime.java ---
    @@ -0,0 +1,98 @@
    +package quarks.analytics.sensors;
    +
    +import java.util.Date;
    +import java.util.Objects;
    +import java.util.concurrent.TimeUnit;
    +
    +import quarks.function.Predicate;
    +
    +/**
    + * A generic "deadtime" {@link Predicate}.
    + * <p>
    + * After accepting a tuple ({@link #test(Object) test()} returns true),
    + * any tuples received during the "deadtime" period are rejected
    + * ({@link #test(Object) test()} returns false).
    + * Then the next tuple is accepted and a new deadtime period begun.
    + * </p><p>
    + * The deadtime period may be changed while the topology is running
    + * via {@link #setPeriod(long, TimeUnit)}.
    + * </p>
    + *
    + * @param <T> tuple type
    + */
    +public class Deadtime<T> implements Predicate<T> {
    +    private static final long serialVersionUID = 1L;
    +    private transient long deadtimePeriod;
    --- End diff --
    
    thanks!  meant to type volatile.


---
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-124] [REVIEW] add Deadtime ...

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/91#discussion_r60327979
  
    --- Diff: analytics/sensors/src/main/java/quarks/analytics/sensors/Deadtime.java ---
    @@ -0,0 +1,98 @@
    +package quarks.analytics.sensors;
    +
    +import java.util.Date;
    +import java.util.Objects;
    +import java.util.concurrent.TimeUnit;
    +
    +import quarks.function.Predicate;
    +
    +/**
    + * A generic "deadtime" {@link Predicate}.
    + * <p>
    + * After accepting a tuple ({@link #test(Object) test()} returns true),
    + * any tuples received during the "deadtime" period are rejected
    + * ({@link #test(Object) test()} returns false).
    + * Then the next tuple is accepted and a new deadtime period begun.
    + * </p><p>
    + * The deadtime period may be changed while the topology is running
    + * via {@link #setPeriod(long, TimeUnit)}.
    + * </p>
    + *
    + * @param <T> tuple type
    + */
    +public class Deadtime<T> implements Predicate<T> {
    +    private static final long serialVersionUID = 1L;
    +    private transient long deadtimePeriod;
    --- End diff --
    
    Why are these fields transient?


---
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-124] [REVIEW] add Deadtime ...

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/91#discussion_r60328840
  
    --- Diff: analytics/sensors/src/main/java/quarks/analytics/sensors/Deadtime.java ---
    @@ -0,0 +1,98 @@
    +package quarks.analytics.sensors;
    +
    +import java.util.Date;
    +import java.util.Objects;
    +import java.util.concurrent.TimeUnit;
    +
    +import quarks.function.Predicate;
    +
    +/**
    + * A generic "deadtime" {@link Predicate}.
    + * <p>
    + * After accepting a tuple ({@link #test(Object) test()} returns true),
    + * any tuples received during the "deadtime" period are rejected
    + * ({@link #test(Object) test()} returns false).
    + * Then the next tuple is accepted and a new deadtime period begun.
    + * </p><p>
    + * The deadtime period may be changed while the topology is running
    + * via {@link #setPeriod(long, TimeUnit)}.
    + * </p>
    + *
    + * @param <T> tuple type
    + */
    +public class Deadtime<T> implements Predicate<T> {
    +    private static final long serialVersionUID = 1L;
    +    private transient long deadtimePeriod;
    +    private transient TimeUnit deadtimeUnit;
    +    private transient long deadtimePeriodMillis;
    +    private transient long lastPassTimeMillis;
    +    private transient long nextPassTimeMillis;
    +
    +    /**
    +     * Create a new deadtime Predicate
    +     * <p>
    +     * Same as {@code Deadtime(0, TimeUnit.SECONDS)}
    +     */
    +    public Deadtime() {
    +        setPeriod(0, TimeUnit.SECONDS);
    +    }
    +    
    +    /**
    +     * Create a new deadtime Predicate
    +     * <p>
    +     * The first received tuple is always "accepted".
    +     * @param deadtimePeriod see {@link #setPeriod(long, TimeUnit) setDeadtimePeriod()}
    +     * @param unit {@link TimeUnit} of {@code deadtimePeriod}
    +     */
    +    public Deadtime(long deadtimePeriod, TimeUnit unit) {
    +        setPeriod(deadtimePeriod, unit);
    +    }
    +    
    +    /**
    +     * Set the deadtime period
    +     * <p>
    +     * The next time to enable a tuple to be accepted is
    +     * immediately adjusted relative to the last accepted tuple time.
    +     * </p><p>
    +     * The deadtime period behavior is subject to the accuracy
    +     * of the system's {@link System#currentTimeMillis()}.
    +     * </p>
    +     * @param deadtimePeriod the amount of to time to reject
    +     *        tuples received after the last passed tuple.
    +     *        Specify a value of 0 to pass all received tuples.
    +     *        Must be >= 0.
    +     *        A period of 0 is used if the specified period is less than 1ms.
    +     * @param unit {@link TimeUnit} of {@code deadtimePeriod}
    +     */
    +    public synchronized void setPeriod(long deadtimePeriod, TimeUnit unit) {
    +        if (deadtimePeriod < 0)
    +            throw new IllegalArgumentException("deadtimePeriod");
    +        Objects.requireNonNull(unit, "unit");
    +        this.deadtimePeriod = deadtimePeriod;
    +        this.deadtimeUnit = unit;
    +        this.deadtimePeriodMillis = unit.toMillis(deadtimePeriod);
    +        nextPassTimeMillis = lastPassTimeMillis + deadtimePeriodMillis;
    +    }
    +
    +    @Override
    +    public boolean test(T value) {
    +        long now = System.currentTimeMillis(); 
    +        if (now < nextPassTimeMillis)
    +            return false;
    +        else {
    +            lastPassTimeMillis = now;
    +            nextPassTimeMillis = lastPassTimeMillis + deadtimePeriodMillis;
    --- End diff --
    
    might be clearer (and faster) it this was:
    
    ` nextPassTimeMillis = now + deadtimePeriodMillis;`


---
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-124] [REVIEW] add Deadtime ...

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/91#discussion_r60329452
  
    --- Diff: analytics/sensors/src/main/java/quarks/analytics/sensors/Filters.java ---
    @@ -114,4 +114,27 @@ private Filters() {}
     
             return stream.filter(new Deadband<>(value, inBand));
         }
    +    
    +    /**
    +     * A filter that discards tuples received during the "deadtime period"
    +     * following a tuple this is allowed to pass through.
    +     * <p>
    +     * E.g., for a deadtime period of 30 minutes, after letting a tuple
    +     * pass through, any tuples received during the next 30 minutes are
    +     * filtered out.  Then the next arriving tuple is passed through and
    +     * a new deadtime period is begun.
    +     * </p><p>
    +     * See {@link Deadtime} for information about changing the deadtime period
    --- End diff --
    
    Is this for the future, as there's no mechanism for the caller of this method to change the period?


---
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-124] [REVIEW] add Deadtime ...

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

    https://github.com/apache/incubator-quarks/pull/91#discussion_r60424304
  
    --- Diff: analytics/sensors/src/main/java/quarks/analytics/sensors/Filters.java ---
    @@ -114,4 +114,27 @@ private Filters() {}
     
             return stream.filter(new Deadband<>(value, inBand));
         }
    +    
    +    /**
    +     * A filter that discards tuples received during the "deadtime period"
    +     * following a tuple this is allowed to pass through.
    +     * <p>
    +     * E.g., for a deadtime period of 30 minutes, after letting a tuple
    +     * pass through, any tuples received during the next 30 minutes are
    +     * filtered out.  Then the next arriving tuple is passed through and
    +     * a new deadtime period is begun.
    +     * </p><p>
    +     * See {@link Deadtime} for information about changing the deadtime period
    --- End diff --
    
    reworked


---
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.
---