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 {
if (ack.attribute("h") != null) {
long count = Long.valueOf(ack.attributeValue("h"));
// Remove stanzas from temporary storage as now acknowledged
long i = getClientProcessedStanzas();
Log.debug("Ack: h={} mine={} length={}", count, i, unacknowledgedServerStanzas.size());
if (count < i) {
Log.debug("Ack: h={} mine={} length={}", count, clientProcessedStanzas, unacknowledgedServerStanzas.size());
if (count < clientProcessedStanzas) {
/* Consider rollover? */
Log.debug("Maybe rollover");
if (i > mask) {
while (count < i) {
if (clientProcessedStanzas > mask) {
while (count < clientProcessedStanzas) {
Log.debug("Rolling...");
count += mask + 1;
}
}
}
while (i < count) {
while (clientProcessedStanzas < count) {
unacknowledgedServerStanzas.removeFirst();
i++;
Log.debug("In Ack: h={} mine={} length={}", count, i, unacknowledgedServerStanzas.size());
clientProcessedStanzas++;
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 {
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