mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-12-22 20:47:57 +01:00
Add StanzaCollector.getCollectedStanzasAfterCancelled()
This commit is contained in:
parent
1dec29617e
commit
d958b42eff
1 changed files with 23 additions and 0 deletions
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue