public class PacketCollector extends 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.getPacketCollectorSize()
.
Modifier and Type | Class and Description |
---|---|
static class |
PacketCollector.Configuration |
Modifier | Constructor and Description |
---|---|
protected |
PacketCollector(XMPPConnection connection,
PacketCollector.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 PacketCollector.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 packet.
|
<P extends Stanza> |
nextResultOrThrow(long timeout)
Returns the next available packet.
|
<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 |
processPacket(Stanza packet)
Processes a stanza(/packet) to see if it meets the criteria for this stanza(/packet) collector.
|
protected PacketCollector(XMPPConnection connection, PacketCollector.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()
public <P extends Stanza> P pollResultOrThrow() throws XMPPException.XMPPErrorException
Throws an XMPPErrorException in case the polled stanzas did contain an XMPPError.
XMPPException.XMPPErrorException
- in case an error response.public <P extends Stanza> P nextResultBlockForever()
public <P extends Stanza> P nextResult()
public <P extends Stanza> P nextResult(long timeout)
timeout
- the timeout in milliseconds.public <P extends Stanza> P nextResultOrThrow() throws SmackException.NoResponseException, XMPPException.XMPPErrorException
XMPPException.XMPPErrorException
- in case an error response.SmackException.NoResponseException
- if there was no response from the server.public <P extends Stanza> P nextResultOrThrow(long timeout) throws SmackException.NoResponseException, XMPPException.XMPPErrorException
timeout
- the amount of time to wait for the next stanza(/packet) (in milleseconds).SmackException.NoResponseException
- if there was no response from the server.XMPPException.XMPPErrorException
- in case an error response.public int getCollectedCount()
protected void processPacket(Stanza packet)
packet
- the stanza(/packet) to process.public static PacketCollector.Configuration newConfiguration()