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 | Constructor and Description |
|---|---|
protected |
PacketCollector(XMPPConnection connection,
PacketFilter packetFilter)
Creates a new packet collector.
|
protected |
PacketCollector(XMPPConnection connection,
PacketFilter packetFilter,
int maxSize)
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.
|
PacketFilter |
getPacketFilter()
Returns the packet filter associated with this packet collector.
|
<P extends Packet> |
nextResult()
Returns the next available packet.
|
<P extends Packet> |
nextResult(long timeout)
Returns the next available packet.
|
<P extends Packet> |
nextResultBlockForever()
Returns the next available packet.
|
<P extends Packet> |
nextResultOrThrow()
Returns the next available packet.
|
<P extends Packet> |
nextResultOrThrow(long timeout)
Returns the next available packet.
|
<P extends Packet> |
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.
|
protected void |
processPacket(Packet packet)
Processes a packet to see if it meets the criteria for this packet collector.
|
protected PacketCollector(XMPPConnection connection, PacketFilter packetFilter)
connection - the connection the collector is tied to.packetFilter - determines which packets will be returned by this collector.protected PacketCollector(XMPPConnection connection, PacketFilter packetFilter, int maxSize)
connection - the connection the collector is tied to.packetFilter - determines which packets will be returned by this collector.maxSize - the maximum number of packets that will be stored in the collector.public void cancel()
public PacketFilter getPacketFilter()
public <P extends Packet> P pollResult()
public <P extends Packet> P nextResultBlockForever()
public <P extends Packet> P nextResult()
public <P extends Packet> P nextResult(long timeout)
public <P extends Packet> 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 Packet> 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.protected void processPacket(Packet packet)
packet - the packet to process.