public final class StanzaCollector
extends java.lang.Object
implements java.lang.AutoCloseable
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 and Type | Method and Description |
|---|---|
void |
cancel()
Explicitly cancels the stanza collector so that no more results are
queued up.
|
void |
close() |
int |
getCollectedCount()
Get the number of collected stanzas this stanza collector has collected so far.
|
java.util.List<Stanza> |
getCollectedStanzasAfterCancelled()
Return a list of all collected stanzas.
|
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 stanza.
|
<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.
|
java.lang.String |
toString() |
public void cancel()
public StanzaFilter getStanzaFilter()
public <P extends Stanza> P pollResult()
null if no packets are currently in the
result queue.P - type of the result stanza.null if there are no more
results.public <P extends Stanza> P pollResultOrThrow() throws XMPPException.XMPPErrorException
null if no packets are currently in the
result queue.
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.InterruptedExceptionpublic <P extends Stanza> P nextResult() throws java.lang.InterruptedException
P - type of the result stanza.java.lang.InterruptedExceptionpublic <P extends Stanza> P nextResult(long timeout) throws java.lang.InterruptedException
timeout has elapsed or if the connection was terminated because of an error. If the timeout elapses without a
result or if there was an connection error, null will be returned.P - type of the result stanza.timeout - the timeout in milliseconds.null on timeout or connection error.java.lang.InterruptedExceptionpublic <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.InterruptedExceptionSmackException.NotConnectedExceptionnextResultOrThrow(long)public <P extends Stanza> P nextResultOrThrow(long timeout) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, java.lang.InterruptedException, SmackException.NotConnectedException
timeout has elapsed. This method does also cancel the
collector in every case.
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 java.util.List<Stanza> getCollectedStanzasAfterCancelled()
public int getCollectedCount()
public java.lang.String toString()
toString in class java.lang.Objectprotected void processStanza(Stanza packet)
packet - the stanza to process.public static StanzaCollector.Configuration newConfiguration()
public void close()
close in interface java.lang.AutoCloseable