You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by se...@apache.org on 2018/04/22 20:40:40 UTC
[04/17] flink git commit: [hotfix] [core] Cleanup Deadline
[hotfix] [core] Cleanup Deadline
Gets rid of unnecessary boxing and multiplications/divisions that Duration does internally.
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/f5b7637d
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/f5b7637d
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/f5b7637d
Branch: refs/heads/master
Commit: f5b7637d1252325e2916c47a459674100658269a
Parents: 76ad79c
Author: Stephan Ewen <se...@apache.org>
Authored: Tue Apr 17 18:55:29 2018 +0200
Committer: Stephan Ewen <se...@apache.org>
Committed: Sun Apr 22 16:28:34 2018 +0200
----------------------------------------------------------------------
.../apache/flink/api/common/time/Deadline.java | 23 +++++++++++++++-----
1 file changed, 17 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/f5b7637d/flink-core/src/main/java/org/apache/flink/api/common/time/Deadline.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/time/Deadline.java b/flink-core/src/main/java/org/apache/flink/api/common/time/Deadline.java
index 042c1e1..1c3a82e 100644
--- a/flink-core/src/main/java/org/apache/flink/api/common/time/Deadline.java
+++ b/flink-core/src/main/java/org/apache/flink/api/common/time/Deadline.java
@@ -31,12 +31,12 @@ public class Deadline {
/** The deadline, relative to {@link System#nanoTime()}. */
private final long timeNanos;
- private Deadline(Duration time) {
- this.timeNanos = time.toNanos();
+ private Deadline(long deadline) {
+ this.timeNanos = deadline;
}
public Deadline plus(Duration other) {
- return new Deadline(Duration.ofNanos(timeNanos).plus(other));
+ return new Deadline(Math.addExact(timeNanos, other.toNanos()));
}
/**
@@ -44,7 +44,7 @@ public class Deadline {
* has passed.
*/
public Duration timeLeft() {
- return Duration.ofNanos(timeNanos).minus(Duration.ofNanos(System.nanoTime()));
+ return Duration.ofNanos(Math.subtractExact(timeNanos, System.nanoTime()));
}
/**
@@ -58,14 +58,25 @@ public class Deadline {
* Determines whether the deadline is in the past, i.e. whether the time left is negative.
*/
public boolean isOverdue() {
- return timeNanos - System.nanoTime() < 0;
+ return timeNanos < System.nanoTime();
}
+ // ------------------------------------------------------------------------
+ // Creating Deadlines
+ // ------------------------------------------------------------------------
+
/**
* Constructs a {@link Deadline} that has now as the deadline. Use this and then extend via
* {@link #plus(Duration)} to specify a deadline in the future.
*/
public static Deadline now() {
- return new Deadline(Duration.ofNanos(System.nanoTime()));
+ return new Deadline(System.nanoTime());
+ }
+
+ /**
+ * Constructs a Deadline that is a given duration after now.
+ */
+ public static Deadline fromNow(Duration duration) {
+ return new Deadline(Math.addExact(System.nanoTime(), duration.toNanos()));
}
}