Commit 422e7ff6 authored by Guus der Kinderen's avatar Guus der Kinderen

OF-1028: Request ack only when unack'ed stanzas exist.

The peer might send unsollicited acks. Instead of requesting ack after every
so many stanzas that we send out, only request ack if we have unack'ed stanzas.
parent c1b3f28f
......@@ -57,12 +57,6 @@ public class StreamManager {
*/
private String namespace;
/**
* Count of how many stanzas/packets
* have been sent from the server to the client (not necessarily processed)
*/
private long serverSentStanzas = 0;
/**
* Count of how many stanzas/packets
* sent from the client that the server has processed
......@@ -229,15 +223,19 @@ public class StreamManager {
public void sentStanza(Packet packet) {
if(isEnabled()) {
synchronized (this) {
this.serverSentStanzas++;
final long requestFrequency = JiveGlobals.getLongProperty( "stream.management.requestFrequency", 5 );
final boolean requestAck;
synchronized (this) {
// The next ID is one higher than the last stanza that was sent (which might be unacknowledged!)
final long x = 1 + ( unacknowledgedServerStanzas.isEmpty() ? clientProcessedStanzas : unacknowledgedServerStanzas.getLast().x );
unacknowledgedServerStanzas.addLast( new StreamManager.UnackedPacket( x, packet.createCopy() ) );
Log.debug("Added stanza of type {} to collection of unacknowledged stanzas (x={}). Collection size is now {} / {}", packet.getElement().getName(), x, serverSentStanzas, unacknowledgedServerStanzas.size());
requestAck = unacknowledgedServerStanzas.size() >= requestFrequency;
Log.debug("Added stanza of type {} to collection of unacknowledged stanzas (x={}). Collection size is now {} / {}", packet.getElement().getName(), x, unacknowledgedServerStanzas.size());
}
if(serverSentStanzas % JiveGlobals.getLongProperty("stream.management.requestFrequency", 5) == 0) {
if(requestAck) {
sendServerRequest();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment