Removed the DB listener when the connection is closed.

This commit is contained in:
akwizgran
2011-12-07 21:37:13 +00:00
parent e2cb1027af
commit c728377ae1

View File

@@ -184,10 +184,9 @@ abstract class StreamConnection implements DatabaseListener {
void write() { void write() {
try { try {
db.addListener(this);
OutputStream out = createConnectionWriter().getOutputStream(); OutputStream out = createConnectionWriter().getOutputStream();
writer = protoWriterFactory.createProtocolWriter(out); writer = protoWriterFactory.createProtocolWriter(out);
// Start receiving database events
db.addListener(this);
// Send the initial packets: transports, subs, acks, offer // Send the initial packets: transports, subs, acks, offer
dbExecutor.execute(new GenerateTransportUpdate()); dbExecutor.execute(new GenerateTransportUpdate());
dbExecutor.execute(new GenerateSubscriptionUpdate()); dbExecutor.execute(new GenerateSubscriptionUpdate());
@@ -215,6 +214,8 @@ abstract class StreamConnection implements DatabaseListener {
} catch(IOException e) { } catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.getMessage()); if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.getMessage());
transport.dispose(false); transport.dispose(false);
} finally {
db.removeListener(this);
} }
} }