mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
No need to poll plugins before they're enabled.
This commit is contained in:
@@ -142,10 +142,12 @@ class PluginManagerImpl implements PluginManager, Service, EventListener {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plugin getPlugin(TransportId t) {
|
||||
return plugins.get(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<DuplexPlugin> getInvitationPlugins() {
|
||||
List<DuplexPlugin> supported = new ArrayList<DuplexPlugin>();
|
||||
for (DuplexPlugin d : duplexPlugins)
|
||||
@@ -153,6 +155,7 @@ class PluginManagerImpl implements PluginManager, Service, EventListener {
|
||||
return Collections.unmodifiableList(supported);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<DuplexPlugin> getKeyAgreementPlugins() {
|
||||
List<DuplexPlugin> supported = new ArrayList<DuplexPlugin>();
|
||||
for (DuplexPlugin d : duplexPlugins)
|
||||
@@ -194,6 +197,7 @@ class PluginManagerImpl implements PluginManager, Service, EventListener {
|
||||
|
||||
private void connectToContact(final ContactId c, final SimplexPlugin p) {
|
||||
ioExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TransportId t = p.getId();
|
||||
if (!connectionRegistry.isConnected(c, t)) {
|
||||
@@ -207,6 +211,7 @@ class PluginManagerImpl implements PluginManager, Service, EventListener {
|
||||
|
||||
private void connectToContact(final ContactId c, final DuplexPlugin p) {
|
||||
ioExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TransportId t = p.getId();
|
||||
if (!connectionRegistry.isConnected(c, t)) {
|
||||
@@ -229,6 +234,7 @@ class PluginManagerImpl implements PluginManager, Service, EventListener {
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
TransportId id = factory.getId();
|
||||
@@ -248,7 +254,6 @@ class PluginManagerImpl implements PluginManager, Service, EventListener {
|
||||
if (started) {
|
||||
plugins.put(id, plugin);
|
||||
simplexPlugins.add(plugin);
|
||||
if (plugin.shouldPoll()) poller.addPlugin(plugin);
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
String name = plugin.getClass().getSimpleName();
|
||||
LOG.info("Starting " + name + " took " +
|
||||
@@ -281,6 +286,7 @@ class PluginManagerImpl implements PluginManager, Service, EventListener {
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
TransportId id = factory.getId();
|
||||
@@ -300,7 +306,6 @@ class PluginManagerImpl implements PluginManager, Service, EventListener {
|
||||
if (started) {
|
||||
plugins.put(id, plugin);
|
||||
duplexPlugins.add(plugin);
|
||||
if (plugin.shouldPoll()) poller.addPlugin(plugin);
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
String name = plugin.getClass().getSimpleName();
|
||||
LOG.info("Starting " + name + " took " +
|
||||
@@ -332,6 +337,7 @@ class PluginManagerImpl implements PluginManager, Service, EventListener {
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
@@ -357,6 +363,7 @@ class PluginManagerImpl implements PluginManager, Service, EventListener {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Settings getSettings() {
|
||||
try {
|
||||
return settingsManager.getSettings(id.getString());
|
||||
@@ -366,6 +373,7 @@ class PluginManagerImpl implements PluginManager, Service, EventListener {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransportProperties getLocalProperties() {
|
||||
try {
|
||||
TransportProperties p =
|
||||
@@ -377,6 +385,7 @@ class PluginManagerImpl implements PluginManager, Service, EventListener {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<ContactId, TransportProperties> getRemoteProperties() {
|
||||
try {
|
||||
return transportPropertyManager.getRemoteProperties(id);
|
||||
@@ -386,6 +395,7 @@ class PluginManagerImpl implements PluginManager, Service, EventListener {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergeSettings(Settings s) {
|
||||
try {
|
||||
settingsManager.mergeSettings(s, id.getString());
|
||||
@@ -394,6 +404,7 @@ class PluginManagerImpl implements PluginManager, Service, EventListener {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergeLocalProperties(TransportProperties p) {
|
||||
try {
|
||||
transportPropertyManager.mergeLocalProperties(id, p);
|
||||
@@ -402,24 +413,29 @@ class PluginManagerImpl implements PluginManager, Service, EventListener {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int showChoice(String[] options, String... message) {
|
||||
return uiCallback.showChoice(options, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showConfirmationMessage(String... message) {
|
||||
return uiCallback.showConfirmationMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMessage(String... message) {
|
||||
uiCallback.showMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transportEnabled() {
|
||||
eventBus.broadcast(new TransportEnabledEvent(id));
|
||||
Plugin p = plugins.get(id);
|
||||
if (p != null) poller.pollNow(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transportDisabled() {
|
||||
eventBus.broadcast(new TransportDisabledEvent(id));
|
||||
}
|
||||
@@ -432,10 +448,12 @@ class PluginManagerImpl implements PluginManager, Service, EventListener {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readerCreated(TransportConnectionReader r) {
|
||||
connectionManager.manageIncomingConnection(id, r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writerCreated(ContactId c, TransportConnectionWriter w) {
|
||||
connectionManager.manageOutgoingConnection(c, id, w);
|
||||
}
|
||||
@@ -448,10 +466,12 @@ class PluginManagerImpl implements PluginManager, Service, EventListener {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incomingConnectionCreated(DuplexTransportConnection d) {
|
||||
connectionManager.manageIncomingConnection(id, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void outgoingConnectionCreated(ContactId c,
|
||||
DuplexTransportConnection d) {
|
||||
connectionManager.manageOutgoingConnection(c, id, d);
|
||||
|
||||
@@ -4,9 +4,6 @@ import org.briarproject.api.plugins.Plugin;
|
||||
|
||||
interface Poller {
|
||||
|
||||
/** Adds the given plugin to the collection of plugins to be polled. */
|
||||
void addPlugin(Plugin p);
|
||||
|
||||
/** Tells the poller to poll the given plugin immediately. */
|
||||
void pollNow(Plugin p);
|
||||
|
||||
|
||||
@@ -39,25 +39,17 @@ class PollerImpl implements Poller {
|
||||
tasks = new ConcurrentHashMap<TransportId, PollTask>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
timer.cancel();
|
||||
}
|
||||
|
||||
public void addPlugin(Plugin p) {
|
||||
// Randomise first polling interval
|
||||
if (p.shouldPoll())
|
||||
schedule(p, randomise(p.getPollingInterval()), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pollNow(Plugin p) {
|
||||
// Randomise next polling interval
|
||||
if (p.shouldPoll()) schedule(p, 0, true);
|
||||
}
|
||||
|
||||
private int randomise(int interval) {
|
||||
return (int) (interval * random.nextDouble());
|
||||
}
|
||||
|
||||
private void schedule(Plugin p, int interval, boolean randomiseNext) {
|
||||
// Replace any previously scheduled task for this plugin
|
||||
PollTask task = new PollTask(p, randomiseNext);
|
||||
@@ -68,6 +60,7 @@ class PollerImpl implements Poller {
|
||||
|
||||
private void poll(final Plugin p) {
|
||||
ioExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Polling " + p.getClass().getSimpleName());
|
||||
@@ -90,7 +83,8 @@ class PollerImpl implements Poller {
|
||||
public void run() {
|
||||
tasks.remove(plugin.getId());
|
||||
int interval = plugin.getPollingInterval();
|
||||
if (randomiseNext) interval = randomise(interval);
|
||||
if (randomiseNext)
|
||||
interval = (int) (interval * random.nextDouble());
|
||||
schedule(plugin, interval, false);
|
||||
poll(plugin);
|
||||
}
|
||||
|
||||
@@ -84,9 +84,6 @@ public class PluginManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(simplexPlugin)); // Created
|
||||
oneOf(simplexPlugin).start();
|
||||
will(returnValue(true)); // Started
|
||||
oneOf(simplexPlugin).shouldPoll();
|
||||
will(returnValue(true));
|
||||
oneOf(poller).addPlugin(simplexPlugin);
|
||||
// Second simplex plugin
|
||||
oneOf(simplexFailFactory).getId();
|
||||
will(returnValue(simplexFailId));
|
||||
@@ -105,8 +102,6 @@ public class PluginManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(duplexPlugin)); // Created
|
||||
oneOf(duplexPlugin).start();
|
||||
will(returnValue(true)); // Started
|
||||
oneOf(duplexPlugin).shouldPoll();
|
||||
will(returnValue(false));
|
||||
// Second duplex plugin
|
||||
oneOf(duplexFailFactory).getId();
|
||||
will(returnValue(duplexFailId));
|
||||
@@ -193,9 +188,6 @@ public class PluginManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(simplexPlugin)); // Created
|
||||
oneOf(simplexPlugin).start();
|
||||
will(returnValue(true)); // Started
|
||||
oneOf(simplexPlugin).shouldPoll();
|
||||
will(returnValue(true)); // Should poll
|
||||
oneOf(poller).addPlugin(simplexPlugin);
|
||||
// Second simplex plugin
|
||||
oneOf(simplexFactory1).getId();
|
||||
will(returnValue(simplexId1));
|
||||
@@ -204,8 +196,6 @@ public class PluginManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(simplexPlugin1)); // Created
|
||||
oneOf(simplexPlugin1).start();
|
||||
will(returnValue(true)); // Started
|
||||
oneOf(simplexPlugin1).shouldPoll();
|
||||
will(returnValue(false)); // Should not poll
|
||||
// First duplex plugin
|
||||
oneOf(pluginConfig).getDuplexFactories();
|
||||
will(returnValue(Arrays.asList(duplexFactory, duplexFactory1)));
|
||||
@@ -216,9 +206,6 @@ public class PluginManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(duplexPlugin)); // Created
|
||||
oneOf(duplexPlugin).start();
|
||||
will(returnValue(true)); // Started
|
||||
oneOf(duplexPlugin).shouldPoll();
|
||||
will(returnValue(true)); // Should poll
|
||||
oneOf(poller).addPlugin(duplexPlugin);
|
||||
// Second duplex plugin
|
||||
oneOf(duplexFactory1).getId();
|
||||
will(returnValue(duplexId1));
|
||||
@@ -227,8 +214,6 @@ public class PluginManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(duplexPlugin1)); // Created
|
||||
oneOf(duplexPlugin1).start();
|
||||
will(returnValue(true)); // Started
|
||||
oneOf(duplexPlugin1).shouldPoll();
|
||||
will(returnValue(false)); // Should not poll
|
||||
// Start listening for events
|
||||
oneOf(eventBus).addListener(with(any(EventListener.class)));
|
||||
// eventOccurred()
|
||||
|
||||
Reference in New Issue
Block a user