public class StanzaCollector
extends java.lang.Object
StanzaListener
when you need to wait for a specific
result.
Each stanza(/packet) 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(/packet) collector.
|
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Explicitly cancels the stanza(/packet) collector so that no more results are
queued up.
|
int |
getCollectedCount()
Get the number of collected stanzas this stanza(/packet) collector has collected so far.
|
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(/packet) 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(/packet) 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(/packet) 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(/packet) to see if it meets the criteria for this stanza(/packet) 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 java.lang.InterruptedException
P
- type of the result stanza.java.lang.InterruptedException
public <P extends Stanza> P nextResult() throws java.lang.InterruptedException
P
- type of the result stanza.java.lang.InterruptedException
public <P extends Stanza> P nextResult(long timeout) throws java.lang.InterruptedException
P
- type of the result stanza.timeout
- the timeout in milliseconds.java.lang.InterruptedException
public <P extends Stanza> P nextResultOrThrow() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, java.lang.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.java.lang.InterruptedException
SmackException.NotConnectedException
nextResultOrThrow(long)
public <P extends Stanza> P nextResultOrThrow(long timeout) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, java.lang.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.java.lang.InterruptedException
- if the calling thread was interrupted.SmackException.NotConnectedException
- if there was no response and the connection got disconnected.public int getCollectedCount()
protected void processStanza(Stanza packet)
packet
- the stanza(/packet) to process.public static StanzaCollector.Configuration newConfiguration()