001package com.pi4j.concurrent; 002 003/* 004 * #%L 005 * ********************************************************************** 006 * ORGANIZATION : Pi4J 007 * PROJECT : Pi4J :: Java Library (Core) 008 * FILENAME : ScheduledExecutorServiceWrapper.java 009 * 010 * This file is part of the Pi4J project. More information about 011 * this project can be found here: http://www.pi4j.com/ 012 * ********************************************************************** 013 * %% 014 * Copyright (C) 2012 - 2013 Pi4J 015 * %% 016 * Licensed under the Apache License, Version 2.0 (the "License"); 017 * you may not use this file except in compliance with the License. 018 * You may obtain a copy of the License at 019 * 020 * http://www.apache.org/licenses/LICENSE-2.0 021 * 022 * Unless required by applicable law or agreed to in writing, software 023 * distributed under the License is distributed on an "AS IS" BASIS, 024 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 025 * See the License for the specific language governing permissions and 026 * limitations under the License. 027 * #L% 028 */ 029 030 031import java.util.Collection; 032import java.util.List; 033import java.util.concurrent.Callable; 034import java.util.concurrent.ExecutionException; 035import java.util.concurrent.Future; 036import java.util.concurrent.ScheduledExecutorService; 037import java.util.concurrent.ScheduledFuture; 038import java.util.concurrent.TimeUnit; 039import java.util.concurrent.TimeoutException; 040 041public class ScheduledExecutorServiceWrapper implements ScheduledExecutorService { 042 043 private ScheduledExecutorService service; 044 045 /** 046 * Default constructor 047 * @param service 048 */ 049 public ScheduledExecutorServiceWrapper(ScheduledExecutorService service) { 050 this.service = service; 051 } 052 053 @Override 054 public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { 055 return service.awaitTermination(timeout, unit); 056 } 057 058 @Override 059 public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException { 060 return service.invokeAll(tasks); 061 } 062 063 @Override 064 public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) 065 throws InterruptedException { 066 return service.invokeAll(tasks, timeout, unit); 067 } 068 069 @Override 070 public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException { 071 return service.invokeAny(tasks); 072 } 073 074 @Override 075 public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) 076 throws InterruptedException, ExecutionException, TimeoutException { 077 return service.invokeAny(tasks, timeout, unit); 078 } 079 080 @Override 081 public boolean isShutdown() { 082 return service.isShutdown(); 083 } 084 085 @Override 086 public boolean isTerminated() { 087 return service.isShutdown(); 088 } 089 090 @Override 091 public void shutdown() { 092 throw new UnsupportedOperationException("This scheduled executor service can only be shutdown by Pi4J."); 093 } 094 095 @Override 096 public List<Runnable> shutdownNow() { 097 throw new UnsupportedOperationException("This scheduled executor service can only be shutdown by Pi4J."); 098 } 099 100 @Override 101 public <T> Future<T> submit(Callable<T> task) { 102 return service.submit(task); 103 } 104 105 @Override 106 public Future<?> submit(Runnable task) { 107 return service.submit(task); 108 } 109 110 @Override 111 public <T> Future<T> submit(Runnable task, T result) { 112 return service.submit(task, result); 113 } 114 115 @Override 116 public void execute(Runnable command) { 117 service.execute(command); 118 } 119 120 @Override 121 public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { 122 return service.schedule(command, delay, unit); 123 } 124 125 @Override 126 public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) { 127 return service.schedule(callable, delay, unit); 128 } 129 130 @Override 131 public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, 132 TimeUnit unit) { 133 return service.scheduleAtFixedRate(command, initialDelay, period, unit); 134 } 135 136 @Override 137 public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, 138 long delay, TimeUnit unit) { 139 return service.scheduleWithFixedDelay(command, initialDelay, delay, unit); 140 } 141}