Poll plugins when connectivity changes. Bug #66.

This should enable us to connect to contacts faster at startup and
whenever a new means of connecting becomes available.
This commit is contained in:
akwizgran
2014-04-04 22:04:05 +01:00
parent 9f8d12e6c2
commit 08b91d2483
11 changed files with 113 additions and 136 deletions

View File

@@ -91,35 +91,37 @@ class BluetoothPlugin implements DuplexPlugin {
if(LOG.isLoggable(INFO))
LOG.info("Local address " + localDevice.getBluetoothAddress());
running = true;
pluginExecutor.execute(new Runnable() {
public void run() {
bind();
}
});
bind();
return true;
}
private void bind() {
if(!running) return;
// Advertise the Bluetooth address to contacts
TransportProperties p = new TransportProperties();
p.put("address", localDevice.getBluetoothAddress());
callback.mergeLocalProperties(p);
// Bind a server socket to accept connections from contacts
String url = makeUrl("localhost", getUuid());
StreamConnectionNotifier ss;
try {
ss = (StreamConnectionNotifier) Connector.open(url);
} catch(IOException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
return;
}
if(!running) {
tryToClose(ss);
return;
}
socket = ss;
acceptContactConnections(ss);
pluginExecutor.execute(new Runnable() {
public void run() {
if(!running) return;
// Advertise the Bluetooth address to contacts
TransportProperties p = new TransportProperties();
p.put("address", localDevice.getBluetoothAddress());
callback.mergeLocalProperties(p);
// Bind a server socket to accept connections from contacts
String url = makeUrl("localhost", getUuid());
StreamConnectionNotifier ss;
try {
ss = (StreamConnectionNotifier) Connector.open(url);
} catch(IOException e) {
if(LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);
return;
}
if(!running) {
tryToClose(ss);
return;
}
socket = ss;
callback.pollNow();
acceptContactConnections(ss);
}
});
}
private String makeUrl(String address, String uuid) {