Add StanzaCollector.getCollectedStanzasAfterCancelled()

This commit is contained in:
Florian Schmaus 2018-06-11 18:25:07 +02:00
parent 1dec29617e
commit d958b42eff
1 changed files with 23 additions and 0 deletions

View File

@ -17,6 +17,8 @@
package org.jivesoftware.smack;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;
@ -268,6 +270,27 @@ public class StanzaCollector {
return result;
}
private List<Stanza> collectedCache;
/**
* Return a list of all collected stanzas. This method must be invoked after the collector has been cancelled.
*
* @return a list of collected stanzas.
* @since 4.3.0
*/
public List<Stanza> getCollectedStanzasAfterCancelled() {
if (!cancelled) {
throw new IllegalStateException("Stanza collector was not yet cancelled");
}
if (collectedCache == null) {
collectedCache = new ArrayList<>(getCollectedCount());
resultQueue.drainTo(collectedCache);
}
return collectedCache;
}
/**
* Get the number of collected stanzas this stanza collector has collected so far.
*