keith-turner commented on a change in pull request #402: ACCUMULO-4615: Updated 
get status for thread safety and with a per-task timeout
URL: https://github.com/apache/accumulo/pull/402#discussion_r177163927
 
 

 ##########
 File path: 
server/master/src/main/java/org/apache/accumulo/master/TimeoutTaskExecutor.java
 ##########
 @@ -0,0 +1,235 @@
+/*
+ * 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.accumulo.master;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import javax.annotation.concurrent.NotThreadSafe;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Runs one or more tasks with a timeout per task (instead of a timeout for 
the entire pool). Uses callbacks to invoke functions on successful, timed out, 
or
+ * tasks that error.
+ *
+ * This class uses an underlying fixed thread pool to schedule the submitted 
tasks. Once a task is submitted, the desired end time for the task is recorded 
and
+ * used to determine the timeout for the task's associated {@link Future}.
+ *
+ * The timeout will not be exact as the start time is recorded prior to 
submitting the {@link Callable}. This may result in an effective timeout that is
+ * slightly smaller than expected. The timeout used during initialization 
should be adjusted accordingly.
+ *
+ * The {@link TimeoutTaskExecutor} itself is not a thread-safe class. Only a 
single thread should submit tasks and complete them.
+ *
+ * @param <T> The return type for the corresponding Callable.
+ * @param <C> The type of Callable submitted to this executor.
+ */
+@NotThreadSafe
+public class TimeoutTaskExecutor<T, C extends Callable<T>> implements 
AutoCloseable {
+
+  private final static Logger log = 
LoggerFactory.getLogger(TimeoutTaskExecutor.class);
+
+  private final long timeout;
+  private final ExecutorService executorService;
+  private final BlockingQueue<WrappedTask> startedTasks;
 
 Review comment:
   I like how you solved the busy wait problem by adding this queue.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to