Commit 3b5e22bb authored by Guus der Kinderen's avatar Guus der Kinderen

OF-1028: Avoid potential concurrency issue.

Prevent exposing access to a field that we're careful to modify
under lock. Again, a defensive copy is a suitable alternative,
but seems unneeded.
parent bac4c600
...@@ -138,25 +138,26 @@ public class StreamManager { ...@@ -138,25 +138,26 @@ public class StreamManager {
if (ack.attribute("h") != null) { if (ack.attribute("h") != null) {
long count = Long.valueOf(ack.attributeValue("h")); long count = Long.valueOf(ack.attributeValue("h"));
// Remove stanzas from temporary storage as now acknowledged // Remove stanzas from temporary storage as now acknowledged
long i = getClientProcessedStanzas(); Log.debug("Ack: h={} mine={} length={}", count, clientProcessedStanzas, unacknowledgedServerStanzas.size());
Log.debug("Ack: h={} mine={} length={}", count, i, unacknowledgedServerStanzas.size()); if (count < clientProcessedStanzas) {
if (count < i) {
/* Consider rollover? */ /* Consider rollover? */
Log.debug("Maybe rollover"); Log.debug("Maybe rollover");
if (i > mask) { if (clientProcessedStanzas > mask) {
while (count < i) { while (count < clientProcessedStanzas) {
Log.debug("Rolling..."); Log.debug("Rolling...");
count += mask + 1; count += mask + 1;
} }
} }
} }
while (i < count) { while (clientProcessedStanzas < count) {
unacknowledgedServerStanzas.removeFirst(); unacknowledgedServerStanzas.removeFirst();
i++; clientProcessedStanzas++;
Log.debug("In Ack: h={} mine={} length={}", count, i, unacknowledgedServerStanzas.size()); Log.debug("In Ack: h={} mine={} length={}", count, clientProcessedStanzas, unacknowledgedServerStanzas.size());
} }
setClientProcessedStanzas(count); if(count >= clientProcessedStanzas) {
clientProcessedStanzas = count;
}
} }
} }
} }
...@@ -281,23 +282,4 @@ public class StreamManager { ...@@ -281,23 +282,4 @@ public class StreamManager {
this.serverProcessedStanzas++; this.serverProcessedStanzas++;
} }
} }
/**
* Retrieve the number of stanzas processed by the client since
* Stream Management was enabled.
* @return number of stanzas processed by the client
*/
public long getClientProcessedStanzas() {
return clientProcessedStanzas;
}
/**
* Sets the count of stanzas processed by the client since
* Stream Management was enabled.
*/
public void setClientProcessedStanzas(long count) {
if(count >= clientProcessedStanzas) {
clientProcessedStanzas = count;
}
}
} }
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