public class StanzaCollector extends Object
StanzaListener
when you need to wait for a specific
result.
Each stanza collector will queue up a configured number of packets for processing before
older packets are automatically dropped. The default number is retrieved by
SmackConfiguration.getStanzaCollectorSize()
.
Modifier and Type | Class and Description |
---|---|
static class |
StanzaCollector.Configuration |
Modifier | Constructor and Description |
---|---|
protected |
StanzaCollector(XMPPConnection connection,
StanzaCollector.Configuration configuration)
Creates a new stanza collector.
|
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Explicitly cancels the stanza collector so that no more results are
queued up.
|
int |
getCollectedCount()
Get the number of collected stanzas this stanza collector has collected so far.
|
List<Stanza> |
getCollectedStanzasAfterCancelled()
Return a list of all collected stanzas.
|
StanzaFilter |
getPacketFilter()
Deprecated.
use
getStanzaFilter() instead. |
StanzaFilter |
getStanzaFilter()
Returns the stanza filter associated with this stanza collector.
|
static StanzaCollector.Configuration |
newConfiguration()
Get a new stanza collector configuration instance.
|
<P extends Stanza> |
nextResult()
Returns the next available packet.
|
<P extends Stanza> |
nextResult(long timeout)
Returns the next available packet.
|
<P extends Stanza> |
nextResultBlockForever()
Returns the next available packet.
|
<P extends Stanza> |
nextResultOrThrow()
Returns the next available stanza.
|
<P extends Stanza> |
nextResultOrThrow(long timeout)
Returns the next available stanza.
|
<P extends Stanza> |
pollResult()
Polls to see if a stanza is currently available and returns it, or
immediately returns null if no packets are currently in the
result queue.
|
<P extends Stanza> |
pollResultOrThrow()
Polls to see if a stanza is currently available and returns it, or
immediately returns null if no packets are currently in the
result queue.
|
protected void |
processStanza(Stanza packet)
Processes a stanza to see if it meets the criteria for this stanza collector.
|
protected StanzaCollector(XMPPConnection connection, StanzaCollector.Configuration configuration)
connection
- the connection the collector is tied to.configuration
- the configuration used to construct this collectorpublic void cancel()
@Deprecated public StanzaFilter getPacketFilter()
getStanzaFilter()
instead.public StanzaFilter getStanzaFilter()
public <P extends Stanza> P pollResult()
P
- type of the result stanza.public <P extends Stanza> P pollResultOrThrow() throws XMPPException.XMPPErrorException
Throws an XMPPErrorException in case the polled stanzas did contain an XMPPError.
P
- type of the result stanza.XMPPException.XMPPErrorException
- in case an error response.public <P extends Stanza> P nextResultBlockForever() throws InterruptedException
P
- type of the result stanza.InterruptedException
public <P extends Stanza> P nextResult() throws InterruptedException
P
- type of the result stanza.InterruptedException
public <P extends Stanza> P nextResult(long timeout) throws InterruptedException
P
- type of the result stanza.timeout
- the timeout in milliseconds.InterruptedException
public <P extends Stanza> P nextResultOrThrow() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, InterruptedException, SmackException.NotConnectedException
nextResultOrThrow(long)
where the timeout argument is the default reply timeout of
the connection associated with this collector.P
- type of the result stanza.XMPPException.XMPPErrorException
- in case an error response was received.SmackException.NoResponseException
- if there was no response from the server.InterruptedException
SmackException.NotConnectedException
nextResultOrThrow(long)
public <P extends Stanza> P nextResultOrThrow(long timeout) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, InterruptedException, SmackException.NotConnectedException
Three things can happen when waiting for an response:
in which this method will
XMPPException.XMPPErrorException
.SmackException.NoResponseException
.InterruptedException
.
Additionally the method will throw a SmackException.NotConnectedException
if no response was
received and the connection got disconnected.
P
- type of the result stanza.timeout
- the amount of time to wait for the next stanza in milliseconds.SmackException.NoResponseException
- if there was no response from the server.XMPPException.XMPPErrorException
- in case an error response was received.InterruptedException
- if the calling thread was interrupted.SmackException.NotConnectedException
- if there was no response and the connection got disconnected.public List<Stanza> getCollectedStanzasAfterCancelled()
public int getCollectedCount()
protected void processStanza(Stanza packet)
packet
- the stanza to process.public static StanzaCollector.Configuration newConfiguration()