aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/xml
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/pixart/messenger/xml')
-rw-r--r--src/main/java/de/pixart/messenger/xml/TagWriter.java17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/main/java/de/pixart/messenger/xml/TagWriter.java b/src/main/java/de/pixart/messenger/xml/TagWriter.java
index c6b84170d..53f04128f 100644
--- a/src/main/java/de/pixart/messenger/xml/TagWriter.java
+++ b/src/main/java/de/pixart/messenger/xml/TagWriter.java
@@ -5,7 +5,9 @@ import android.util.Log;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
import de.pixart.messenger.Config;
import de.pixart.messenger.xmpp.stanzas.AbstractStanza;
@@ -15,13 +17,15 @@ public class TagWriter {
private OutputStreamWriter outputStream;
private boolean finished = false;
private LinkedBlockingQueue<AbstractStanza> writeQueue = new LinkedBlockingQueue<AbstractStanza>();
+ private CountDownLatch stanzaWriterCountDownLatch = null;
private Thread asyncStanzaWriter = new Thread() {
@Override
public void run() {
+ stanzaWriterCountDownLatch = new CountDownLatch(1);
while (!isInterrupted()) {
if (finished && writeQueue.size() == 0) {
- return;
+ break;
}
try {
AbstractStanza output = writeQueue.take();
@@ -30,9 +34,10 @@ public class TagWriter {
outputStream.flush();
}
} catch (Exception e) {
- return;
+ break;
}
}
+ stanzaWriterCountDownLatch.countDown();
}
};
@@ -94,8 +99,12 @@ public class TagWriter {
this.finished = true;
}
- public boolean finished() {
- return (this.writeQueue.size() == 0);
+ public boolean await(long timeout, TimeUnit timeunit) throws InterruptedException {
+ if (stanzaWriterCountDownLatch == null) {
+ return true;
+ } else {
+ return stanzaWriterCountDownLatch.await(timeout, timeunit);
+ }
}
public boolean isActive() {