Ensure semaphore is released if an exception is thrown.

This commit is contained in:
akwizgran
2011-12-06 00:03:05 +00:00
parent f474ed229d
commit 00df158ad6
2 changed files with 18 additions and 9 deletions

View File

@@ -72,9 +72,10 @@ class IncomingBatchConnection {
} catch(DbException e) {
if(LOG.isLoggable(Level.WARNING))
LOG.warning(e.getMessage());
}
} finally {
semaphore.release();
}
}
});
} else if(proto.hasBatch()) {
final UnverifiedBatch b = proto.readBatch();
@@ -90,9 +91,10 @@ class IncomingBatchConnection {
} catch(GeneralSecurityException e) {
if(LOG.isLoggable(Level.WARNING))
LOG.warning(e.getMessage());
}
} finally {
semaphore.release();
}
}
});
} else if(proto.hasSubscriptionUpdate()) {
final SubscriptionUpdate s = proto.readSubscriptionUpdate();
@@ -105,9 +107,10 @@ class IncomingBatchConnection {
} catch(DbException e) {
if(LOG.isLoggable(Level.WARNING))
LOG.warning(e.getMessage());
}
} finally {
semaphore.release();
}
}
});
} else if(proto.hasTransportUpdate()) {
final TransportUpdate t = proto.readTransportUpdate();
@@ -120,9 +123,10 @@ class IncomingBatchConnection {
} catch(DbException e) {
if(LOG.isLoggable(Level.WARNING))
LOG.warning(e.getMessage());
}
} finally {
semaphore.release();
}
}
});
} else {
throw new FormatException();

View File

@@ -140,9 +140,10 @@ abstract class StreamConnection implements DatabaseListener {
} catch(DbException e) {
if(LOG.isLoggable(Level.WARNING))
LOG.warning(e.getMessage());
}
} finally {
semaphore.release();
}
}
});
} else if(proto.hasBatch()) {
final UnverifiedBatch b = proto.readBatch();
@@ -158,9 +159,10 @@ abstract class StreamConnection implements DatabaseListener {
} catch(GeneralSecurityException e) {
if(LOG.isLoggable(Level.WARNING))
LOG.warning(e.getMessage());
}
} finally {
semaphore.release();
}
}
});
} else if(proto.hasOffer()) {
Offer o = proto.readOffer();
@@ -200,9 +202,10 @@ abstract class StreamConnection implements DatabaseListener {
} catch(DbException e) {
if(LOG.isLoggable(Level.WARNING))
LOG.warning(e.getMessage());
}
} finally {
semaphore.release();
}
}
});
// Store the requested message IDs and notify the writer
synchronized(this) {
@@ -223,9 +226,10 @@ abstract class StreamConnection implements DatabaseListener {
} catch(DbException e) {
if(LOG.isLoggable(Level.WARNING))
LOG.warning(e.getMessage());
}
} finally {
semaphore.release();
}
}
});
} else if(proto.hasTransportUpdate()) {
final TransportUpdate t = proto.readTransportUpdate();
@@ -238,9 +242,10 @@ abstract class StreamConnection implements DatabaseListener {
} catch(DbException e) {
if(LOG.isLoggable(Level.WARNING))
LOG.warning(e.getMessage());
}
} finally {
semaphore.release();
}
}
});
} else {
throw new FormatException();