mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 03:39:05 +01:00
Replaced Timer with ScheduledExecutorService. #258
This commit is contained in:
@@ -1,23 +1,41 @@
|
||||
package org.briarproject.system;
|
||||
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.api.system.Clock;
|
||||
import org.briarproject.api.system.LocationUtils;
|
||||
import org.briarproject.api.system.SeedProvider;
|
||||
import org.briarproject.api.system.Timer;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@Module
|
||||
public class SystemModule {
|
||||
|
||||
public static class EagerSingletons {
|
||||
@Inject
|
||||
ScheduledExecutorService scheduledExecutorService;
|
||||
}
|
||||
|
||||
private final ScheduledExecutorService scheduler;
|
||||
|
||||
public SystemModule() {
|
||||
scheduler = Executors.newSingleThreadScheduledExecutor();
|
||||
}
|
||||
|
||||
@Provides
|
||||
Clock provideClock() {
|
||||
return new SystemClock();
|
||||
}
|
||||
|
||||
@Provides
|
||||
Timer provideTimer() {
|
||||
return new SystemTimer();
|
||||
@Singleton
|
||||
ScheduledExecutorService provideScheduledExecutorService(
|
||||
LifecycleManager lifecycleManager) {
|
||||
lifecycleManager.registerForShutdown(scheduler);
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
package org.briarproject.system;
|
||||
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.briarproject.api.system.Timer;
|
||||
|
||||
/** Default timer implementation. */
|
||||
public class SystemTimer implements Timer {
|
||||
|
||||
private final java.util.Timer timer = new java.util.Timer(true);
|
||||
|
||||
public void cancel() {
|
||||
timer.cancel();
|
||||
}
|
||||
|
||||
public int purge() {
|
||||
return timer.purge();
|
||||
}
|
||||
|
||||
public void schedule(TimerTask task, long delay) {
|
||||
timer.schedule(task, delay);
|
||||
}
|
||||
|
||||
public void schedule(TimerTask task, long delay, long period) {
|
||||
timer.schedule(task, delay, period);
|
||||
}
|
||||
|
||||
public void scheduleAtFixedRate(TimerTask task, long delay, long period) {
|
||||
timer.scheduleAtFixedRate(task, delay, period);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user