You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@edgent.apache.org by dl...@apache.org on 2016/04/20 20:08:49 UTC
[3/4] incubator-quarks git commit: adjust for feedback
adjust for feedback
Project: http://git-wip-us.apache.org/repos/asf/incubator-quarks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quarks/commit/b7e467d2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quarks/tree/b7e467d2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quarks/diff/b7e467d2
Branch: refs/heads/master
Commit: b7e467d2ac9c3624b867b53f2b38e5ce767c1ba1
Parents: f018ec5
Author: Dale LaBossiere <dl...@us.ibm.com>
Authored: Wed Apr 20 13:27:24 2016 -0400
Committer: Dale LaBossiere <dl...@us.ibm.com>
Committed: Wed Apr 20 13:27:24 2016 -0400
----------------------------------------------------------------------
.../java/quarks/analytics/sensors/Deadtime.java | 59 ++++++++++----------
.../java/quarks/analytics/sensors/Filters.java | 8 ++-
2 files changed, 35 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/b7e467d2/analytics/sensors/src/main/java/quarks/analytics/sensors/Deadtime.java
----------------------------------------------------------------------
diff --git a/analytics/sensors/src/main/java/quarks/analytics/sensors/Deadtime.java b/analytics/sensors/src/main/java/quarks/analytics/sensors/Deadtime.java
index f79516a..debfe1b 100644
--- a/analytics/sensors/src/main/java/quarks/analytics/sensors/Deadtime.java
+++ b/analytics/sensors/src/main/java/quarks/analytics/sensors/Deadtime.java
@@ -7,29 +7,28 @@ import java.util.concurrent.TimeUnit;
import quarks.function.Predicate;
/**
- * A generic "deadtime" {@link Predicate}.
+ * 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.
+ * {@link #test(Object) test()} returns true on its initial call
+ * and then false for any calls occurring during the following deadtime period.
+ * After the end of a deadtime period, the next call to {@code test()}
+ * returns true and a new deadtime period is begun.
* </p><p>
* The deadtime period may be changed while the topology is running
* via {@link #setPeriod(long, TimeUnit)}.
* </p>
*
* @param <T> tuple type
+ * @see Filters#deadtime(quarks.topology.TStream, long, TimeUnit) Filters.deadtime()
*/
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;
+ private long deadtimePeriodMillis;
+ private long lastTrueTimeMillis;
+ private volatile long nextTrueTimeMillis;
/**
- * Create a new deadtime Predicate
+ * Create a new Deadtime Predicate
* <p>
* Same as {@code Deadtime(0, TimeUnit.SECONDS)}
*/
@@ -38,10 +37,10 @@ public class Deadtime<T> implements Predicate<T> {
}
/**
- * Create a new deadtime Predicate
+ * Create a new Deadtime Predicate
* <p>
* The first received tuple is always "accepted".
- * @param deadtimePeriod see {@link #setPeriod(long, TimeUnit) setDeadtimePeriod()}
+ * @param deadtimePeriod see {@link #setPeriod(long, TimeUnit) setPeriod()}
* @param unit {@link TimeUnit} of {@code deadtimePeriod}
*/
public Deadtime(long deadtimePeriod, TimeUnit unit) {
@@ -51,37 +50,40 @@ public class Deadtime<T> implements Predicate<T> {
/**
* 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.
+ * The end of a currently active deadtime period is shortened or extended
+ * to match the new deadtime period specification.
* </p><p>
* The deadtime period behavior is subject to the accuracy
* of the system's {@link System#currentTimeMillis()}.
+ * A period of less than 1ms is equivalent to specifying 0.
* </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.
+ * @param deadtimePeriod the amount of time for {@code test()}
+ * to return false after returning true.
+ * Specify a value of 0 for no deadtime period.
* 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;
+ deadtimePeriodMillis = unit.toMillis(deadtimePeriod);
+ nextTrueTimeMillis = lastTrueTimeMillis + deadtimePeriodMillis;
}
+ /**
+ * Test the deadtime predicate.
+ * @param value ignored
+ * @return false if in a deadtime period, true otherwise
+ */
@Override
public boolean test(T value) {
long now = System.currentTimeMillis();
- if (now < nextPassTimeMillis)
+ if (now < nextTrueTimeMillis)
return false;
- else {
- lastPassTimeMillis = now;
- nextPassTimeMillis = lastPassTimeMillis + deadtimePeriodMillis;
+ else synchronized(this) {
+ lastTrueTimeMillis = now;
+ nextTrueTimeMillis = now + deadtimePeriodMillis;
return true;
}
}
@@ -91,8 +93,7 @@ public class Deadtime<T> implements Predicate<T> {
*/
@Override
public String toString() {
- return "deadtimePeriod="+deadtimePeriod+" "+deadtimeUnit
- + " nextPass after "+new Date(nextPassTimeMillis);
+ return "nextPass after "+new Date(nextTrueTimeMillis);
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/b7e467d2/analytics/sensors/src/main/java/quarks/analytics/sensors/Filters.java
----------------------------------------------------------------------
diff --git a/analytics/sensors/src/main/java/quarks/analytics/sensors/Filters.java b/analytics/sensors/src/main/java/quarks/analytics/sensors/Filters.java
index 28f609b..e274e11 100644
--- a/analytics/sensors/src/main/java/quarks/analytics/sensors/Filters.java
+++ b/analytics/sensors/src/main/java/quarks/analytics/sensors/Filters.java
@@ -116,15 +116,17 @@ public class Filters {
}
/**
- * A filter that discards tuples received during the "deadtime period"
- * following a tuple this is allowed to pass through.
+ * Deadtime filter.
+ *
+ * A filter that discards tuples for a period of time after passing
+ * a tuple.
* <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
+ * Use {@link Deadtime} directly if you need to change the deadtime period
* while the topology is running.
* </p>
* @param stream TStream to add deadtime filter to