• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
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.android.systemui.util.concurrency;
18 
19 import android.os.Handler;
20 import android.os.Looper;
21 
22 import java.util.concurrent.Executor;
23 
24 /**
25  * Factory for building Executors running on a unique named thread.
26  *
27  * Use this when our generally available @Main, @Background, @UiBackground, @LongRunning, or
28  * similar global qualifiers don't quite cut it. Note that the methods here can create entirely new
29  * threads; there are no singletons here. Use responsibly.
30  */
31 public interface ThreadFactory {
32     /**
33      * Returns a {@link Looper} running on a named thread.
34      *
35      * The thread is implicitly started and may be left running indefinitely, depending on the
36      * implementation. Assume this is the case and use responsibly.
37      */
buildLooperOnNewThread(String threadName)38     Looper buildLooperOnNewThread(String threadName);
39 
40     /**
41      * Returns a {@link Handler} running on a named thread.
42      *
43      * The thread is implicitly started and may be left running indefinitely, depending on the
44      * implementation. Assume this is the case and use responsibly.
45      */
buildHandlerOnNewThread(String threadName)46     Handler buildHandlerOnNewThread(String threadName);
47 
48     /**
49      * Return an {@link java.util.concurrent.Executor} running on a named thread.
50      *
51      * The thread is implicitly started and may be left running indefinitely, depending on the
52      * implementation. Assume this is the case and use responsibly.
53      **/
buildExecutorOnNewThread(String threadName)54     Executor buildExecutorOnNewThread(String threadName);
55 
56     /**
57      * Return an {@link DelayableExecutor} running on a named thread.
58      *
59      * The thread is implicitly started and may be left running indefinitely, depending on the
60      * implementation. Assume this is the case and use responsibly.
61      **/
buildDelayableExecutorOnNewThread(String threadName)62     DelayableExecutor buildDelayableExecutorOnNewThread(String threadName);
63 
64     /**
65      * Return an {@link DelayableExecutor} running on the given HandlerThread.
66      **/
buildDelayableExecutorOnHandler(Handler handler)67     DelayableExecutor buildDelayableExecutorOnHandler(Handler handler);
68 
69     /**
70      * Return an {@link DelayableExecutor} running the given Looper
71      **/
buildDelayableExecutorOnLooper(Looper looper)72     DelayableExecutor buildDelayableExecutorOnLooper(Looper looper);
73 }
74