• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.xtremelabs.robolectric.util;
2 
3 import com.xtremelabs.robolectric.Robolectric;
4 
5 import java.util.Collection;
6 import java.util.List;
7 import java.util.concurrent.Callable;
8 import java.util.concurrent.ExecutionException;
9 import java.util.concurrent.ExecutorService;
10 import java.util.concurrent.Future;
11 import java.util.concurrent.FutureTask;
12 import java.util.concurrent.TimeUnit;
13 import java.util.concurrent.TimeoutException;
14 
15 public class RobolectricBackgroundExecutorService implements ExecutorService {
16     @Override
shutdown()17     public void shutdown() {
18         throw new UnsupportedOperationException();
19     }
20 
21     @Override
shutdownNow()22     public List<Runnable> shutdownNow() {
23         throw new UnsupportedOperationException();
24     }
25 
26     @Override
isShutdown()27     public boolean isShutdown() {
28         throw new UnsupportedOperationException();
29     }
30 
31     @Override
isTerminated()32     public boolean isTerminated() {
33         throw new UnsupportedOperationException();
34     }
35 
36     @Override
awaitTermination(long l, TimeUnit timeUnit)37     public boolean awaitTermination(long l, TimeUnit timeUnit) throws InterruptedException {
38         throw new UnsupportedOperationException();
39     }
40 
41     @Override
submit(Callable<T> tCallable)42     public <T> Future<T> submit(Callable<T> tCallable) {
43         return schedule(new FutureTask<T>(tCallable));
44     }
45 
46     @Override
submit(Runnable runnable, T t)47     public <T> Future<T> submit(Runnable runnable, T t) {
48         return schedule(new FutureTask<T>(runnable, t));
49     }
50 
51     @Override
submit(Runnable runnable)52     public Future<?> submit(Runnable runnable) {
53         return submit(runnable, null);
54     }
55 
schedule(final FutureTask<T> futureTask)56     private <T> Future<T> schedule(final FutureTask<T> futureTask) {
57         Robolectric.getShadowApplication().getBackgroundScheduler().post(new Runnable() {
58             @Override
59             public void run() {
60                 futureTask.run();
61             }
62         });
63 
64         return futureTask;
65     }
66 
67     @Override
invokeAll(Collection<? extends Callable<T>> callables)68     public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> callables) throws InterruptedException {
69         throw new UnsupportedOperationException();
70     }
71 
72     @Override
invokeAll(Collection<? extends Callable<T>> callables, long l, TimeUnit timeUnit)73     public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> callables, long l, TimeUnit timeUnit) throws InterruptedException {
74         throw new UnsupportedOperationException();
75     }
76 
77     @Override
invokeAny(Collection<? extends Callable<T>> callables)78     public <T> T invokeAny(Collection<? extends Callable<T>> callables) throws InterruptedException, ExecutionException {
79         throw new UnsupportedOperationException();
80     }
81 
82     @Override
invokeAny(Collection<? extends Callable<T>> callables, long l, TimeUnit timeUnit)83     public <T> T invokeAny(Collection<? extends Callable<T>> callables, long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
84         throw new UnsupportedOperationException();
85     }
86 
87     @Override
execute(Runnable runnable)88     public void execute(Runnable runnable) {
89         submit(runnable);
90     }
91 }
92 
93