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/23 04:44:55 UTC

[03/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/c11477ad
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/c11477ad
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/c11477ad

Branch: refs/heads/release-1.5
Commit: c11477adc91adf2cb41ec7268b73de241b109d53
Parents: deba8dc
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 22:42:16 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/c11477ad/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()));
 	}
 }