Commit 59dc065c authored by akwizgran's avatar akwizgran

Plugin factories can supply clocks for their plugins if needed.

parent 960ead02
......@@ -2,10 +2,8 @@ package net.sf.briar.api.plugins.duplex;
import java.util.concurrent.Executor;
import net.sf.briar.clock.Clock;
public interface DuplexPluginFactory {
DuplexPlugin createPlugin(Executor pluginExecutor, Clock clock,
DuplexPlugin createPlugin(Executor pluginExecutor,
DuplexPluginCallback callback);
}
......@@ -2,10 +2,8 @@ package net.sf.briar.api.plugins.simplex;
import java.util.concurrent.Executor;
import net.sf.briar.clock.Clock;
public interface SimplexPluginFactory {
SimplexPlugin createPlugin(Executor pluginExecutor, Clock clock,
SimplexPlugin createPlugin(Executor pluginExecutor,
SimplexPluginCallback callback);
}
......@@ -35,7 +35,6 @@ import net.sf.briar.api.protocol.TransportId;
import net.sf.briar.api.protocol.TransportIndex;
import net.sf.briar.api.transport.ConnectionDispatcher;
import net.sf.briar.api.ui.UiCallback;
import net.sf.briar.clock.Clock;
import com.google.inject.Inject;
......@@ -55,7 +54,6 @@ class PluginManagerImpl implements PluginManager {
};
private final ExecutorService pluginExecutor;
private final Clock clock;
private final DatabaseComponent db;
private final Poller poller;
private final ConnectionDispatcher dispatcher;
......@@ -65,10 +63,9 @@ class PluginManagerImpl implements PluginManager {
@Inject
PluginManagerImpl(@PluginExecutor ExecutorService pluginExecutor,
Clock clock, DatabaseComponent db, Poller poller,
DatabaseComponent db, Poller poller,
ConnectionDispatcher dispatcher, UiCallback uiCallback) {
this.pluginExecutor = pluginExecutor;
this.clock = clock;
this.db = db;
this.poller = poller;
this.dispatcher = dispatcher;
......@@ -91,7 +88,7 @@ class PluginManagerImpl implements PluginManager {
(SimplexPluginFactory) c.newInstance();
SimplexCallback callback = new SimplexCallback();
SimplexPlugin plugin = factory.createPlugin(pluginExecutor,
clock, callback);
callback);
if(plugin == null) {
if(LOG.isLoggable(Level.INFO)) {
LOG.info(factory.getClass().getSimpleName()
......@@ -131,7 +128,7 @@ class PluginManagerImpl implements PluginManager {
(DuplexPluginFactory) c.newInstance();
DuplexCallback callback = new DuplexCallback();
DuplexPlugin plugin = factory.createPlugin(pluginExecutor,
clock, callback);
callback);
if(plugin == null) {
if(LOG.isLoggable(Level.INFO)) {
LOG.info(factory.getClass().getSimpleName()
......
......@@ -6,15 +6,15 @@ import net.sf.briar.api.plugins.PluginExecutor;
import net.sf.briar.api.plugins.duplex.DuplexPlugin;
import net.sf.briar.api.plugins.duplex.DuplexPluginCallback;
import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
import net.sf.briar.clock.Clock;
import net.sf.briar.clock.SystemClock;
public class BluetoothPluginFactory implements DuplexPluginFactory {
private static final long POLLING_INTERVAL = 3L * 60L * 1000L; // 3 mins
public DuplexPlugin createPlugin(@PluginExecutor Executor pluginExecutor,
Clock clock, DuplexPluginCallback callback) {
return new BluetoothPlugin(pluginExecutor, clock, callback,
DuplexPluginCallback callback) {
return new BluetoothPlugin(pluginExecutor, new SystemClock(), callback,
POLLING_INTERVAL);
}
}
......@@ -5,11 +5,10 @@ import java.util.concurrent.Executor;
import net.sf.briar.api.plugins.simplex.SimplexPlugin;
import net.sf.briar.api.plugins.simplex.SimplexPluginCallback;
import net.sf.briar.api.plugins.simplex.SimplexPluginFactory;
import net.sf.briar.clock.Clock;
public class GmailPluginFactory implements SimplexPluginFactory {
public SimplexPlugin createPlugin(Executor pluginExecutor, Clock clock,
public SimplexPlugin createPlugin(Executor pluginExecutor,
SimplexPluginCallback callback) {
return new GmailPlugin(pluginExecutor, callback);
......
......@@ -6,7 +6,6 @@ import net.sf.briar.api.plugins.PluginExecutor;
import net.sf.briar.api.plugins.simplex.SimplexPlugin;
import net.sf.briar.api.plugins.simplex.SimplexPluginCallback;
import net.sf.briar.api.plugins.simplex.SimplexPluginFactory;
import net.sf.briar.clock.Clock;
import net.sf.briar.util.OsUtils;
public class RemovableDrivePluginFactory implements SimplexPluginFactory {
......@@ -14,7 +13,7 @@ public class RemovableDrivePluginFactory implements SimplexPluginFactory {
private static final long POLLING_INTERVAL = 10L * 1000L; // 10 seconds
public SimplexPlugin createPlugin(@PluginExecutor Executor pluginExecutor,
Clock clock, SimplexPluginCallback callback) {
SimplexPluginCallback callback) {
RemovableDriveFinder finder;
RemovableDriveMonitor monitor;
if(OsUtils.isLinux()) {
......
......@@ -6,14 +6,13 @@ import net.sf.briar.api.plugins.PluginExecutor;
import net.sf.briar.api.plugins.duplex.DuplexPlugin;
import net.sf.briar.api.plugins.duplex.DuplexPluginCallback;
import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
import net.sf.briar.clock.Clock;
public class SimpleSocketPluginFactory implements DuplexPluginFactory {
private static final long POLLING_INTERVAL = 5L * 60L * 1000L; // 5 mins
public DuplexPlugin createPlugin(@PluginExecutor Executor pluginExecutor,
Clock clock, DuplexPluginCallback callback) {
DuplexPluginCallback callback) {
return new SimpleSocketPlugin(pluginExecutor, callback,
POLLING_INTERVAL);
}
......
......@@ -6,14 +6,13 @@ import net.sf.briar.api.plugins.PluginExecutor;
import net.sf.briar.api.plugins.duplex.DuplexPlugin;
import net.sf.briar.api.plugins.duplex.DuplexPluginCallback;
import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
import net.sf.briar.clock.Clock;
public class TorPluginFactory implements DuplexPluginFactory {
private static final long POLLING_INTERVAL = 15L * 60L * 1000L; // 15 mins
public DuplexPlugin createPlugin(@PluginExecutor Executor pluginExecutor,
Clock clock, DuplexPluginCallback callback) {
DuplexPluginCallback callback) {
return new TorPlugin(pluginExecutor, callback, POLLING_INTERVAL);
}
}
......@@ -13,7 +13,6 @@ import net.sf.briar.api.protocol.TransportId;
import net.sf.briar.api.protocol.TransportIndex;
import net.sf.briar.api.transport.ConnectionDispatcher;
import net.sf.briar.api.ui.UiCallback;
import net.sf.briar.clock.SystemClock;
import org.jmock.Expectations;
import org.jmock.Mockery;
......@@ -48,8 +47,8 @@ public class PluginManagerImplTest extends BriarTestCase {
oneOf(poller).stop();
}});
ExecutorService executor = Executors.newCachedThreadPool();
PluginManagerImpl p = new PluginManagerImpl(executor, new SystemClock(),
db, poller, dispatcher, uiCallback);
PluginManagerImpl p = new PluginManagerImpl(executor, db, poller,
dispatcher, uiCallback);
// We expect either 3 or 4 plugins to be started, depending on whether
// the test machine has a Bluetooth device
int started = p.start();
......
......@@ -14,7 +14,6 @@ import net.sf.briar.api.TransportProperties;
import net.sf.briar.api.plugins.simplex.SimplexPluginCallback;
import net.sf.briar.api.plugins.simplex.SimplexTransportReader;
import net.sf.briar.api.plugins.simplex.SimplexTransportWriter;
import net.sf.briar.clock.SystemClock;
import org.junit.Before;
import org.junit.Test;
......@@ -102,8 +101,7 @@ Map<ContactId,TransportProperties> map = new HashMap<ContactId, TransportPropert
public void testPluginFactoryCreation()
{
GmailPluginFactory plugin = new GmailPluginFactory();
plugin.createPlugin(Executors.newSingleThreadExecutor(),
new SystemClock(), callback);
plugin.createPlugin(Executors.newSingleThreadExecutor(), callback);
}
@Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment