Add partial emulation for ExecutorService and ScheduledExecutorService

These classes complement existing java.util.concurrent classes and only
non-blocking emulatable parts of the API provided. If missing APIs
needs to provided by subclasses, they should be marked with GwtIncompatible
at the subclass.

Change-Id: Iac5cd927ea76ad743f268793ab2c381aa80ff7aa
Review-Link: https://gwt-review.googlesource.com/#/c/21620/
diff --git a/user/super/com/google/gwt/emul/java/util/concurrent/ExecutorService.java b/user/super/com/google/gwt/emul/java/util/concurrent/ExecutorService.java
new file mode 100644
index 0000000..52cc729
--- /dev/null
+++ b/user/super/com/google/gwt/emul/java/util/concurrent/ExecutorService.java
@@ -0,0 +1,63 @@
+// CHECKSTYLE_OFF: Copyrighted to Guava Authors.
+/*
+ * Copyright (C) 2017 The Guava Authors
+ *
+ * Licensed 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.
+ */
+// CHECKSTYLE_ON
+
+package java.util.concurrent;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Emulation of ExecutorService.
+ */
+public interface ExecutorService extends Executor {
+
+  void shutdown();
+
+  List<Runnable> shutdownNow();
+
+  boolean isShutdown();
+
+  boolean isTerminated();
+
+  // Blocking calls cannot be emulated on web. Subclasses of this class in shared code should mark
+  // their override with @GwtIncompatible.
+  // @GwtIncompatible("blocking")
+  // boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException;
+
+  <T> Future<T> submit(Callable<T> task);
+
+  <T> Future<T> submit(Runnable task, T result);
+
+  Future<?> submit(Runnable task);
+
+  // Even though invokeAll and invokeAy methods below are blocking, they actually block on execution
+  // of the task that is provided hence could be emulated by directly executing them.
+
+  <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
+      throws InterruptedException;
+
+  <T> List<Future<T>> invokeAll(
+      Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
+      throws InterruptedException;
+
+  <T> T invokeAny(Collection<? extends Callable<T>> tasks)
+      throws InterruptedException, ExecutionException;
+
+  <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
+      throws InterruptedException, ExecutionException, TimeoutException;
+}
diff --git a/user/super/com/google/gwt/emul/java/util/concurrent/ScheduledExecutorService.java b/user/super/com/google/gwt/emul/java/util/concurrent/ScheduledExecutorService.java
new file mode 100644
index 0000000..a8e48af
--- /dev/null
+++ b/user/super/com/google/gwt/emul/java/util/concurrent/ScheduledExecutorService.java
@@ -0,0 +1,35 @@
+// CHECKSTYLE_OFF: Copyrighted to Guava Authors.
+/*
+ * Copyright (C) 2017 The Guava Authors
+ *
+ * Licensed 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.
+ */
+// CHECKSTYLE_ON
+
+package java.util.concurrent;
+
+/**
+ * Emulation of ScheduledExecutorService.
+ */
+public interface ScheduledExecutorService extends ExecutorService {
+
+  ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit);
+
+  <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit);
+
+  ScheduledFuture<?> scheduleAtFixedRate(
+      Runnable command, long initialDelay, long period, TimeUnit unit);
+
+  ScheduledFuture<?> scheduleWithFixedDelay(
+      Runnable command, long initialDelay, long delay, TimeUnit unit);
+}