DefaultScheduledExecutorService.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Google Inc.
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
00015  */
00016 
00017 package org.ros.concurrent;
00018 
00019 import com.google.common.collect.Lists;
00020 
00021 import java.util.Collection;
00022 import java.util.List;
00023 import java.util.concurrent.Callable;
00024 import java.util.concurrent.ExecutionException;
00025 import java.util.concurrent.Executor;
00026 import java.util.concurrent.ExecutorService;
00027 import java.util.concurrent.Executors;
00028 import java.util.concurrent.Future;
00029 import java.util.concurrent.ScheduledExecutorService;
00030 import java.util.concurrent.ScheduledFuture;
00031 import java.util.concurrent.ThreadPoolExecutor;
00032 import java.util.concurrent.TimeUnit;
00033 import java.util.concurrent.TimeoutException;
00034 
00045 public class DefaultScheduledExecutorService implements ScheduledExecutorService {
00046 
00047   private static final int CORE_POOL_SIZE = 11;
00048 
00049   private final ExecutorService executorService;
00050   private final ScheduledExecutorService scheduledExecutorService;
00051 
00052   public DefaultScheduledExecutorService() {
00053     this(Executors.newCachedThreadPool());
00054   }
00055 
00061   public DefaultScheduledExecutorService(ExecutorService executorService) {
00062     this(executorService, Executors.newScheduledThreadPool(CORE_POOL_SIZE));
00063   }
00064 
00071   public DefaultScheduledExecutorService(ExecutorService executorService,
00072       ScheduledExecutorService scheduledExecutorService) {
00073     this.executorService = executorService;
00074     this.scheduledExecutorService = scheduledExecutorService;
00075   }
00076 
00077   @Override
00078   public void shutdown() {
00079     executorService.shutdown();
00080     scheduledExecutorService.shutdown();
00081   }
00082 
00083   @Override
00084   public List<Runnable> shutdownNow() {
00085     List<Runnable> combined = Lists.newArrayList();
00086     combined.addAll(executorService.shutdownNow());
00087     combined.addAll(scheduledExecutorService.shutdownNow());
00088     return combined;
00089   }
00090 
00091   @Override
00092   public boolean isShutdown() {
00093     return executorService.isShutdown() && scheduledExecutorService.isShutdown();
00094   }
00095 
00096   @Override
00097   public boolean isTerminated() {
00098     return executorService.isTerminated() && scheduledExecutorService.isTerminated();
00099   }
00100 
00109   @Override
00110   public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
00111     boolean executorServiceResult = executorService.awaitTermination(timeout, unit);
00112     boolean scheduledExecutorServiceResult =
00113         scheduledExecutorService.awaitTermination(timeout, unit);
00114     return executorServiceResult && scheduledExecutorServiceResult;
00115   }
00116 
00117   @Override
00118   public <T> Future<T> submit(Callable<T> task) {
00119     return executorService.submit(task);
00120   }
00121 
00122   @Override
00123   public <T> Future<T> submit(Runnable task, T result) {
00124     return executorService.submit(task, result);
00125   }
00126 
00127   @Override
00128   public Future<?> submit(Runnable task) {
00129     return executorService.submit(task);
00130   }
00131 
00132   @Override
00133   public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
00134       throws InterruptedException {
00135     return executorService.invokeAll(tasks);
00136   }
00137 
00138   @Override
00139   public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout,
00140       TimeUnit unit) throws InterruptedException {
00141     return executorService.invokeAll(tasks, timeout, unit);
00142   }
00143 
00144   @Override
00145   public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException,
00146       ExecutionException {
00147     return executorService.invokeAny(tasks);
00148   }
00149 
00150   @Override
00151   public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
00152       throws InterruptedException, ExecutionException, TimeoutException {
00153     return executorService.invokeAny(tasks, timeout, unit);
00154   }
00155 
00156   @Override
00157   public void execute(Runnable command) {
00158     executorService.execute(command);
00159   }
00160 
00161   @Override
00162   public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
00163     return scheduledExecutorService.schedule(command, delay, unit);
00164   }
00165 
00166   @Override
00167   public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
00168     return scheduledExecutorService.schedule(callable, delay, unit);
00169   }
00170 
00171   @Override
00172   public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period,
00173       TimeUnit unit) {
00174     return scheduledExecutorService.scheduleAtFixedRate(command, initialDelay, period, unit);
00175   }
00176 
00177   @Override
00178   public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay,
00179       TimeUnit unit) {
00180     return scheduledExecutorService.scheduleWithFixedDelay(command, initialDelay, delay, unit);
00181   }
00182 }


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49