forked from mirror/monocles_chat
Revert "flush stanzas in batches" (Daniel Gultsch)
This commit is contained in:
parent
5dadaab50c
commit
f36efee885
1 changed files with 4 additions and 18 deletions
|
@ -8,23 +8,18 @@ import java.io.OutputStreamWriter;
|
|||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import eu.siacs.conversations.Config;
|
||||
import eu.siacs.conversations.xmpp.stanzas.AbstractStanza;
|
||||
|
||||
public class TagWriter {
|
||||
|
||||
private static final int FLUSH_DELAY = 400;
|
||||
|
||||
private OutputStreamWriter outputStream;
|
||||
private boolean finished = false;
|
||||
private LinkedBlockingQueue<AbstractStanza> writeQueue = new LinkedBlockingQueue<AbstractStanza>();
|
||||
private CountDownLatch stanzaWriterCountDownLatch = null;
|
||||
private Thread asyncStanzaWriter = new Thread() {
|
||||
|
||||
private final AtomicInteger batchStanzaCount = new AtomicInteger(0);
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
stanzaWriterCountDownLatch = new CountDownLatch(1);
|
||||
|
@ -33,21 +28,12 @@ public class TagWriter {
|
|||
break;
|
||||
}
|
||||
try {
|
||||
final AbstractStanza stanza = writeQueue.poll(FLUSH_DELAY, TimeUnit.MILLISECONDS);
|
||||
if (stanza != null) {
|
||||
batchStanzaCount.incrementAndGet();
|
||||
outputStream.write(stanza.toString());
|
||||
} else {
|
||||
final int batch = batchStanzaCount.getAndSet(0);
|
||||
if (batch > 1) {
|
||||
Log.d(Config.LOGTAG, "flushing " + batch + " stanzas");
|
||||
}
|
||||
AbstractStanza output = writeQueue.take();
|
||||
outputStream.write(output.toString());
|
||||
if (writeQueue.size() == 0) {
|
||||
outputStream.flush();
|
||||
final AbstractStanza nextStanza = writeQueue.take();
|
||||
batchStanzaCount.incrementAndGet();
|
||||
outputStream.write(nextStanza.toString());
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
} catch (Exception e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue