edgent-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddebrunner <...@git.apache.org>
Subject [GitHub] incubator-quarks pull request: [QUARKS-124] [REVIEW] add Deadtime ...
Date Tue, 19 Apr 2016 23:15:09 GMT
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.
---

Mime
View raw message