1 /*
2  * Copyright (C) 2006 The Guava Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.common.util.concurrent;
18 
19 import static com.google.common.base.Preconditions.checkNotNull;
20 
21 import com.google.common.annotations.Beta;
22 
23 import java.util.concurrent.Callable;
24 import java.util.concurrent.TimeUnit;
25 
26 /**
27  * A TimeLimiter implementation which actually does not attempt to limit time
28  * at all.  This may be desirable to use in some unit tests.  More importantly,
29  * attempting to debug a call which is time-limited would be extremely annoying,
30  * so this gives you a time-limiter you can easily swap in for your real
31  * time-limiter while you're debugging.
32  *
33  * @author Kevin Bourrillion
34  * @since 1.0
35  */
36 @Beta
37 public final class FakeTimeLimiter implements TimeLimiter {
38   @Override
newProxy(T target, Class<T> interfaceType, long timeoutDuration, TimeUnit timeoutUnit)39   public <T> T newProxy(T target, Class<T> interfaceType, long timeoutDuration,
40       TimeUnit timeoutUnit) {
41     checkNotNull(target);
42     checkNotNull(interfaceType);
43     checkNotNull(timeoutUnit);
44     return target; // ha ha
45   }
46 
47   @Override
callWithTimeout(Callable<T> callable, long timeoutDuration, TimeUnit timeoutUnit, boolean amInterruptible)48   public <T> T callWithTimeout(Callable<T> callable, long timeoutDuration,
49       TimeUnit timeoutUnit, boolean amInterruptible) throws Exception {
50     checkNotNull(timeoutUnit);
51     return callable.call(); // fooled you
52   }
53 }
54