1 /* 2 * Copyright (C) 2019 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 java.util.concurrent.Executor; 20 import java.util.concurrent.TimeUnit; 21 22 /** 23 * A sub-class of {@link Executor} that allows scheduling commands to execute periodically. 24 */ 25 public interface RepeatableExecutor extends Executor { 26 27 /** 28 * Execute supplied Runnable on the Executors thread after initial delay, and subsequently with 29 * the given delay between the termination of one execution and the commencement of the next. 30 * 31 * Each invocation of the supplied Runnable will be scheduled after the previous invocation 32 * completes. For example, if you schedule the Runnable with a 60 second delay, and the Runnable 33 * itself takes 1 second, the effective delay will be 61 seconds between each invocation. 34 * 35 * See {@link java.util.concurrent.ScheduledExecutorService#scheduleRepeatedly(Runnable, 36 * long, long)} 37 * 38 * @return A Runnable that, when run, removes the supplied argument from the Executor queue. 39 */ executeRepeatedly(Runnable r, long initialDelayMillis, long delayMillis)40 default Runnable executeRepeatedly(Runnable r, long initialDelayMillis, long delayMillis) { 41 return executeRepeatedly(r, initialDelayMillis, delayMillis, TimeUnit.MILLISECONDS); 42 } 43 44 /** 45 * Execute supplied Runnable on the Executors thread after initial delay, and subsequently with 46 * the given delay between the termination of one execution and the commencement of the next.. 47 * 48 * See {@link java.util.concurrent.ScheduledExecutorService#scheduleRepeatedly(Runnable, 49 * long, long)} 50 * 51 * @return A Runnable that, when run, removes the supplied argument from the Executor queue. 52 */ executeRepeatedly(Runnable r, long initialDelay, long delay, TimeUnit unit)53 Runnable executeRepeatedly(Runnable r, long initialDelay, long delay, TimeUnit unit); 54 } 55