public class PacketCollector
extends java.lang.Object
PacketListener when you need to wait for a specific
result.
Each 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 packet collector.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Explicitly cancels the packet collector so that no more results are
queued up.
|
int |
getCollectedCount()
Get the number of collected stanzas this packet collector has collected so far.
|
PacketFilter |
getPacketFilter()
Returns the packet filter associated with this packet collector.
|
static PacketCollector.Configuration |
newConfiguration()
Get a new 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 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 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 packet to see if it meets the criteria for this 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()
public PacketFilter getPacketFilter()
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 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 packet to process.public static PacketCollector.Configuration newConfiguration()