Wrap scheduler in an interface.

This commit is contained in:
akwizgran
2020-07-30 16:03:31 +01:00
parent 280f87065e
commit 86641741a0
22 changed files with 213 additions and 136 deletions

View File

@@ -1,25 +0,0 @@
package org.briarproject.bramble.api.system;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Annotation for injecting a scheduled executor service
* that can be used to schedule the execution of tasks.
* <p>
* The service should <b>only</b> be used for running tasks on other executors
* at scheduled times.
* No significant work should be run by the service itself!
*/
@Qualifier
@Target({FIELD, METHOD, PARAMETER})
@Retention(RUNTIME)
public @interface Scheduler {
}

View File

@@ -0,0 +1,34 @@
package org.briarproject.bramble.api.system;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
/**
* A service that can be used to schedule the execution of tasks.
* <p>
* The service should only be used for running tasks on other executors
* at scheduled times. No significant work should be run by the service itself.
*/
@NotNullByDefault
public interface TaskScheduler {
/**
* See {@link ScheduledExecutorService#schedule(Runnable, long, TimeUnit)}.
*/
ScheduledFuture<?> schedule(Runnable task, long delay, TimeUnit unit);
/**
* See {@link ScheduledExecutorService#scheduleAtFixedRate(Runnable, long, long, TimeUnit)}.
*/
ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long delay,
long interval, TimeUnit unit);
/**
* See {@link ScheduledExecutorService#scheduleWithFixedDelay(Runnable, long, long, TimeUnit)}.
*/
ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long delay,
long interval, TimeUnit unit);
}