Example usage for com.google.common.util.concurrent ListeningScheduledExecutorService ListeningScheduledExecutorService

List of usage examples for com.google.common.util.concurrent ListeningScheduledExecutorService ListeningScheduledExecutorService

Introduction

In this page you can find the example usage for com.google.common.util.concurrent ListeningScheduledExecutorService ListeningScheduledExecutorService.

Prototype

ListeningScheduledExecutorService

Source Link

Usage

From source file:com.tinspx.util.concurrent.LimitedExecutorService.java

/**
 * Returns a {@code ListeningScheduledExecutorService} that forwards all
 * submitted tasks to this {@code LimitedExecutorService} using the 
 * specified {@code key}.//from w  w  w  . j  a v  a  2  s . co  m
 * 
 * @see #withDefaultKey(Object)
 */
public ListeningScheduledExecutorService withKey(@NonNull final Object key) {
    return new ListeningScheduledExecutorService() {
        @Override
        public ListenableScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
            return LimitedExecutorService.this.schedule(key, command, delay, unit);
        }

        @Override
        public <V> ListenableScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
            return LimitedExecutorService.this.schedule(key, callable, delay, unit);
        }

        @Override
        public ListenableScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay,
                long period, TimeUnit unit) {
            return LimitedExecutorService.this.scheduleAtFixedRate(key, command, initialDelay, period, unit);
        }

        @Override
        public ListenableScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay,
                long delay, TimeUnit unit) {
            return LimitedExecutorService.this.scheduleWithFixedDelay(key, command, initialDelay, delay, unit);
        }

        @Override
        public void shutdown() {
            LimitedExecutorService.this.shutdown();
        }

        @Override
        public List<Runnable> shutdownNow() {
            return LimitedExecutorService.this.shutdownNow();
        }

        @Override
        public boolean isShutdown() {
            return LimitedExecutorService.this.isShutdown();
        }

        @Override
        public boolean isTerminated() {
            return LimitedExecutorService.this.isTerminated();
        }

        @Override
        public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
            return LimitedExecutorService.this.awaitTermination(timeout, unit);
        }

        @Override
        public <T> ListenableFuture<T> submit(Callable<T> task) {
            return LimitedExecutorService.this.submit(key, task);
        }

        @Override
        public <T> ListenableFuture<T> submit(Runnable task, @Nullable T result) {
            return LimitedExecutorService.this.submit(key, task, result);
        }

        @Override
        public ListenableFuture<?> submit(Runnable task) {
            return LimitedExecutorService.this.submit(key, task);
        }

        @Override
        public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
                throws InterruptedException {
            return LimitedExecutorService.this.invokeAll(key, tasks);
        }

        @Override
        public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout,
                TimeUnit unit) throws InterruptedException {
            return LimitedExecutorService.this.invokeAll(key, tasks, timeout, unit);
        }

        @Override
        public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
                throws InterruptedException, ExecutionException {
            return LimitedExecutorService.this.invokeAny(key, tasks);
        }

        @Override
        public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
                throws InterruptedException, ExecutionException, TimeoutException {
            return LimitedExecutorService.this.invokeAny(key, tasks, timeout, unit);
        }

        @Override
        public void execute(Runnable command) {
            LimitedExecutorService.this.execute(key, command);
        }

        @Override
        public String toString() {
            return String.format("%s with key [%s]", LimitedExecutorService.this, key);
        }
    };
}