mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-23 16:19:54 +01:00
Removed polling semaphore (not needed - Modem.dial() will return false).
This commit is contained in:
@@ -14,7 +14,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Semaphore;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sf.briar.api.ContactId;
|
import net.sf.briar.api.ContactId;
|
||||||
@@ -43,7 +42,6 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
|||||||
private final SerialPortList serialPortList;
|
private final SerialPortList serialPortList;
|
||||||
private final DuplexPluginCallback callback;
|
private final DuplexPluginCallback callback;
|
||||||
private final long pollingInterval;
|
private final long pollingInterval;
|
||||||
private final Semaphore polling;
|
|
||||||
|
|
||||||
private volatile boolean running = false;
|
private volatile boolean running = false;
|
||||||
private volatile Modem modem = null;
|
private volatile Modem modem = null;
|
||||||
@@ -56,7 +54,6 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
|||||||
this.serialPortList = serialPortList;
|
this.serialPortList = serialPortList;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.pollingInterval = pollingInterval;
|
this.pollingInterval = pollingInterval;
|
||||||
polling = new Semaphore(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransportId getId() {
|
public TransportId getId() {
|
||||||
@@ -132,20 +129,13 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
|||||||
|
|
||||||
private void poll() {
|
private void poll() {
|
||||||
if(!running) return;
|
if(!running) return;
|
||||||
if(!polling.tryAcquire()) {
|
|
||||||
if(LOG.isLoggable(INFO))
|
|
||||||
LOG.info("Previous poll still in progress");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
// Get the ISO 3166 code for the caller's country
|
// Get the ISO 3166 code for the caller's country
|
||||||
String callerIso = callback.getLocalProperties().get("iso3166");
|
String callerIso = callback.getLocalProperties().get("iso3166");
|
||||||
if(StringUtils.isNullOrEmpty(callerIso)) return;
|
if(StringUtils.isNullOrEmpty(callerIso)) return;
|
||||||
// Call contacts one at a time in a random order
|
// Call contacts one at a time in a random order
|
||||||
Map<ContactId, TransportProperties> remote =
|
Map<ContactId, TransportProperties> remote =
|
||||||
callback.getRemoteProperties();
|
callback.getRemoteProperties();
|
||||||
List<ContactId> contacts =
|
List<ContactId> contacts = new ArrayList<ContactId>(remote.keySet());
|
||||||
new ArrayList<ContactId>(remote.keySet());
|
|
||||||
Collections.shuffle(contacts);
|
Collections.shuffle(contacts);
|
||||||
Iterator<ContactId> it = contacts.iterator();
|
Iterator<ContactId> it = contacts.iterator();
|
||||||
while(it.hasNext() && running) {
|
while(it.hasNext() && running) {
|
||||||
@@ -165,8 +155,7 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
|||||||
try {
|
try {
|
||||||
if(!modem.dial(number)) continue;
|
if(!modem.dial(number)) continue;
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
if(LOG.isLoggable(WARNING))
|
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||||
LOG.log(WARNING, e.toString(), e);
|
|
||||||
if(resetModem()) continue;
|
if(resetModem()) continue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -182,9 +171,6 @@ class ModemPlugin implements DuplexPlugin, Modem.Callback {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
polling.release();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DuplexTransportConnection createConnection(ContactId c) {
|
public DuplexTransportConnection createConnection(ContactId c) {
|
||||||
|
|||||||
Reference in New Issue
Block a user