[
https://issues.apache.org/jira/browse/TAJO-1385?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14365089#comment-14365089
]
ASF GitHub Bot commented on TAJO-1385:
--------------------------------------
Github user navis commented on a diff in the pull request:
https://github.com/apache/tajo/pull/407#discussion_r26570436
--- Diff: tajo-common/src/main/java/org/apache/tajo/util/BasicFuture.java
---
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.util;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+public class BasicFuture<T> implements Future<T> {
+
+ private T result;
+ private Exception exception;
+
+ @Override
+ public boolean cancel(boolean mayInterruptIfRunning) {
+ return false;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return false;
+ }
+
+ @Override
+ public synchronized boolean isDone() {
+ return result != null || exception != null;
+ }
+
+ @Override
+ public synchronized T get() throws InterruptedException,
ExecutionException {
+ while (result == null && exception == null) {
+ wait();
+ }
+ if (exception != null) {
+ throw new ExecutionException(exception);
+ }
+ return result;
+ }
+
+ @Override
+ public synchronized T get(long timeout, TimeUnit unit)
+ throws InterruptedException, ExecutionException, TimeoutException {
+ long remain = unit.toMillis(timeout);
+ long prev = System.currentTimeMillis();
+ while (result == null && exception == null && remain > 0) {
+ wait(remain);
+ long current = System.currentTimeMillis();
+ remain -= current - prev;
+ prev = current;
+ }
+ if (exception != null) {
+ throw new ExecutionException(exception);
+ }
+ if (result != null) {
+ return result;
+ }
+ throw new TimeoutException("Timed-out");
+ }
+
+ public synchronized void done(T result, Exception ex) {
--- End diff --
Ok, I'll separate done method into two.
> Remove locking on RMContext
> ---------------------------
>
> Key: TAJO-1385
> URL: https://issues.apache.org/jira/browse/TAJO-1385
> Project: Tajo
> Issue Type: Improvement
> Reporter: Navis
> Assignee: Navis
> Priority: Trivial
>
> Seemed not necessary.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)