[NO ISSUE][UTIL] Span, ThrowingAction enhancements
Change-Id: I884f0f1c517d39eafbbfbef78fe62f85803c0a8a
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/8923
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mblow@apache.org>
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/Span.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/Span.java
index bc33e6d..a9d8ec8 100644
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/Span.java
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/Span.java
@@ -18,12 +18,80 @@
*/
package org.apache.hyracks.util;
+import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
public class Span {
+
+ public static final Span INFINITE = new Span() {
+ @Override
+ public void reset() {
+ //no-op
+ }
+
+ @Override
+ public long getSpanNanos() {
+ return Long.MAX_VALUE;
+ }
+
+ @Override
+ public long getSpan(TimeUnit unit) {
+ return Long.MAX_VALUE;
+ }
+
+ @Override
+ public boolean elapsed() {
+ return false;
+ }
+
+ @Override
+ public long elapsed(TimeUnit unit) {
+ return -1;
+ }
+
+ @Override
+ public void sleep() throws InterruptedException {
+ new Semaphore(0).acquire();
+ }
+
+ @Override
+ public void sleep(long sleep, TimeUnit unit) throws InterruptedException {
+ unit.sleep(sleep);
+ }
+
+ @Override
+ public long remaining(TimeUnit unit) {
+ return Long.MAX_VALUE;
+ }
+
+ @Override
+ public void wait(Object monitor) throws InterruptedException {
+ monitor.wait();
+ }
+
+ @Override
+ public void loopUntilExhausted(ThrowingAction action) throws Exception {
+ super.loopUntilExhausted(action);
+ }
+
+ @Override
+ public void loopUntilExhausted(ThrowingAction action, long delay, TimeUnit delayUnit) throws Exception {
+ super.loopUntilExhausted(action, delay, delayUnit);
+ }
+
+ @Override
+ public String toString() {
+ return "<INFINITY>";
+ }
+ };
+
private final long spanNanos;
private volatile long startNanos;
+ private Span() {
+ spanNanos = startNanos = -1;
+ }
+
private Span(long span, TimeUnit unit) {
spanNanos = unit.toNanos(span);
reset();
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ThrowingAction.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ThrowingAction.java
index d675179..136ce30 100644
--- a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ThrowingAction.java
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/ThrowingAction.java
@@ -21,4 +21,11 @@
@FunctionalInterface
public interface ThrowingAction {
void run() throws Exception; // NOSONAR
+
+ static ComputingAction<Void> asComputingAction(ThrowingAction action) {
+ return () -> {
+ action.run();
+ return null;
+ };
+ }
}