Use the transport's idle timeout, not a hardcoded value.

This commit is contained in:
akwizgran
2014-12-14 15:18:39 +00:00
parent d4fa656dbb
commit 29a6596ee3
15 changed files with 77 additions and 26 deletions

View File

@@ -107,14 +107,27 @@ class ConnectionManagerImpl implements ConnectionManager {
}
}
private MessagingSession createOutgoingSession(StreamContext ctx,
TransportConnectionWriter w, boolean duplex) throws IOException {
private MessagingSession createSimplexOutgoingSession(StreamContext ctx,
TransportConnectionWriter w) throws IOException {
try {
StreamWriter streamWriter = streamWriterFactory.createStreamWriter(
w.getOutputStream(), w.getMaxFrameLength(), ctx);
return messagingSessionFactory.createOutgoingSession(
return messagingSessionFactory.createSimplexOutgoingSession(
ctx.getContactId(), ctx.getTransportId(), w.getMaxLatency(),
duplex, streamWriter.getOutputStream());
streamWriter.getOutputStream());
} finally {
ByteUtils.erase(ctx.getSecret());
}
}
private MessagingSession createDuplexOutgoingSession(StreamContext ctx,
TransportConnectionWriter w) throws IOException {
try {
StreamWriter streamWriter = streamWriterFactory.createStreamWriter(
w.getOutputStream(), w.getMaxFrameLength(), ctx);
return messagingSessionFactory.createDuplexOutgoingSession(
ctx.getContactId(), ctx.getTransportId(), w.getMaxLatency(),
w.getMaxIdleTime(), streamWriter.getOutputStream());
} finally {
ByteUtils.erase(ctx.getSecret());
}
@@ -199,7 +212,7 @@ class ConnectionManagerImpl implements ConnectionManager {
connectionRegistry.registerConnection(contactId, transportId);
try {
// Create and run the outgoing session
createOutgoingSession(ctx, writer, false).run();
createSimplexOutgoingSession(ctx, writer).run();
disposeWriter(false);
} catch(IOException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
@@ -287,7 +300,7 @@ class ConnectionManagerImpl implements ConnectionManager {
}
try {
// Create and run the outgoing session
outgoingSession = createOutgoingSession(ctx, writer, true);
outgoingSession = createDuplexOutgoingSession(ctx, writer);
outgoingSession.run();
disposeWriter(false);
} catch(IOException e) {
@@ -353,7 +366,7 @@ class ConnectionManagerImpl implements ConnectionManager {
});
try {
// Create and run the outgoing session
outgoingSession = createOutgoingSession(ctx, writer, true);
outgoingSession = createDuplexOutgoingSession(ctx, writer);
outgoingSession.run();
disposeWriter(false);
} catch(IOException e) {

View File

@@ -56,6 +56,10 @@ public abstract class FilePlugin implements SimplexPlugin {
return maxLatency;
}
public long getMaxIdleTime() {
return Long.MAX_VALUE; // We don't need keepalives
}
public boolean isRunning() {
return running;
}

View File

@@ -35,6 +35,10 @@ class FileTransportWriter implements TransportConnectionWriter {
return plugin.getMaxLatency();
}
public long getMaxIdleTime() {
return plugin.getMaxIdleTime();
}
public long getCapacity() {
return capacity;
}

View File

@@ -67,6 +67,10 @@ class TcpTransportConnection implements DuplexTransportConnection {
return plugin.getMaxLatency();
}
public long getMaxIdleTime() {
return plugin.getMaxIdleTime();
}
public long getCapacity() {
return Long.MAX_VALUE;
}