Code formatting and small cleanups.

This commit is contained in:
akwizgran
2015-01-28 21:18:31 +00:00
parent fcb983a651
commit 47bd84122e
22 changed files with 371 additions and 439 deletions

View File

@@ -49,6 +49,10 @@ Service, EventListener {
private static final int PRIVATE_MESSAGE_NOTIFICATION_ID = 3;
private static final int GROUP_POST_NOTIFICATION_ID = 4;
private static final String CONTACT_URI =
"content://org.briarproject/contact";
private static final String GROUP_URI =
"content://org.briarproject/group";
private static final Logger LOG =
Logger.getLogger(AndroidNotificationManagerImpl.class.getName());
@@ -115,8 +119,7 @@ Service, EventListener {
else contactCounts.put(c, count + 1);
privateTotal++;
updatePrivateMessageNotification();
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -128,8 +131,7 @@ Service, EventListener {
if(count == null) return; // Already cleared
privateTotal -= count;
updatePrivateMessageNotification();
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -158,7 +160,7 @@ Service, EventListener {
Intent i = new Intent(appContext, ConversationActivity.class);
ContactId c = contactCounts.keySet().iterator().next();
i.putExtra("briar.CONTACT_ID", c.getInt());
i.setData(Uri.parse(String.format("content://contact/%s", c.getInt())));
i.setData(Uri.parse(CONTACT_URI + "/" + c.getInt()));
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
TaskStackBuilder t = TaskStackBuilder.create(appContext);
t.addParentStack(ConversationActivity.class);
@@ -203,8 +205,7 @@ Service, EventListener {
else groupCounts.put(g, count + 1);
groupTotal++;
updateGroupPostNotification();
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -216,8 +217,7 @@ Service, EventListener {
if(count == null) return; // Already cleared
groupTotal -= count;
updateGroupPostNotification();
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -245,8 +245,8 @@ Service, EventListener {
Intent i = new Intent(appContext, GroupActivity.class);
GroupId g = groupCounts.keySet().iterator().next();
i.putExtra("briar.GROUP_ID", g.getBytes());
String groupIdString = new String(g.getBytes());
i.setData(Uri.parse(String.format("content://org.brairproject.group/%s", groupIdString)));
String idHex = StringUtils.toHexString(g.getBytes());
i.setData(Uri.parse(GROUP_URI + "/" + idHex));
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
TaskStackBuilder t = TaskStackBuilder.create(appContext);
t.addParentStack(GroupActivity.class);
@@ -280,8 +280,7 @@ Service, EventListener {
privateTotal = groupTotal = 0;
clearPrivateMessageNotification();
clearGroupPostNotification();
}
finally{
} finally {
synchLock.unlock();
}
}

View File

@@ -35,8 +35,7 @@ class ReferenceManagerImpl implements ReferenceManager {
LOG.info(innerMap.size() + " handles for " + c.getName());
Object o = innerMap.get(handle);
return c.cast(o);
}
finally{
} finally {
synchLock.unlock();
}
@@ -57,8 +56,7 @@ class ReferenceManagerImpl implements ReferenceManager {
" after put");
}
return handle;
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -75,8 +73,7 @@ class ReferenceManagerImpl implements ReferenceManager {
" after remove");
}
return c.cast(o);
}
finally{
} finally {
synchLock.unlock();
}

View File

@@ -34,9 +34,6 @@ class AndroidLocationUtils implements LocationUtils {
* <ul>
* <li>Phone network. This works even when no SIM card is inserted, or a
* foreign SIM card is inserted.</li>
* <li><del>Location service (GPS/WiFi/etc).</del> <em>This is disabled for
* now, until we figure out an offline method of converting a long/lat
* into a country code, that doesn't involve a network call.</em>
* <li>SIM card. This is only an heuristic and assumes the user is not
* roaming.</li>
* <li>User locale. This is an even worse heuristic.</li>

View File

@@ -39,8 +39,7 @@ class FortunaGenerator {
digest.update(seed);
digest.digest(key, 0, KEY_BYTES);
incrementCounter();
}
finally{
} finally {
synchLock.unlock();
}
@@ -56,8 +55,7 @@ class FortunaGenerator {
throw new RuntimeException("Counter exhausted");
counter[i + 1]++;
}
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -67,8 +65,7 @@ class FortunaGenerator {
synchLock.lock();
try {
return counter;
}
finally{
} finally {
synchLock.unlock();
}
@@ -105,8 +102,7 @@ class FortunaGenerator {
for(int i = 0; i < KEY_BYTES; i++) newKey[i] = 0;
// Return the number of bytes written
return len;
}
finally{
} finally {
synchLock.unlock();
}
}

View File

@@ -44,8 +44,7 @@ class PseudoRandomImpl implements PseudoRandom {
System.arraycopy(state, offset, b, off, len);
offset += len;
return b;
}
finally{
} finally {
synchLock.unlock();
}
}

View File

@@ -441,8 +441,7 @@ abstract class JdbcDatabase implements Database<Connection> {
try {
if(closed) throw new DbClosedException();
txn = connections.poll();
}
finally{
} finally {
connectionsLock.unlock();
}
@@ -455,8 +454,7 @@ abstract class JdbcDatabase implements Database<Connection> {
connectionsLock.lock();
try {
openConnections++;
}
finally{
} finally {
connectionsLock.unlock();
}
}
@@ -474,8 +472,7 @@ abstract class JdbcDatabase implements Database<Connection> {
try {
connections.add(txn);
connectionsChanged.signalAll();
}
finally{
} finally {
connectionsLock.unlock();
}
} catch(SQLException e) {
@@ -491,10 +488,10 @@ abstract class JdbcDatabase implements Database<Connection> {
try {
openConnections--;
connectionsChanged.signalAll();
}
finally{
} finally {
connectionsLock.unlock();
} }
}
}
}
public void commitTransaction(Connection txn) throws DbException {
@@ -512,8 +509,7 @@ abstract class JdbcDatabase implements Database<Connection> {
try {
connections.add(txn);
connectionsChanged.signalAll();
}
finally{
} finally {
connectionsLock.unlock();
}
}
@@ -545,8 +541,7 @@ abstract class JdbcDatabase implements Database<Connection> {
openConnections -= connections.size();
connections.clear();
}
}
finally{
} finally {
connectionsLock.unlock();
}

View File

@@ -109,12 +109,12 @@ class ConnectorGroup extends Thread implements InvitationTask {
synchLock.lock();
try {
listeners.add(l);
return new InvitationState(localInvitationCode, remoteInvitationCode,
localConfirmationCode, remoteConfirmationCode, connected.get(),
connectionFailed, localCompared, remoteCompared, localMatched,
remoteMatched, remoteName);
}
finally{
return new InvitationState(localInvitationCode,
remoteInvitationCode, localConfirmationCode,
remoteConfirmationCode, connected.get(), connectionFailed,
localCompared, remoteCompared, localMatched, remoteMatched,
remoteName);
} finally {
synchLock.unlock();
}
}
@@ -140,8 +140,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
synchLock.lock();
try {
connectionFailed = true;
}
finally{
} finally {
synchLock.unlock();
}
for(InvitationListener l : listeners) l.connectionFailed();
@@ -177,8 +176,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
synchLock.lock();
try {
connectionFailed = true;
}
finally{
} finally {
synchLock.unlock();
}
for(InvitationListener l : listeners) l.connectionFailed();
@@ -212,8 +210,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
try {
localCompared = true;
localMatched = true;
}
finally{
} finally {
synchLock.unlock();
}
localConfirmationLatch.countDown();
@@ -224,8 +221,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
try {
localCompared = true;
localMatched = false;
}
finally{
} finally {
synchLock.unlock();
}
localConfirmationLatch.countDown();
@@ -243,8 +239,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
try {
localConfirmationCode = localCode;
remoteConfirmationCode = remoteCode;
}
finally{
} finally {
synchLock.unlock();
}
for(InvitationListener l : listeners)
@@ -260,8 +255,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
synchLock.lock();
try {
return localMatched;
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -271,8 +265,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
try {
remoteCompared = true;
remoteMatched = true;
}
finally{
} finally {
synchLock.unlock();
}
for(InvitationListener l : listeners) l.remoteConfirmationSucceeded();
@@ -283,8 +276,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
try {
remoteCompared = true;
remoteMatched = false;
}
finally{
} finally {
synchLock.unlock();
}
for(InvitationListener l : listeners) l.remoteConfirmationFailed();
@@ -295,8 +287,7 @@ class ConnectorGroup extends Thread implements InvitationTask {
synchLock.lock();
try {
remoteName = name;
}
finally{
} finally {
synchLock.unlock();
}
for(InvitationListener l : listeners)

View File

@@ -27,8 +27,7 @@ class ShutdownManagerImpl implements ShutdownManager {
hooks.put(handle, hook);
Runtime.getRuntime().addShutdownHook(hook);
return handle;
}
finally{
} finally {
synchLock.unlock();
}
@@ -44,8 +43,7 @@ class ShutdownManagerImpl implements ShutdownManager {
Thread hook = hooks.remove(handle);
if(hook == null) return false;
else return Runtime.getRuntime().removeShutdownHook(hook);
}
finally{
} finally {
synchLock.unlock();
}

View File

@@ -9,9 +9,9 @@ import org.briarproject.api.messaging.Group;
import org.briarproject.api.messaging.GroupFactory;
import org.briarproject.api.messaging.MessageFactory;
import org.briarproject.api.messaging.MessageVerifier;
import org.briarproject.api.messaging.MessagingSessionFactory;
import org.briarproject.api.messaging.PacketReaderFactory;
import org.briarproject.api.messaging.PacketWriterFactory;
import org.briarproject.api.messaging.MessagingSessionFactory;
import org.briarproject.api.messaging.SubscriptionUpdate;
import org.briarproject.api.messaging.UnverifiedMessage;
import org.briarproject.api.serial.StructReader;

View File

@@ -61,8 +61,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
} else {
contactCounts.put(c, count + 1);
}
}
finally{
} finally {
synchLock.unlock();
}
@@ -94,8 +93,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
} else {
contactCounts.put(c, count - 1);
}
}
finally{
} finally {
synchLock.unlock();
}
@@ -114,8 +112,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
List<ContactId> ids = new ArrayList<ContactId>(m.keySet());
if(LOG.isLoggable(INFO)) LOG.info(ids.size() + " contacts connected");
return Collections.unmodifiableList(ids);
}
finally{
} finally {
synchLock.unlock();
}
@@ -125,8 +122,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
synchLock.lock();
try {
return contactCounts.containsKey(c);
}
finally{
} finally {
synchLock.unlock();
}

View File

@@ -1,11 +1,12 @@
package org.briarproject.reliability;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import java.io.IOException;
import java.util.Comparator;
import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -43,7 +44,7 @@ class Receiver implements ReadHandler {
while(now < end && valid) {
if(dataFrames.isEmpty()) {
// Wait for a data frame
dataFrameAvailable.await(end - now, TimeUnit.MILLISECONDS);
dataFrameAvailable.await(end - now, MILLISECONDS);
} else {
Data d = dataFrames.first();
if(d.getSequenceNumber() == nextSequenceNumber) {
@@ -55,15 +56,14 @@ class Receiver implements ReadHandler {
return d;
} else {
// Wait for the next in-order data frame
dataFrameAvailable.await(end - now, TimeUnit.MILLISECONDS);
dataFrameAvailable.await(end - now, MILLISECONDS);
}
}
now = clock.currentTimeMillis();
}
if(valid) throw new IOException("Read timed out");
throw new IOException("Connection closed");
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -73,8 +73,7 @@ class Receiver implements ReadHandler {
synchLock.lock();
try {
dataFrameAvailable.signalAll();
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -134,8 +133,7 @@ class Receiver implements ReadHandler {
}
// Acknowledge the data frame even if it's a duplicate
sender.sendAck(sequenceNumber, windowSize);
}
finally{
} finally {
synchLock.unlock();
}
}

View File

@@ -1,11 +1,12 @@
package org.briarproject.reliability;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -101,9 +102,9 @@ class Sender {
// Don't accept an unreasonably large window size
windowSize = Math.min(a.getWindowSize(), MAX_WINDOW_SIZE);
// If space has become available, notify any waiting writers
if(windowSize > oldWindowSize || foundIndex != -1) sendWindowAvailable.signalAll();
}
finally{
if(windowSize > oldWindowSize || foundIndex != -1)
sendWindowAvailable.signalAll();
} finally {
synchLock.unlock();
}
// Fast retransmission
@@ -145,8 +146,7 @@ class Sender {
}
}
}
}
finally{
} finally {
synchLock.unlock();
}
// Send a window probe if necessary
@@ -171,7 +171,7 @@ class Sender {
long now = clock.currentTimeMillis(), end = now + WRITE_TIMEOUT;
while(now < end && outstandingBytes + payloadLength >= windowSize) {
dataWaiting = true;
sendWindowAvailable.await(end - now, TimeUnit.MILLISECONDS);
sendWindowAvailable.await(end - now, MILLISECONDS);
now = clock.currentTimeMillis();
}
if(outstandingBytes + payloadLength >= windowSize)
@@ -179,8 +179,7 @@ class Sender {
outstanding.add(new Outstanding(d, now));
outstandingBytes += payloadLength;
dataWaiting = false;
}
finally{
} finally {
synchLock.unlock();
}
writeHandler.handleWrite(d.getBuffer());
@@ -189,9 +188,9 @@ class Sender {
void flush() throws IOException, InterruptedException {
synchLock.lock();
try {
while(dataWaiting || !outstanding.isEmpty()) sendWindowAvailable.await();
}
finally{
while(dataWaiting || !outstanding.isEmpty())
sendWindowAvailable.await();
} finally {
synchLock.unlock();
}
}

View File

@@ -78,7 +78,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
synchLock.lock();
try {
eventBus.addListener(this);
// Load the temporary secrets and transport latencies from the database
// Load the temporary secrets and transport latencies from the DB
Collection<TemporarySecret> secrets;
try {
secrets = db.getSecrets();
@@ -89,15 +89,18 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
}
// Work out what phase of its lifecycle each secret is in
long now = clock.currentTimeMillis();
Collection<TemporarySecret> dead = assignSecretsToMaps(now, secrets);
Collection<TemporarySecret> dead =
assignSecretsToMaps(now, secrets);
// Replace any dead secrets
Collection<TemporarySecret> created = replaceDeadSecrets(now, dead);
if(!created.isEmpty()) {
// Store any secrets that have been created, removing any dead ones
// Store any secrets that have been created,
// removing any dead ones
try {
db.addSecrets(created);
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
if(LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);
return false;
}
}
@@ -109,10 +112,10 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
for(TemporarySecret s : newSecrets.values())
tagRecogniser.addSecret(s);
// Schedule periodic key rotation
timer.scheduleAtFixedRate(this, MS_BETWEEN_CHECKS, MS_BETWEEN_CHECKS);
timer.scheduleAtFixedRate(this, MS_BETWEEN_CHECKS,
MS_BETWEEN_CHECKS);
return true;
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -218,8 +221,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
currentSecrets.clear();
newSecrets.clear();
return true;
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -246,8 +248,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
}
byte[] secret = s.getSecret();
return new StreamContext(c, t, secret, streamNumber, s.getAlice());
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -287,8 +288,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
tagRecogniser.addSecret(s1);
tagRecogniser.addSecret(s2);
tagRecogniser.addSecret(s3);
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -327,8 +327,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
// Pass any secrets that have been created to the recogniser
for(TemporarySecret s : created) tagRecogniser.addSecret(s);
}
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -405,8 +404,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
removeSecrets(c, oldSecrets);
removeSecrets(c, currentSecrets);
removeSecrets(c, newSecrets);
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -425,8 +423,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
synchLock.lock();
try {
maxLatencies.put(event.getTransportId(), event.getMaxLatency());
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -450,8 +447,7 @@ class KeyManagerImpl extends TimerTask implements KeyManager, EventListener {
removeSecrets(t, oldSecrets);
removeSecrets(t, currentSecrets);
removeSecrets(t, newSecrets);
}
finally{
} finally {
synchLock.unlock();
}
}

View File

@@ -39,8 +39,7 @@ class TagRecogniserImpl implements TagRecogniser {
synchLock.lock();
try {
r = recognisers.get(t);
}
finally{
} finally {
synchLock.unlock();
}
if(r == null) return null;
@@ -57,8 +56,7 @@ class TagRecogniserImpl implements TagRecogniser {
r = new TransportTagRecogniser(crypto, db, t);
recognisers.put(t, r);
}
}
finally{
} finally {
synchLock.unlock();
}
r.addSecret(s);
@@ -69,8 +67,7 @@ class TagRecogniserImpl implements TagRecogniser {
synchLock.lock();
try {
r = recognisers.get(t);
}
finally{
} finally {
synchLock.unlock();
}
if(r != null) r.removeSecret(c, period);
@@ -81,8 +78,7 @@ class TagRecogniserImpl implements TagRecogniser {
try {
for(TransportTagRecogniser r : recognisers.values())
r.removeSecrets(c);
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -91,8 +87,7 @@ class TagRecogniserImpl implements TagRecogniser {
synchLock.lock();
try {
recognisers.remove(t);
}
finally{
} finally {
synchLock.unlock();
}
@@ -103,8 +98,7 @@ class TagRecogniserImpl implements TagRecogniser {
try {
for(TransportTagRecogniser r : recognisers.values())
r.removeSecrets();
}
finally{
} finally {
synchLock.unlock();
}

View File

@@ -67,8 +67,7 @@ class TransportTagRecogniser {
t.window.getCentre(), t.window.getBitmap());
return new StreamContext(t.contactId, transportId, t.secret,
t.streamNumber, t.alice);
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -96,8 +95,7 @@ class TransportTagRecogniser {
// Create a removal context to remove the window and the tags later
RemovalContext r = new RemovalContext(window, secret, alice);
removalMap.put(new RemovalKey(contactId, period), r);
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -109,8 +107,7 @@ class TransportTagRecogniser {
RemovalContext removed = removalMap.remove(k);
if(removed == null) throw new IllegalArgumentException();
removeSecret(removed);
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -132,9 +129,9 @@ class TransportTagRecogniser {
Collection<RemovalKey> keysToRemove = new ArrayList<RemovalKey>();
for(RemovalKey k : removalMap.keySet())
if(k.contactId.equals(c)) keysToRemove.add(k);
for(RemovalKey k : keysToRemove) removeSecret(k.contactId, k.period);
}
finally{
for(RemovalKey k : keysToRemove)
removeSecret(k.contactId, k.period);
} finally {
synchLock.unlock();
}
}
@@ -145,8 +142,7 @@ class TransportTagRecogniser {
for(RemovalContext r : removalMap.values()) removeSecret(r);
assert tagMap.isEmpty();
removalMap.clear();
}
finally{
} finally {
synchLock.unlock();
}
}

View File

@@ -1,7 +1,8 @@
package org.briarproject.util;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
public class LatchedReference<T> {
@@ -23,7 +24,7 @@ public class LatchedReference<T> {
}
public T waitForReference(long timeout) throws InterruptedException {
latch.await(timeout, TimeUnit.MILLISECONDS);
latch.await(timeout, MILLISECONDS);
return reference.get();
}
}

View File

@@ -58,8 +58,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
try {
if(!initialised) initialise();
return super.addShutdownHook(r);
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -95,8 +94,7 @@ class WindowsShutdownManagerImpl extends ShutdownManagerImpl {
}
}
if(interrupted) Thread.currentThread().interrupt();
}
finally{
} finally {
synchLock.unlock();
}
}

View File

@@ -1,10 +1,11 @@
package org.briarproject.plugins.file;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -56,9 +57,8 @@ class PollingRemovableDriveMonitor implements RemovableDriveMonitor, Runnable {
while(running) {
pollingLock.lock();
try {
stopPolling.await(pollingInterval, TimeUnit.MILLISECONDS);
}
finally{
stopPolling.await(pollingInterval, MILLISECONDS);
} finally {
pollingLock.unlock();
}
if(!running) return;

View File

@@ -4,7 +4,6 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -47,8 +46,7 @@ JNotifyListener {
triedLoad = true;
}
if(loadError != null) throw new IOException(loadError.toString());
}
finally{
} finally {
staticSynchLock.unlock();
}
}
@@ -68,8 +66,7 @@ JNotifyListener {
started = true;
this.callback = callback;
this.watches.addAll(watches);
}
finally{
} finally {
synchLock.unlock();
}
}
@@ -85,8 +82,7 @@ JNotifyListener {
callback = null;
watches = new ArrayList<Integer>(this.watches);
this.watches.clear();
}
finally{
} finally {
synchLock.unlock();
}
for(Integer w : watches) JNotify.removeWatch(w);
@@ -97,8 +93,7 @@ JNotifyListener {
synchLock.lock();
try {
callback = this.callback;
}
finally{
} finally {
synchLock.unlock();
}
if(callback != null)

View File

@@ -91,7 +91,8 @@ class CountryCodes {
new Country("GP", "Guadeloupe", "590", "00", ""),
new Country("GQ", "Equatorial Guinea", "240", "00", ""),
new Country("GR", "Greece", "30", "00", ""),
new Country("GS", "South Georgia and the South Sandwich Islands", "995", "8**10", "8"),
new Country("GS", "South Georgia and the South Sandwich Islands",
"995", "8**10", "8"),
new Country("GT", "Guatemala", "502", "00", ""),
new Country("GU", "Guam", "1", "011", "1"),
new Country("GW", "Guinea-Bissau", "245", "00", ""),

View File

@@ -1,5 +1,6 @@
package org.briarproject.plugins.modem;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static jssc.SerialPort.PURGE_RXCLEAR;
@@ -10,7 +11,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.concurrent.Executor;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -105,12 +105,11 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
long now = clock.currentTimeMillis();
long end = now + OK_TIMEOUT;
while(now < end && !initialised) {
initialisedStateChanged.await(end - now, TimeUnit.MILLISECONDS);
initialisedStateChanged.await(end - now, MILLISECONDS);
now = clock.currentTimeMillis();
}
success = initialised;
}
finally{
} finally {
synchLock.unlock();
}
} catch(InterruptedException e) {
@@ -143,8 +142,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
connected = false;
initialisedStateChanged.signalAll();
connectedStateChanged.signalAll();
}
finally{
} finally {
synchLock.unlock();
}
// Hang up if necessary and close the port
@@ -174,8 +172,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
reliability = this.reliability;
this.reliability = null;
connected = false;
}
finally{
} finally {
synchLock.unlock();
}
reliability.stop();
@@ -214,8 +211,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
return false;
}
this.reliability = reliability;
}
finally{
} finally {
synchLock.unlock();
}
reliability.start();
@@ -234,12 +230,11 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
long now = clock.currentTimeMillis();
long end = now + CONNECT_TIMEOUT;
while(now < end && initialised && !connected) {
connectedStateChanged.await(end - now, TimeUnit.MILLISECONDS);
connectedStateChanged.await(end - now, MILLISECONDS);
now = clock.currentTimeMillis();
}
if(connected) return true;
}
finally{
} finally {
synchLock.unlock();
}
} catch(InterruptedException e) {
@@ -259,8 +254,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
synchLock.lock();
try {
reliability = this.reliability;
}
finally{
} finally {
synchLock.unlock();
}
if(reliability == null) throw new IOException("Not connected");
@@ -272,8 +266,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
synchLock.lock();
try {
reliability = this.reliability;
}
finally{
} finally {
synchLock.unlock();
}
if(reliability == null) throw new IOException("Not connected");
@@ -328,8 +321,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
synchLock.lock();
try {
reliability = this.reliability;
}
finally{
} finally {
synchLock.unlock();
}
if(reliability == null) return false;
@@ -354,8 +346,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
try {
connected = true;
connectedStateChanged.signalAll();
}
finally{
} finally {
synchLock.unlock();
}
// There might be data in the buffer as well as text
@@ -372,8 +363,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
try {
connected = false;
connectedStateChanged.signalAll();
}
finally{
} finally {
synchLock.unlock();
}
} else if(s.equals("OK")) {
@@ -381,8 +371,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
try {
initialised = true;
initialisedStateChanged.signalAll();
}
finally{
} finally {
synchLock.unlock();
}
} else if(s.equals("RING")) {
@@ -422,8 +411,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
return;
}
this.reliability = reliability;
}
finally{
} finally {
synchLock.unlock();
}
reliability.start();
@@ -442,12 +430,11 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
long now = clock.currentTimeMillis();
long end = now + CONNECT_TIMEOUT;
while(now < end && initialised && !connected) {
connectedStateChanged.await(end - now, TimeUnit.MILLISECONDS);
connectedStateChanged.await(end - now, MILLISECONDS);
now = clock.currentTimeMillis();
}
success = connected;
}
finally{
} finally {
synchLock.unlock();
}
} catch(InterruptedException e) {

View File

@@ -11,7 +11,6 @@ import org.briarproject.api.event.ContactConnectedEvent;
import org.briarproject.api.event.ContactDisconnectedEvent;
import org.briarproject.api.event.EventBus;
import org.briarproject.api.plugins.ConnectionRegistry;
import org.briarproject.plugins.ConnectionRegistryImpl;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.junit.Test;