mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Merged IncomingConnectionExecutor and PluginExecutor into IoExecutor.
We don't need two separate executors for long-running IO threads.
This commit is contained in:
@@ -4,21 +4,20 @@ import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.api.lifecycle.ShutdownManager;
|
||||
import org.briarproject.util.OsUtils;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
public class DesktopLifecycleModule extends AbstractModule {
|
||||
public class DesktopLifecycleModule extends LifecycleModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(LifecycleManager.class).to(
|
||||
LifecycleManagerImpl.class).in(Singleton.class);
|
||||
if(OsUtils.isWindows()) {
|
||||
bind(ShutdownManager.class).to(
|
||||
WindowsShutdownManagerImpl.class).in(
|
||||
Singleton.class);
|
||||
WindowsShutdownManagerImpl.class).in(Singleton.class);
|
||||
} else {
|
||||
bind(ShutdownManager.class).to(
|
||||
ShutdownManagerImpl.class).in(Singleton.class);
|
||||
ShutdownManagerImpl.class).in(Singleton.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import java.util.Collection;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.briarproject.api.crypto.CryptoComponent;
|
||||
import org.briarproject.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.api.lifecycle.ShutdownManager;
|
||||
import org.briarproject.api.plugins.PluginExecutor;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPluginConfig;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPluginConfig;
|
||||
@@ -19,18 +19,15 @@ import org.briarproject.plugins.modem.ModemPluginFactory;
|
||||
import org.briarproject.plugins.tcp.LanTcpPluginFactory;
|
||||
import org.briarproject.plugins.tcp.WanTcpPluginFactory;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
public class DesktopPluginsModule extends AbstractModule {
|
||||
|
||||
public void configure() {}
|
||||
public class DesktopPluginsModule extends PluginsModule {
|
||||
|
||||
@Provides
|
||||
SimplexPluginConfig getSimplexPluginConfig(
|
||||
@PluginExecutor Executor pluginExecutor, FileUtils fileUtils) {
|
||||
SimplexPluginConfig getSimplexPluginConfig(@IoExecutor Executor ioExecutor,
|
||||
FileUtils fileUtils) {
|
||||
SimplexPluginFactory removable =
|
||||
new RemovableDrivePluginFactory(pluginExecutor, fileUtils);
|
||||
new RemovableDrivePluginFactory(ioExecutor, fileUtils);
|
||||
final Collection<SimplexPluginFactory> factories =
|
||||
Arrays.asList(removable);
|
||||
return new SimplexPluginConfig() {
|
||||
@@ -41,16 +38,15 @@ public class DesktopPluginsModule extends AbstractModule {
|
||||
}
|
||||
|
||||
@Provides
|
||||
DuplexPluginConfig getDuplexPluginConfig(
|
||||
@PluginExecutor Executor pluginExecutor,
|
||||
DuplexPluginConfig getDuplexPluginConfig(@IoExecutor Executor ioExecutor,
|
||||
CryptoComponent crypto, ReliabilityLayerFactory reliabilityFactory,
|
||||
ShutdownManager shutdownManager) {
|
||||
DuplexPluginFactory bluetooth = new BluetoothPluginFactory(
|
||||
pluginExecutor, crypto.getSecureRandom());
|
||||
DuplexPluginFactory modem = new ModemPluginFactory(pluginExecutor,
|
||||
ioExecutor, crypto.getSecureRandom());
|
||||
DuplexPluginFactory modem = new ModemPluginFactory(ioExecutor,
|
||||
reliabilityFactory);
|
||||
DuplexPluginFactory lan = new LanTcpPluginFactory(pluginExecutor);
|
||||
DuplexPluginFactory wan = new WanTcpPluginFactory(pluginExecutor,
|
||||
DuplexPluginFactory lan = new LanTcpPluginFactory(ioExecutor);
|
||||
DuplexPluginFactory wan = new WanTcpPluginFactory(ioExecutor,
|
||||
shutdownManager);
|
||||
final Collection<DuplexPluginFactory> factories =
|
||||
Arrays.asList(bluetooth, modem, lan, wan);
|
||||
|
||||
@@ -42,7 +42,7 @@ class BluetoothPlugin implements DuplexPlugin {
|
||||
Logger.getLogger(BluetoothPlugin.class.getName());
|
||||
private static final int UUID_BYTES = 16;
|
||||
|
||||
private final Executor pluginExecutor;
|
||||
private final Executor ioExecutor;
|
||||
private final Clock clock;
|
||||
private final SecureRandom secureRandom;
|
||||
private final DuplexPluginCallback callback;
|
||||
@@ -54,10 +54,10 @@ class BluetoothPlugin implements DuplexPlugin {
|
||||
private volatile StreamConnectionNotifier socket = null;
|
||||
private volatile LocalDevice localDevice = null;
|
||||
|
||||
BluetoothPlugin(Executor pluginExecutor, Clock clock,
|
||||
SecureRandom secureRandom, DuplexPluginCallback callback,
|
||||
int maxFrameLength, long maxLatency, long pollingInterval) {
|
||||
this.pluginExecutor = pluginExecutor;
|
||||
BluetoothPlugin(Executor ioExecutor, Clock clock, SecureRandom secureRandom,
|
||||
DuplexPluginCallback callback, int maxFrameLength, long maxLatency,
|
||||
long pollingInterval) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.clock = clock;
|
||||
this.secureRandom = secureRandom;
|
||||
this.callback = callback;
|
||||
@@ -96,7 +96,7 @@ class BluetoothPlugin implements DuplexPlugin {
|
||||
}
|
||||
|
||||
private void bind() {
|
||||
pluginExecutor.execute(new Runnable() {
|
||||
ioExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
if(!running) return;
|
||||
// Advertise the Bluetooth address to contacts
|
||||
@@ -197,7 +197,7 @@ class BluetoothPlugin implements DuplexPlugin {
|
||||
if(StringUtils.isNullOrEmpty(address)) continue;
|
||||
final String uuid = e.getValue().get("uuid");
|
||||
if(StringUtils.isNullOrEmpty(uuid)) continue;
|
||||
pluginExecutor.execute(new Runnable() {
|
||||
ioExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
if(!running) return;
|
||||
StreamConnection s = connect(makeUrl(address, uuid));
|
||||
|
||||
@@ -16,13 +16,13 @@ public class BluetoothPluginFactory implements DuplexPluginFactory {
|
||||
private static final long MAX_LATENCY = 60 * 1000; // 1 minute
|
||||
private static final long POLLING_INTERVAL = 3 * 60 * 1000; // 3 minutes
|
||||
|
||||
private final Executor pluginExecutor;
|
||||
private final Executor ioExecutor;
|
||||
private final SecureRandom secureRandom;
|
||||
private final Clock clock;
|
||||
|
||||
public BluetoothPluginFactory(Executor pluginExecutor,
|
||||
public BluetoothPluginFactory(Executor ioExecutor,
|
||||
SecureRandom secureRandom) {
|
||||
this.pluginExecutor = pluginExecutor;
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.secureRandom = secureRandom;
|
||||
clock = new SystemClock();
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public class BluetoothPluginFactory implements DuplexPluginFactory {
|
||||
}
|
||||
|
||||
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||
return new BluetoothPlugin(pluginExecutor, clock, secureRandom,
|
||||
callback, MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL);
|
||||
return new BluetoothPlugin(ioExecutor, clock, secureRandom, callback,
|
||||
MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ class PollingRemovableDriveMonitor implements RemovableDriveMonitor, Runnable {
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(PollingRemovableDriveMonitor.class.getName());
|
||||
|
||||
private final Executor pluginExecutor;
|
||||
private final Executor ioExecutor;
|
||||
private final RemovableDriveFinder finder;
|
||||
private final long pollingInterval;
|
||||
private final Object pollingLock = new Object();
|
||||
@@ -19,9 +19,9 @@ class PollingRemovableDriveMonitor implements RemovableDriveMonitor, Runnable {
|
||||
private volatile boolean running = false;
|
||||
private volatile Callback callback = null;
|
||||
|
||||
public PollingRemovableDriveMonitor(Executor pluginExecutor,
|
||||
public PollingRemovableDriveMonitor(Executor ioExecutor,
|
||||
RemovableDriveFinder finder, long pollingInterval) {
|
||||
this.pluginExecutor = pluginExecutor;
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.finder = finder;
|
||||
this.pollingInterval = pollingInterval;
|
||||
}
|
||||
@@ -29,7 +29,7 @@ class PollingRemovableDriveMonitor implements RemovableDriveMonitor, Runnable {
|
||||
public void start(Callback callback) throws IOException {
|
||||
this.callback = callback;
|
||||
running = true;
|
||||
pluginExecutor.execute(this);
|
||||
ioExecutor.execute(this);
|
||||
}
|
||||
|
||||
public void stop() throws IOException {
|
||||
|
||||
@@ -27,11 +27,11 @@ implements RemovableDriveMonitor.Callback {
|
||||
private final RemovableDriveFinder finder;
|
||||
private final RemovableDriveMonitor monitor;
|
||||
|
||||
RemovableDrivePlugin(Executor pluginExecutor, FileUtils fileUtils,
|
||||
RemovableDrivePlugin(Executor ioExecutor, FileUtils fileUtils,
|
||||
SimplexPluginCallback callback, RemovableDriveFinder finder,
|
||||
RemovableDriveMonitor monitor, int maxFrameLength,
|
||||
long maxLatency) {
|
||||
super(pluginExecutor, fileUtils, callback, maxFrameLength, maxLatency);
|
||||
super(ioExecutor, fileUtils, callback, maxFrameLength, maxLatency);
|
||||
this.finder = finder;
|
||||
this.monitor = monitor;
|
||||
}
|
||||
|
||||
@@ -17,12 +17,12 @@ public class RemovableDrivePluginFactory implements SimplexPluginFactory {
|
||||
private static final long MAX_LATENCY = 14 * 24 * 60 * 60 * 1000;
|
||||
private static final long POLLING_INTERVAL = 10 * 1000; // 10 seconds
|
||||
|
||||
private final Executor pluginExecutor;
|
||||
private final Executor ioExecutor;
|
||||
private final FileUtils fileUtils;
|
||||
|
||||
public RemovableDrivePluginFactory(Executor pluginExecutor,
|
||||
public RemovableDrivePluginFactory(Executor ioExecutor,
|
||||
FileUtils fileUtils) {
|
||||
this.pluginExecutor = pluginExecutor;
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.fileUtils = fileUtils;
|
||||
}
|
||||
|
||||
@@ -42,16 +42,16 @@ public class RemovableDrivePluginFactory implements SimplexPluginFactory {
|
||||
} else if(OsUtils.isMac()) {
|
||||
// JNotify requires OS X 10.5 or newer, so we have to poll
|
||||
finder = new MacRemovableDriveFinder();
|
||||
monitor = new PollingRemovableDriveMonitor(pluginExecutor, finder,
|
||||
monitor = new PollingRemovableDriveMonitor(ioExecutor, finder,
|
||||
POLLING_INTERVAL);
|
||||
} else if(OsUtils.isWindows()) {
|
||||
finder = new WindowsRemovableDriveFinder();
|
||||
monitor = new PollingRemovableDriveMonitor(pluginExecutor, finder,
|
||||
monitor = new PollingRemovableDriveMonitor(ioExecutor, finder,
|
||||
POLLING_INTERVAL);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return new RemovableDrivePlugin(pluginExecutor, fileUtils, callback,
|
||||
return new RemovableDrivePlugin(ioExecutor, fileUtils, callback,
|
||||
finder, monitor, MAX_FRAME_LENGTH, MAX_LATENCY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ModemPlugin.class.getName());
|
||||
|
||||
private final Executor pluginExecutor;
|
||||
private final Executor ioExecutor;
|
||||
private final ModemFactory modemFactory;
|
||||
private final SerialPortList serialPortList;
|
||||
private final DuplexPluginCallback callback;
|
||||
@@ -43,11 +43,11 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
||||
private volatile boolean running = false;
|
||||
private volatile Modem modem = null;
|
||||
|
||||
ModemPlugin(Executor pluginExecutor, ModemFactory modemFactory,
|
||||
ModemPlugin(Executor ioExecutor, ModemFactory modemFactory,
|
||||
SerialPortList serialPortList, DuplexPluginCallback callback,
|
||||
int maxFrameLength, long maxLatency, long pollingInterval,
|
||||
boolean shuffle) {
|
||||
this.pluginExecutor = pluginExecutor;
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.modemFactory = modemFactory;
|
||||
this.serialPortList = serialPortList;
|
||||
this.callback = callback;
|
||||
@@ -112,7 +112,7 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
||||
|
||||
public void poll(Collection<ContactId> connected) {
|
||||
if(!connected.isEmpty()) return; // One at a time please
|
||||
pluginExecutor.execute(new Runnable() {
|
||||
ioExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
poll();
|
||||
}
|
||||
|
||||
@@ -15,14 +15,14 @@ public class ModemPluginFactory implements DuplexPluginFactory {
|
||||
private static final long MAX_LATENCY = 60 * 1000; // 1 minute
|
||||
private static final long POLLING_INTERVAL = 60 * 60 * 1000; // 1 hour
|
||||
|
||||
private final Executor pluginExecutor;
|
||||
private final Executor ioExecutor;
|
||||
private final ModemFactory modemFactory;
|
||||
private final SerialPortList serialPortList;
|
||||
|
||||
public ModemPluginFactory(Executor pluginExecutor,
|
||||
public ModemPluginFactory(Executor ioExecutor,
|
||||
ReliabilityLayerFactory reliabilityFactory) {
|
||||
this.pluginExecutor = pluginExecutor;
|
||||
modemFactory = new ModemFactoryImpl(pluginExecutor, reliabilityFactory);
|
||||
this.ioExecutor = ioExecutor;
|
||||
modemFactory = new ModemFactoryImpl(ioExecutor, reliabilityFactory);
|
||||
serialPortList = new SerialPortListImpl();
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class ModemPluginFactory implements DuplexPluginFactory {
|
||||
// This plugin is not enabled by default
|
||||
String enabled = callback.getConfig().get("enabled");
|
||||
if(StringUtils.isNullOrEmpty(enabled)) return null;
|
||||
return new ModemPlugin(pluginExecutor, modemFactory, serialPortList,
|
||||
return new ModemPlugin(ioExecutor, modemFactory, serialPortList,
|
||||
callback, MAX_FRAME_LENGTH, MAX_LATENCY, POLLING_INTERVAL,
|
||||
true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user