mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 21:59:54 +01:00
Wrap scheduler in an interface.
This commit is contained in:
@@ -15,10 +15,9 @@ import org.briarproject.bramble.api.network.NetworkStatus;
|
|||||||
import org.briarproject.bramble.api.network.event.NetworkStatusEvent;
|
import org.briarproject.bramble.api.network.event.NetworkStatusEvent;
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.system.Scheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
@@ -50,7 +49,7 @@ class AndroidNetworkManager implements NetworkManager, Service {
|
|||||||
private static final String WIFI_AP_STATE_CHANGED_ACTION =
|
private static final String WIFI_AP_STATE_CHANGED_ACTION =
|
||||||
"android.net.wifi.WIFI_AP_STATE_CHANGED";
|
"android.net.wifi.WIFI_AP_STATE_CHANGED";
|
||||||
|
|
||||||
private final ScheduledExecutorService scheduler;
|
private final TaskScheduler scheduler;
|
||||||
private final EventBus eventBus;
|
private final EventBus eventBus;
|
||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
private final AtomicReference<Future<?>> connectivityCheck =
|
private final AtomicReference<Future<?>> connectivityCheck =
|
||||||
@@ -60,8 +59,8 @@ class AndroidNetworkManager implements NetworkManager, Service {
|
|||||||
private volatile BroadcastReceiver networkStateReceiver = null;
|
private volatile BroadcastReceiver networkStateReceiver = null;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AndroidNetworkManager(@Scheduler ScheduledExecutorService scheduler,
|
AndroidNetworkManager(TaskScheduler scheduler, EventBus eventBus,
|
||||||
EventBus eventBus, Application app) {
|
Application app) {
|
||||||
this.scheduler = scheduler;
|
this.scheduler = scheduler;
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.appContext = app.getApplicationContext();
|
this.appContext = app.getApplicationContext();
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import org.briarproject.bramble.api.plugin.PluginException;
|
|||||||
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexTransportConnection;
|
||||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
import org.briarproject.bramble.util.AndroidUtils;
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
import org.briarproject.bramble.util.IoUtils;
|
import org.briarproject.bramble.util.IoUtils;
|
||||||
|
|
||||||
@@ -31,7 +32,6 @@ import java.util.concurrent.BlockingQueue;
|
|||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -67,7 +67,7 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
|
|||||||
|
|
||||||
private static final int MAX_DISCOVERY_MS = 10_000;
|
private static final int MAX_DISCOVERY_MS = 10_000;
|
||||||
|
|
||||||
private final ScheduledExecutorService scheduler;
|
private final TaskScheduler scheduler;
|
||||||
private final AndroidExecutor androidExecutor;
|
private final AndroidExecutor androidExecutor;
|
||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
@@ -79,10 +79,16 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
|
|||||||
private volatile BluetoothAdapter adapter = null;
|
private volatile BluetoothAdapter adapter = null;
|
||||||
|
|
||||||
AndroidBluetoothPlugin(BluetoothConnectionLimiter connectionLimiter,
|
AndroidBluetoothPlugin(BluetoothConnectionLimiter connectionLimiter,
|
||||||
TimeoutMonitor timeoutMonitor, Executor ioExecutor,
|
TimeoutMonitor timeoutMonitor,
|
||||||
SecureRandom secureRandom, ScheduledExecutorService scheduler,
|
Executor ioExecutor,
|
||||||
AndroidExecutor androidExecutor, Context appContext, Clock clock,
|
SecureRandom secureRandom,
|
||||||
Backoff backoff, PluginCallback callback, int maxLatency,
|
TaskScheduler scheduler,
|
||||||
|
AndroidExecutor androidExecutor,
|
||||||
|
Context appContext,
|
||||||
|
Clock clock,
|
||||||
|
Backoff backoff,
|
||||||
|
PluginCallback callback,
|
||||||
|
int maxLatency,
|
||||||
int maxIdleTime) {
|
int maxIdleTime) {
|
||||||
super(connectionLimiter, timeoutMonitor, ioExecutor, secureRandom,
|
super(connectionLimiter, timeoutMonitor, ioExecutor, secureRandom,
|
||||||
backoff, callback, maxLatency, maxIdleTime);
|
backoff, callback, maxLatency, maxIdleTime);
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ import org.briarproject.bramble.api.plugin.duplex.DuplexPlugin;
|
|||||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
|
|||||||
private static final double BACKOFF_BASE = 1.2;
|
private static final double BACKOFF_BASE = 1.2;
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor;
|
||||||
private final ScheduledExecutorService scheduler;
|
private final TaskScheduler scheduler;
|
||||||
private final AndroidExecutor androidExecutor;
|
private final AndroidExecutor androidExecutor;
|
||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
private final SecureRandom secureRandom;
|
private final SecureRandom secureRandom;
|
||||||
@@ -43,10 +43,14 @@ public class AndroidBluetoothPluginFactory implements DuplexPluginFactory {
|
|||||||
private final BackoffFactory backoffFactory;
|
private final BackoffFactory backoffFactory;
|
||||||
|
|
||||||
public AndroidBluetoothPluginFactory(Executor ioExecutor,
|
public AndroidBluetoothPluginFactory(Executor ioExecutor,
|
||||||
ScheduledExecutorService scheduler,
|
TaskScheduler scheduler,
|
||||||
AndroidExecutor androidExecutor, Context appContext,
|
AndroidExecutor androidExecutor,
|
||||||
SecureRandom secureRandom, EventBus eventBus, Clock clock,
|
Context appContext,
|
||||||
TimeoutMonitor timeoutMonitor, BackoffFactory backoffFactory) {
|
SecureRandom secureRandom,
|
||||||
|
EventBus eventBus,
|
||||||
|
Clock clock,
|
||||||
|
TimeoutMonitor timeoutMonitor,
|
||||||
|
BackoffFactory backoffFactory) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
this.scheduler = scheduler;
|
this.scheduler = scheduler;
|
||||||
this.androidExecutor = androidExecutor;
|
this.androidExecutor = androidExecutor;
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ import org.briarproject.bramble.api.io.TimeoutMonitor;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.plugin.Plugin;
|
import org.briarproject.bramble.api.plugin.Plugin;
|
||||||
import org.briarproject.bramble.api.plugin.duplex.AbstractDuplexTransportConnection;
|
import org.briarproject.bramble.api.plugin.duplex.AbstractDuplexTransportConnection;
|
||||||
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
import org.briarproject.bramble.util.RenewableWakeLock;
|
import org.briarproject.bramble.util.RenewableWakeLock;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
|
|
||||||
import static android.content.Context.POWER_SERVICE;
|
import static android.content.Context.POWER_SERVICE;
|
||||||
import static android.os.PowerManager.PARTIAL_WAKE_LOCK;
|
import static android.os.PowerManager.PARTIAL_WAKE_LOCK;
|
||||||
@@ -34,9 +34,10 @@ class AndroidBluetoothTransportConnection
|
|||||||
|
|
||||||
AndroidBluetoothTransportConnection(Plugin plugin,
|
AndroidBluetoothTransportConnection(Plugin plugin,
|
||||||
BluetoothConnectionLimiter connectionLimiter,
|
BluetoothConnectionLimiter connectionLimiter,
|
||||||
TimeoutMonitor timeoutMonitor, Context appContext,
|
TimeoutMonitor timeoutMonitor,
|
||||||
ScheduledExecutorService scheduler, BluetoothSocket socket)
|
Context appContext,
|
||||||
throws IOException {
|
TaskScheduler scheduler,
|
||||||
|
BluetoothSocket socket) throws IOException {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
this.connectionLimiter = connectionLimiter;
|
this.connectionLimiter = connectionLimiter;
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ import org.briarproject.bramble.api.plugin.PluginCallback;
|
|||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.LocationUtils;
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
import org.briarproject.bramble.api.system.ResourceProvider;
|
import org.briarproject.bramble.api.system.ResourceProvider;
|
||||||
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
import org.briarproject.bramble.util.RenewableWakeLock;
|
import org.briarproject.bramble.util.RenewableWakeLock;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
|
|
||||||
import javax.net.SocketFactory;
|
import javax.net.SocketFactory;
|
||||||
|
|
||||||
@@ -36,18 +36,26 @@ class AndroidTorPlugin extends TorPlugin {
|
|||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
private final RenewableWakeLock wakeLock;
|
private final RenewableWakeLock wakeLock;
|
||||||
|
|
||||||
AndroidTorPlugin(Executor ioExecutor, ScheduledExecutorService scheduler,
|
AndroidTorPlugin(Executor ioExecutor,
|
||||||
Context appContext, NetworkManager networkManager,
|
TaskScheduler scheduler,
|
||||||
LocationUtils locationUtils, SocketFactory torSocketFactory,
|
Context appContext,
|
||||||
Clock clock, ResourceProvider resourceProvider,
|
NetworkManager networkManager,
|
||||||
|
LocationUtils locationUtils,
|
||||||
|
SocketFactory torSocketFactory,
|
||||||
|
Clock clock,
|
||||||
|
ResourceProvider resourceProvider,
|
||||||
CircumventionProvider circumventionProvider,
|
CircumventionProvider circumventionProvider,
|
||||||
BatteryManager batteryManager, Backoff backoff,
|
BatteryManager batteryManager,
|
||||||
|
Backoff backoff,
|
||||||
TorRendezvousCrypto torRendezvousCrypto,
|
TorRendezvousCrypto torRendezvousCrypto,
|
||||||
PluginCallback callback, String architecture, int maxLatency,
|
PluginCallback callback,
|
||||||
|
String architecture,
|
||||||
|
int maxLatency,
|
||||||
int maxIdleTime) {
|
int maxIdleTime) {
|
||||||
super(ioExecutor, networkManager, locationUtils, torSocketFactory,
|
super(ioExecutor, networkManager, locationUtils, torSocketFactory,
|
||||||
clock, resourceProvider, circumventionProvider, batteryManager,
|
clock, resourceProvider, circumventionProvider, batteryManager,
|
||||||
backoff, torRendezvousCrypto, callback, architecture, maxLatency, maxIdleTime,
|
backoff, torRendezvousCrypto, callback, architecture,
|
||||||
|
maxLatency, maxIdleTime,
|
||||||
appContext.getDir("tor", MODE_PRIVATE));
|
appContext.getDir("tor", MODE_PRIVATE));
|
||||||
this.appContext = appContext;
|
this.appContext = appContext;
|
||||||
PowerManager pm = (PowerManager)
|
PowerManager pm = (PowerManager)
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
|||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.LocationUtils;
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
import org.briarproject.bramble.api.system.ResourceProvider;
|
import org.briarproject.bramble.api.system.ResourceProvider;
|
||||||
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
import org.briarproject.bramble.util.AndroidUtils;
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
@@ -39,7 +39,7 @@ public class AndroidTorPluginFactory implements DuplexPluginFactory {
|
|||||||
private static final double BACKOFF_BASE = 1.2;
|
private static final double BACKOFF_BASE = 1.2;
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor;
|
||||||
private final ScheduledExecutorService scheduler;
|
private final TaskScheduler scheduler;
|
||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
private final NetworkManager networkManager;
|
private final NetworkManager networkManager;
|
||||||
private final LocationUtils locationUtils;
|
private final LocationUtils locationUtils;
|
||||||
@@ -52,12 +52,17 @@ public class AndroidTorPluginFactory implements DuplexPluginFactory {
|
|||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
|
|
||||||
public AndroidTorPluginFactory(Executor ioExecutor,
|
public AndroidTorPluginFactory(Executor ioExecutor,
|
||||||
ScheduledExecutorService scheduler, Context appContext,
|
TaskScheduler scheduler,
|
||||||
NetworkManager networkManager, LocationUtils locationUtils,
|
Context appContext,
|
||||||
EventBus eventBus, SocketFactory torSocketFactory,
|
NetworkManager networkManager,
|
||||||
BackoffFactory backoffFactory, ResourceProvider resourceProvider,
|
LocationUtils locationUtils,
|
||||||
|
EventBus eventBus,
|
||||||
|
SocketFactory torSocketFactory,
|
||||||
|
BackoffFactory backoffFactory,
|
||||||
|
ResourceProvider resourceProvider,
|
||||||
CircumventionProvider circumventionProvider,
|
CircumventionProvider circumventionProvider,
|
||||||
BatteryManager batteryManager, Clock clock) {
|
BatteryManager batteryManager,
|
||||||
|
Clock clock) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
this.scheduler = scheduler;
|
this.scheduler = scheduler;
|
||||||
this.appContext = appContext;
|
this.appContext = appContext;
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package org.briarproject.bramble.util;
|
|||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -29,7 +29,7 @@ public class RenewableWakeLock {
|
|||||||
private static final int SAFETY_MARGIN_MS = 10_000;
|
private static final int SAFETY_MARGIN_MS = 10_000;
|
||||||
|
|
||||||
private final PowerManager powerManager;
|
private final PowerManager powerManager;
|
||||||
private final ScheduledExecutorService scheduler;
|
private final TaskScheduler scheduler;
|
||||||
private final int levelAndFlags;
|
private final int levelAndFlags;
|
||||||
private final String tag;
|
private final String tag;
|
||||||
private final long durationMs;
|
private final long durationMs;
|
||||||
@@ -39,10 +39,10 @@ public class RenewableWakeLock {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private PowerManager.WakeLock wakeLock; // Locking: lock
|
private PowerManager.WakeLock wakeLock; // Locking: lock
|
||||||
@Nullable
|
@Nullable
|
||||||
private ScheduledFuture future; // Locking: lock
|
private ScheduledFuture<?> future; // Locking: lock
|
||||||
|
|
||||||
public RenewableWakeLock(PowerManager powerManager,
|
public RenewableWakeLock(PowerManager powerManager,
|
||||||
ScheduledExecutorService scheduler, int levelAndFlags, String tag,
|
TaskScheduler scheduler, int levelAndFlags, String tag,
|
||||||
long duration, TimeUnit timeUnit) {
|
long duration, TimeUnit timeUnit) {
|
||||||
this.powerManager = powerManager;
|
this.powerManager = powerManager;
|
||||||
this.scheduler = scheduler;
|
this.scheduler = scheduler;
|
||||||
|
|||||||
@@ -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 {
|
|
||||||
}
|
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ package org.briarproject.bramble.io;
|
|||||||
import org.briarproject.bramble.api.io.TimeoutMonitor;
|
import org.briarproject.bramble.api.io.TimeoutMonitor;
|
||||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.Scheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -11,7 +11,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.annotation.concurrent.GuardedBy;
|
import javax.annotation.concurrent.GuardedBy;
|
||||||
@@ -30,7 +29,7 @@ class TimeoutMonitorImpl implements TimeoutMonitor {
|
|||||||
|
|
||||||
private static final long CHECK_INTERVAL_MS = SECONDS.toMillis(10);
|
private static final long CHECK_INTERVAL_MS = SECONDS.toMillis(10);
|
||||||
|
|
||||||
private final ScheduledExecutorService scheduler;
|
private final TaskScheduler scheduler;
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor;
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
@@ -41,7 +40,7 @@ class TimeoutMonitorImpl implements TimeoutMonitor {
|
|||||||
private Future<?> task = null;
|
private Future<?> task = null;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
TimeoutMonitorImpl(@Scheduler ScheduledExecutorService scheduler,
|
TimeoutMonitorImpl(TaskScheduler scheduler,
|
||||||
@IoExecutor Executor ioExecutor, Clock clock) {
|
@IoExecutor Executor ioExecutor, Clock clock) {
|
||||||
this.scheduler = scheduler;
|
this.scheduler = scheduler;
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
@@ -74,7 +73,7 @@ class TimeoutMonitorImpl implements TimeoutMonitor {
|
|||||||
if (toCancel != null) toCancel.cancel(false);
|
if (toCancel != null) toCancel.cancel(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduler
|
// Scheduler
|
||||||
private void checkTimeouts() {
|
private void checkTimeouts() {
|
||||||
ioExecutor.execute(() -> {
|
ioExecutor.execute(() -> {
|
||||||
List<TimeoutInputStream> snapshot;
|
List<TimeoutInputStream> snapshot;
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import org.briarproject.bramble.api.plugin.simplex.SimplexPlugin;
|
|||||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.Scheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -36,7 +36,6 @@ import java.util.Map;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -58,7 +57,7 @@ class PollerImpl implements Poller, EventListener {
|
|||||||
private static final Logger LOG = getLogger(PollerImpl.class.getName());
|
private static final Logger LOG = getLogger(PollerImpl.class.getName());
|
||||||
|
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor;
|
||||||
private final ScheduledExecutorService scheduler;
|
private final TaskScheduler scheduler;
|
||||||
private final ConnectionManager connectionManager;
|
private final ConnectionManager connectionManager;
|
||||||
private final ConnectionRegistry connectionRegistry;
|
private final ConnectionRegistry connectionRegistry;
|
||||||
private final PluginManager pluginManager;
|
private final PluginManager pluginManager;
|
||||||
@@ -71,11 +70,13 @@ class PollerImpl implements Poller, EventListener {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PollerImpl(@IoExecutor Executor ioExecutor,
|
PollerImpl(@IoExecutor Executor ioExecutor,
|
||||||
@Scheduler ScheduledExecutorService scheduler,
|
TaskScheduler scheduler,
|
||||||
ConnectionManager connectionManager,
|
ConnectionManager connectionManager,
|
||||||
ConnectionRegistry connectionRegistry, PluginManager pluginManager,
|
ConnectionRegistry connectionRegistry,
|
||||||
|
PluginManager pluginManager,
|
||||||
TransportPropertyManager transportPropertyManager,
|
TransportPropertyManager transportPropertyManager,
|
||||||
SecureRandom random, Clock clock) {
|
SecureRandom random,
|
||||||
|
Clock clock) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
this.scheduler = scheduler;
|
this.scheduler = scheduler;
|
||||||
this.connectionManager = connectionManager;
|
this.connectionManager = connectionManager;
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import org.briarproject.bramble.api.rendezvous.event.RendezvousConnectionClosedE
|
|||||||
import org.briarproject.bramble.api.rendezvous.event.RendezvousConnectionOpenedEvent;
|
import org.briarproject.bramble.api.rendezvous.event.RendezvousConnectionOpenedEvent;
|
||||||
import org.briarproject.bramble.api.rendezvous.event.RendezvousPollEvent;
|
import org.briarproject.bramble.api.rendezvous.event.RendezvousPollEvent;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.Scheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -52,7 +52,6 @@ import java.util.Map;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -80,7 +79,7 @@ class RendezvousPollerImpl implements RendezvousPoller, Service, EventListener {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(RendezvousPollerImpl.class.getName());
|
getLogger(RendezvousPollerImpl.class.getName());
|
||||||
|
|
||||||
private final ScheduledExecutorService scheduler;
|
private final TaskScheduler scheduler;
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final IdentityManager identityManager;
|
private final IdentityManager identityManager;
|
||||||
private final TransportCrypto transportCrypto;
|
private final TransportCrypto transportCrypto;
|
||||||
@@ -105,7 +104,7 @@ class RendezvousPollerImpl implements RendezvousPoller, Service, EventListener {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
RendezvousPollerImpl(@IoExecutor Executor ioExecutor,
|
RendezvousPollerImpl(@IoExecutor Executor ioExecutor,
|
||||||
@Scheduler ScheduledExecutorService scheduler,
|
TaskScheduler scheduler,
|
||||||
DatabaseComponent db,
|
DatabaseComponent db,
|
||||||
IdentityManager identityManager,
|
IdentityManager identityManager,
|
||||||
TransportCrypto transportCrypto,
|
TransportCrypto transportCrypto,
|
||||||
@@ -205,7 +204,7 @@ class RendezvousPollerImpl implements RendezvousPoller, Service, EventListener {
|
|||||||
return plugin.createRendezvousEndpoint(k, cs.alice, h);
|
return plugin.createRendezvousEndpoint(k, cs.alice, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduler
|
// Scheduler
|
||||||
private void poll() {
|
private void poll() {
|
||||||
worker.execute(() -> {
|
worker.execute(() -> {
|
||||||
removeExpiredPendingContacts();
|
removeExpiredPendingContacts();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package org.briarproject.bramble.system;
|
|||||||
|
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.Scheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
|
||||||
import java.util.concurrent.RejectedExecutionHandler;
|
import java.util.concurrent.RejectedExecutionHandler;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
@@ -19,17 +19,16 @@ public class SystemModule {
|
|||||||
|
|
||||||
public static class EagerSingletons {
|
public static class EagerSingletons {
|
||||||
@Inject
|
@Inject
|
||||||
@Scheduler
|
TaskScheduler scheduler;
|
||||||
ScheduledExecutorService scheduledExecutorService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ScheduledExecutorService scheduler;
|
private final ScheduledExecutorService scheduledExecutorService;
|
||||||
|
|
||||||
public SystemModule() {
|
public SystemModule() {
|
||||||
// Discard tasks that are submitted during shutdown
|
// Discard tasks that are submitted during shutdown
|
||||||
RejectedExecutionHandler policy =
|
RejectedExecutionHandler policy =
|
||||||
new ScheduledThreadPoolExecutor.DiscardPolicy();
|
new ScheduledThreadPoolExecutor.DiscardPolicy();
|
||||||
scheduler = new ScheduledThreadPoolExecutor(1, policy);
|
scheduledExecutorService = new ScheduledThreadPoolExecutor(1, policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@@ -39,10 +38,8 @@ public class SystemModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Scheduler
|
TaskScheduler provideTaskScheduler(LifecycleManager lifecycleManager) {
|
||||||
ScheduledExecutorService provideScheduledExecutorService(
|
lifecycleManager.registerForShutdown(scheduledExecutorService);
|
||||||
LifecycleManager lifecycleManager) {
|
return new TaskSchedulerImpl(scheduledExecutorService);
|
||||||
lifecycleManager.registerForShutdown(scheduler);
|
|
||||||
return scheduler;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package org.briarproject.bramble.system;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link TaskScheduler} that delegates all calls to a
|
||||||
|
* {@link ScheduledExecutorService}.
|
||||||
|
*/
|
||||||
|
@ThreadSafe
|
||||||
|
@NotNullByDefault
|
||||||
|
class TaskSchedulerImpl implements TaskScheduler {
|
||||||
|
|
||||||
|
private final ScheduledExecutorService delegate;
|
||||||
|
|
||||||
|
TaskSchedulerImpl(ScheduledExecutorService delegate) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ScheduledFuture<?> schedule(Runnable task, long delay,
|
||||||
|
TimeUnit unit) {
|
||||||
|
return delegate.schedule(task, delay, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long delay,
|
||||||
|
long interval, TimeUnit unit) {
|
||||||
|
return delegate.scheduleAtFixedRate(task, delay, interval, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long delay,
|
||||||
|
long interval, TimeUnit unit) {
|
||||||
|
return delegate.scheduleWithFixedDelay(task, delay, interval, unit);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,10 +6,9 @@ import org.briarproject.bramble.api.db.DatabaseExecutor;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.Scheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@@ -22,14 +21,15 @@ class TransportKeyManagerFactoryImpl implements
|
|||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final TransportCrypto transportCrypto;
|
private final TransportCrypto transportCrypto;
|
||||||
private final Executor dbExecutor;
|
private final Executor dbExecutor;
|
||||||
private final ScheduledExecutorService scheduler;
|
private final TaskScheduler scheduler;
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
TransportKeyManagerFactoryImpl(DatabaseComponent db,
|
TransportKeyManagerFactoryImpl(DatabaseComponent db,
|
||||||
TransportCrypto transportCrypto,
|
TransportCrypto transportCrypto,
|
||||||
@DatabaseExecutor Executor dbExecutor,
|
@DatabaseExecutor Executor dbExecutor,
|
||||||
@Scheduler ScheduledExecutorService scheduler, Clock clock) {
|
TaskScheduler scheduler,
|
||||||
|
Clock clock) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.transportCrypto = transportCrypto;
|
this.transportCrypto = transportCrypto;
|
||||||
this.dbExecutor = dbExecutor;
|
this.dbExecutor = dbExecutor;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import org.briarproject.bramble.api.db.Transaction;
|
|||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.Scheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
import org.briarproject.bramble.api.transport.KeySetId;
|
||||||
import org.briarproject.bramble.api.transport.StreamContext;
|
import org.briarproject.bramble.api.transport.StreamContext;
|
||||||
import org.briarproject.bramble.api.transport.TransportKeySet;
|
import org.briarproject.bramble.api.transport.TransportKeySet;
|
||||||
@@ -24,7 +24,6 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -53,7 +52,7 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
|||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final TransportCrypto transportCrypto;
|
private final TransportCrypto transportCrypto;
|
||||||
private final Executor dbExecutor;
|
private final Executor dbExecutor;
|
||||||
private final ScheduledExecutorService scheduler;
|
private final TaskScheduler scheduler;
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
private final TransportId transportId;
|
private final TransportId transportId;
|
||||||
private final long timePeriodLength;
|
private final long timePeriodLength;
|
||||||
@@ -72,9 +71,12 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
|||||||
pendingContactOutContexts = new HashMap<>();
|
pendingContactOutContexts = new HashMap<>();
|
||||||
|
|
||||||
TransportKeyManagerImpl(DatabaseComponent db,
|
TransportKeyManagerImpl(DatabaseComponent db,
|
||||||
TransportCrypto transportCrypto, Executor dbExecutor,
|
TransportCrypto transportCrypto,
|
||||||
@Scheduler ScheduledExecutorService scheduler, Clock clock,
|
Executor dbExecutor,
|
||||||
TransportId transportId, long maxLatency) {
|
TaskScheduler scheduler,
|
||||||
|
Clock clock,
|
||||||
|
TransportId transportId,
|
||||||
|
long maxLatency) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.transportCrypto = transportCrypto;
|
this.transportCrypto = transportCrypto;
|
||||||
this.dbExecutor = dbExecutor;
|
this.dbExecutor = dbExecutor;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import org.briarproject.bramble.api.plugin.simplex.SimplexPlugin;
|
|||||||
import org.briarproject.bramble.api.properties.TransportProperties;
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
import org.briarproject.bramble.api.properties.TransportPropertyManager;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
import org.briarproject.bramble.test.ImmediateExecutor;
|
import org.briarproject.bramble.test.ImmediateExecutor;
|
||||||
import org.briarproject.bramble.test.RunAction;
|
import org.briarproject.bramble.test.RunAction;
|
||||||
@@ -30,7 +31,6 @@ import org.junit.Test;
|
|||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
@@ -45,8 +45,7 @@ import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
|||||||
|
|
||||||
public class PollerImplTest extends BrambleMockTestCase {
|
public class PollerImplTest extends BrambleMockTestCase {
|
||||||
|
|
||||||
private final ScheduledExecutorService scheduler =
|
private final TaskScheduler scheduler = context.mock(TaskScheduler.class);
|
||||||
context.mock(ScheduledExecutorService.class);
|
|
||||||
private final ConnectionManager connectionManager =
|
private final ConnectionManager connectionManager =
|
||||||
context.mock(ConnectionManager.class);
|
context.mock(ConnectionManager.class);
|
||||||
private final ConnectionRegistry connectionRegistry =
|
private final ConnectionRegistry connectionRegistry =
|
||||||
@@ -56,7 +55,8 @@ public class PollerImplTest extends BrambleMockTestCase {
|
|||||||
private final TransportPropertyManager transportPropertyManager =
|
private final TransportPropertyManager transportPropertyManager =
|
||||||
context.mock(TransportPropertyManager.class);
|
context.mock(TransportPropertyManager.class);
|
||||||
private final Clock clock = context.mock(Clock.class);
|
private final Clock clock = context.mock(Clock.class);
|
||||||
private final ScheduledFuture future = context.mock(ScheduledFuture.class);
|
private final ScheduledFuture<?> future =
|
||||||
|
context.mock(ScheduledFuture.class);
|
||||||
private final SecureRandom random;
|
private final SecureRandom random;
|
||||||
|
|
||||||
private final Executor ioExecutor = new ImmediateExecutor();
|
private final Executor ioExecutor = new ImmediateExecutor();
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import org.briarproject.bramble.api.rendezvous.event.RendezvousConnectionClosedE
|
|||||||
import org.briarproject.bramble.api.rendezvous.event.RendezvousConnectionOpenedEvent;
|
import org.briarproject.bramble.api.rendezvous.event.RendezvousConnectionOpenedEvent;
|
||||||
import org.briarproject.bramble.api.rendezvous.event.RendezvousPollEvent;
|
import org.briarproject.bramble.api.rendezvous.event.RendezvousPollEvent;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
import org.briarproject.bramble.test.CaptureArgumentAction;
|
import org.briarproject.bramble.test.CaptureArgumentAction;
|
||||||
import org.briarproject.bramble.test.DbExpectations;
|
import org.briarproject.bramble.test.DbExpectations;
|
||||||
@@ -37,7 +38,6 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
@@ -60,8 +60,7 @@ import static org.briarproject.bramble.test.TestUtils.getTransportProperties;
|
|||||||
|
|
||||||
public class RendezvousPollerImplTest extends BrambleMockTestCase {
|
public class RendezvousPollerImplTest extends BrambleMockTestCase {
|
||||||
|
|
||||||
private final ScheduledExecutorService scheduler =
|
private final TaskScheduler scheduler = context.mock(TaskScheduler.class);
|
||||||
context.mock(ScheduledExecutorService.class);
|
|
||||||
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||||
private final IdentityManager identityManager =
|
private final IdentityManager identityManager =
|
||||||
context.mock(IdentityManager.class);
|
context.mock(IdentityManager.class);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
|
|||||||
import org.briarproject.bramble.api.db.Transaction;
|
import org.briarproject.bramble.api.db.Transaction;
|
||||||
import org.briarproject.bramble.api.plugin.TransportId;
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
import org.briarproject.bramble.api.transport.IncomingKeys;
|
import org.briarproject.bramble.api.transport.IncomingKeys;
|
||||||
import org.briarproject.bramble.api.transport.KeySetId;
|
import org.briarproject.bramble.api.transport.KeySetId;
|
||||||
import org.briarproject.bramble.api.transport.OutgoingKeys;
|
import org.briarproject.bramble.api.transport.OutgoingKeys;
|
||||||
@@ -29,7 +30,6 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
@@ -55,8 +55,7 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase {
|
|||||||
private final TransportCrypto transportCrypto =
|
private final TransportCrypto transportCrypto =
|
||||||
context.mock(TransportCrypto.class);
|
context.mock(TransportCrypto.class);
|
||||||
private final Executor dbExecutor = context.mock(Executor.class);
|
private final Executor dbExecutor = context.mock(Executor.class);
|
||||||
private final ScheduledExecutorService scheduler =
|
private final TaskScheduler scheduler = context.mock(TaskScheduler.class);
|
||||||
context.mock(ScheduledExecutorService.class);
|
|
||||||
private final Clock clock = context.mock(Clock.class);
|
private final Clock clock = context.mock(Clock.class);
|
||||||
|
|
||||||
private final TransportId transportId = getTransportId();
|
private final TransportId transportId = getTransportId();
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import org.briarproject.bramble.api.system.AndroidExecutor;
|
|||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.LocationUtils;
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
import org.briarproject.bramble.api.system.ResourceProvider;
|
import org.briarproject.bramble.api.system.ResourceProvider;
|
||||||
import org.briarproject.bramble.api.system.Scheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
import org.briarproject.bramble.plugin.bluetooth.AndroidBluetoothPluginFactory;
|
import org.briarproject.bramble.plugin.bluetooth.AndroidBluetoothPluginFactory;
|
||||||
import org.briarproject.bramble.plugin.tcp.AndroidLanTcpPluginFactory;
|
import org.briarproject.bramble.plugin.tcp.AndroidLanTcpPluginFactory;
|
||||||
import org.briarproject.bramble.plugin.tor.AndroidTorPluginFactory;
|
import org.briarproject.bramble.plugin.tor.AndroidTorPluginFactory;
|
||||||
@@ -55,7 +55,6 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
@@ -125,14 +124,19 @@ public class AppModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
PluginConfig providePluginConfig(@IoExecutor Executor ioExecutor,
|
PluginConfig providePluginConfig(@IoExecutor Executor ioExecutor,
|
||||||
@Scheduler ScheduledExecutorService scheduler,
|
TaskScheduler scheduler,
|
||||||
AndroidExecutor androidExecutor, SecureRandom random,
|
AndroidExecutor androidExecutor,
|
||||||
SocketFactory torSocketFactory, BackoffFactory backoffFactory,
|
SecureRandom random,
|
||||||
Application app, NetworkManager networkManager,
|
SocketFactory torSocketFactory,
|
||||||
LocationUtils locationUtils, EventBus eventBus,
|
BackoffFactory backoffFactory,
|
||||||
|
Application app,
|
||||||
|
NetworkManager networkManager,
|
||||||
|
LocationUtils locationUtils,
|
||||||
|
EventBus eventBus,
|
||||||
ResourceProvider resourceProvider,
|
ResourceProvider resourceProvider,
|
||||||
CircumventionProvider circumventionProvider,
|
CircumventionProvider circumventionProvider,
|
||||||
BatteryManager batteryManager, Clock clock,
|
BatteryManager batteryManager,
|
||||||
|
Clock clock,
|
||||||
TimeoutMonitor timeoutMonitor) {
|
TimeoutMonitor timeoutMonitor) {
|
||||||
Context appContext = app.getApplicationContext();
|
Context appContext = app.getApplicationContext();
|
||||||
DuplexPluginFactory bluetooth = new AndroidBluetoothPluginFactory(
|
DuplexPluginFactory bluetooth = new AndroidBluetoothPluginFactory(
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import org.briarproject.bramble.api.plugin.event.TransportInactiveEvent;
|
|||||||
import org.briarproject.bramble.api.sync.Group;
|
import org.briarproject.bramble.api.sync.Group;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
import org.briarproject.bramble.api.system.Scheduler;
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
import org.briarproject.bramble.util.StringUtils;
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
import org.briarproject.briar.api.blog.Blog;
|
import org.briarproject.briar.api.blog.Blog;
|
||||||
import org.briarproject.briar.api.blog.BlogManager;
|
import org.briarproject.briar.api.blog.BlogManager;
|
||||||
@@ -48,7 +48,6 @@ import java.util.Comparator;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -85,7 +84,7 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
|||||||
|
|
||||||
private static final int CONNECT_TIMEOUT = 60 * 1000; // Milliseconds
|
private static final int CONNECT_TIMEOUT = 60 * 1000; // Milliseconds
|
||||||
|
|
||||||
private final ScheduledExecutorService scheduler;
|
private final TaskScheduler scheduler;
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor;
|
||||||
private final DatabaseComponent db;
|
private final DatabaseComponent db;
|
||||||
private final ContactGroupFactory contactGroupFactory;
|
private final ContactGroupFactory contactGroupFactory;
|
||||||
@@ -101,13 +100,17 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
|||||||
private volatile boolean torActive = false;
|
private volatile boolean torActive = false;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedManagerImpl(@Scheduler ScheduledExecutorService scheduler,
|
FeedManagerImpl(TaskScheduler scheduler,
|
||||||
@IoExecutor Executor ioExecutor, DatabaseComponent db,
|
@IoExecutor Executor ioExecutor,
|
||||||
ContactGroupFactory contactGroupFactory, ClientHelper clientHelper,
|
DatabaseComponent db,
|
||||||
BlogManager blogManager, BlogPostFactory blogPostFactory,
|
ContactGroupFactory contactGroupFactory,
|
||||||
FeedFactory feedFactory, SocketFactory torSocketFactory,
|
ClientHelper clientHelper,
|
||||||
Clock clock, Dns noDnsLookups) {
|
BlogManager blogManager,
|
||||||
|
BlogPostFactory blogPostFactory,
|
||||||
|
FeedFactory feedFactory,
|
||||||
|
SocketFactory torSocketFactory,
|
||||||
|
Clock clock,
|
||||||
|
Dns noDnsLookups) {
|
||||||
this.scheduler = scheduler;
|
this.scheduler = scheduler;
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
this.db = db;
|
this.db = db;
|
||||||
@@ -285,7 +288,7 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
|||||||
* This method is called periodically from a background service.
|
* This method is called periodically from a background service.
|
||||||
* It fetches all available feeds and posts new entries to the respective
|
* It fetches all available feeds and posts new entries to the respective
|
||||||
* blog.
|
* blog.
|
||||||
*
|
* <p>
|
||||||
* We can not do this within one database {@link Transaction},
|
* We can not do this within one database {@link Transaction},
|
||||||
* because fetching can take a long time
|
* because fetching can take a long time
|
||||||
* and we can not block the database that long.
|
* and we can not block the database that long.
|
||||||
@@ -491,9 +494,9 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
|||||||
private Comparator<SyndEntry> getEntryComparator() {
|
private Comparator<SyndEntry> getEntryComparator() {
|
||||||
return (e1, e2) -> {
|
return (e1, e2) -> {
|
||||||
Date d1 = e1.getPublishedDate() != null ? e1.getPublishedDate() :
|
Date d1 = e1.getPublishedDate() != null ? e1.getPublishedDate() :
|
||||||
e1.getUpdatedDate();
|
e1.getUpdatedDate();
|
||||||
Date d2 = e2.getPublishedDate() != null ? e2.getPublishedDate() :
|
Date d2 = e2.getPublishedDate() != null ? e2.getPublishedDate() :
|
||||||
e2.getUpdatedDate();
|
e2.getUpdatedDate();
|
||||||
if (d1 == null && d2 == null) return 0;
|
if (d1 == null && d2 == null) return 0;
|
||||||
if (d1 == null) return -1;
|
if (d1 == null) return -1;
|
||||||
if (d2 == null) return 1;
|
if (d2 == null) return 1;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.briarproject.bramble.api.sync.Group;
|
|||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.Message;
|
import org.briarproject.bramble.api.sync.Message;
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
import org.briarproject.bramble.api.system.TaskScheduler;
|
||||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||||
import org.briarproject.bramble.test.ImmediateExecutor;
|
import org.briarproject.bramble.test.ImmediateExecutor;
|
||||||
import org.briarproject.briar.api.blog.Blog;
|
import org.briarproject.briar.api.blog.Blog;
|
||||||
@@ -30,7 +31,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
|
|
||||||
import javax.net.SocketFactory;
|
import javax.net.SocketFactory;
|
||||||
|
|
||||||
@@ -45,8 +45,7 @@ import static org.briarproject.briar.api.feed.FeedManager.MAJOR_VERSION;
|
|||||||
|
|
||||||
public class FeedManagerImplTest extends BrambleMockTestCase {
|
public class FeedManagerImplTest extends BrambleMockTestCase {
|
||||||
|
|
||||||
private final ScheduledExecutorService scheduler =
|
private final TaskScheduler scheduler = context.mock(TaskScheduler.class);
|
||||||
context.mock(ScheduledExecutorService.class);
|
|
||||||
private final Executor ioExecutor = new ImmediateExecutor();
|
private final Executor ioExecutor = new ImmediateExecutor();
|
||||||
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
private final DatabaseComponent db = context.mock(DatabaseComponent.class);
|
||||||
private final ContactGroupFactory contactGroupFactory =
|
private final ContactGroupFactory contactGroupFactory =
|
||||||
@@ -92,7 +91,7 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFetchFeedsIoException() throws Exception {
|
public void testFetchFeedsIoException() throws Exception {
|
||||||
BdfDictionary feedDict= new BdfDictionary();
|
BdfDictionary feedDict = new BdfDictionary();
|
||||||
BdfList feedList = BdfList.of(feedDict);
|
BdfList feedList = BdfList.of(feedDict);
|
||||||
|
|
||||||
expectGetFeeds(feedList);
|
expectGetFeeds(feedList);
|
||||||
|
|||||||
Reference in New Issue
Block a user