2003-01-13 17:58:47 +01:00
|
|
|
/**
|
|
|
|
*
|
2018-06-11 18:24:15 +02:00
|
|
|
* Copyright 2003-2007 Jive Software, 2016-2018 Florian Schmaus.
|
2003-01-13 17:58:47 +01:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2004-11-03 00:53:30 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2003-01-13 17:58:47 +01:00
|
|
|
*
|
2004-11-03 00:53:30 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2003-01-13 17:58:47 +01:00
|
|
|
*
|
2004-11-03 00:53:30 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2003-01-13 17:58:47 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.jivesoftware.smack;
|
|
|
|
|
2018-06-11 18:25:07 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2013-02-07 04:42:33 +01:00
|
|
|
import java.util.concurrent.ArrayBlockingQueue;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
2014-03-12 11:50:05 +01:00
|
|
|
import org.jivesoftware.smack.SmackException.NoResponseException;
|
2017-06-14 17:12:43 +02:00
|
|
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
2014-03-12 11:50:05 +01:00
|
|
|
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
2015-02-26 18:41:17 +01:00
|
|
|
import org.jivesoftware.smack.filter.StanzaFilter;
|
2015-02-05 11:17:27 +01:00
|
|
|
import org.jivesoftware.smack.packet.Stanza;
|
2003-01-13 17:58:47 +01:00
|
|
|
|
|
|
|
/**
|
2017-01-03 11:12:34 +01:00
|
|
|
* Provides a mechanism to collect Stanzas into a result queue that pass a
|
|
|
|
* specified filter/matcher. The collector lets you perform blocking and polling
|
|
|
|
* operations on the result queue. So, a StanzaCollector is more suitable to
|
2015-03-01 10:28:15 +01:00
|
|
|
* use than a {@link StanzaListener} when you need to wait for a specific
|
2003-04-15 15:52:38 +02:00
|
|
|
* result.<p>
|
|
|
|
*
|
2018-03-31 14:17:30 +02:00
|
|
|
* Each stanza collector will queue up a configured number of packets for processing before
|
2018-05-09 23:06:12 +02:00
|
|
|
* older packets are automatically dropped. The default number is retrieved by
|
2017-01-03 11:12:34 +01:00
|
|
|
* {@link SmackConfiguration#getStanzaCollectorSize()}.
|
2003-01-13 17:58:47 +01:00
|
|
|
*
|
2017-01-03 11:12:34 +01:00
|
|
|
* @see XMPPConnection#createStanzaCollector(StanzaFilter)
|
2003-01-13 17:58:47 +01:00
|
|
|
* @author Matt Tucker
|
|
|
|
*/
|
2017-01-03 11:12:34 +01:00
|
|
|
public class StanzaCollector {
|
2003-01-13 17:58:47 +01:00
|
|
|
|
2015-02-26 18:41:17 +01:00
|
|
|
private final StanzaFilter packetFilter;
|
2015-03-04 22:42:36 +01:00
|
|
|
|
2015-02-05 11:17:27 +01:00
|
|
|
private final ArrayBlockingQueue<Stanza> resultQueue;
|
2003-01-13 17:58:47 +01:00
|
|
|
|
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* The stanza collector which timeout for the next result will get reset once this collector collects a stanza.
|
2003-01-13 17:58:47 +01:00
|
|
|
*/
|
2017-01-03 11:12:34 +01:00
|
|
|
private final StanzaCollector collectorToReset;
|
2015-01-16 17:24:59 +01:00
|
|
|
|
|
|
|
private final XMPPConnection connection;
|
|
|
|
|
2018-04-23 20:56:54 +02:00
|
|
|
private final Stanza request;
|
|
|
|
|
2018-06-11 18:24:15 +02:00
|
|
|
private volatile boolean cancelled = false;
|
2003-01-13 17:58:47 +01:00
|
|
|
|
2011-06-18 20:18:03 +02:00
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* Creates a new stanza collector. If the stanza filter is <tt>null</tt>, then
|
2011-06-18 20:18:03 +02:00
|
|
|
* all packets will match this collector.
|
|
|
|
*
|
2014-02-23 08:49:46 +01:00
|
|
|
* @param connection the connection the collector is tied to.
|
2015-01-16 17:24:59 +01:00
|
|
|
* @param configuration the configuration used to construct this collector
|
2011-06-18 20:18:03 +02:00
|
|
|
*/
|
2017-01-03 11:12:34 +01:00
|
|
|
protected StanzaCollector(XMPPConnection connection, Configuration configuration) {
|
2014-02-23 08:49:46 +01:00
|
|
|
this.connection = connection;
|
2015-01-16 17:24:59 +01:00
|
|
|
this.packetFilter = configuration.packetFilter;
|
|
|
|
this.resultQueue = new ArrayBlockingQueue<>(configuration.size);
|
|
|
|
this.collectorToReset = configuration.collectorToReset;
|
2018-04-23 20:56:54 +02:00
|
|
|
this.request = configuration.request;
|
2011-06-18 20:18:03 +02:00
|
|
|
}
|
|
|
|
|
2003-01-13 17:58:47 +01:00
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* Explicitly cancels the stanza collector so that no more results are
|
|
|
|
* queued up. Once a stanza collector has been cancelled, it cannot be
|
|
|
|
* re-enabled. Instead, a new stanza collector must be created.
|
2003-01-13 17:58:47 +01:00
|
|
|
*/
|
|
|
|
public void cancel() {
|
|
|
|
// If the packet collector has already been cancelled, do nothing.
|
2005-09-05 22:00:45 +02:00
|
|
|
if (!cancelled) {
|
2003-01-13 17:58:47 +01:00
|
|
|
cancelled = true;
|
2017-01-03 11:12:34 +01:00
|
|
|
connection.removeStanzaCollector(this);
|
2003-01-13 17:58:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* Returns the stanza filter associated with this stanza collector. The packet
|
2003-01-13 17:58:47 +01:00
|
|
|
* filter is used to determine what packets are queued as results.
|
|
|
|
*
|
2018-03-31 14:17:30 +02:00
|
|
|
* @return the stanza filter.
|
2015-02-26 18:41:17 +01:00
|
|
|
* @deprecated use {@link #getStanzaFilter()} instead.
|
2003-01-13 17:58:47 +01:00
|
|
|
*/
|
2015-02-26 18:41:17 +01:00
|
|
|
@Deprecated
|
|
|
|
public StanzaFilter getPacketFilter() {
|
|
|
|
return getStanzaFilter();
|
2003-01-13 17:58:47 +01:00
|
|
|
}
|
|
|
|
|
2015-02-26 18:41:17 +01:00
|
|
|
/**
|
|
|
|
* Returns the stanza filter associated with this stanza collector. The stanza
|
|
|
|
* filter is used to determine what stanzas are queued as results.
|
|
|
|
*
|
|
|
|
* @return the stanza filter.
|
|
|
|
*/
|
|
|
|
public StanzaFilter getStanzaFilter() {
|
|
|
|
return packetFilter;
|
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2003-01-13 17:58:47 +01:00
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* Polls to see if a stanza is currently available and returns it, or
|
2003-01-13 17:58:47 +01:00
|
|
|
* immediately returns <tt>null</tt> if no packets are currently in the
|
|
|
|
* result queue.
|
|
|
|
*
|
2017-12-23 20:21:19 +01:00
|
|
|
* @param <P> type of the result stanza.
|
2018-03-31 14:17:30 +02:00
|
|
|
* @return the next stanza result, or <tt>null</tt> if there are no more
|
2003-01-13 17:58:47 +01:00
|
|
|
* results.
|
|
|
|
*/
|
2014-08-15 10:49:05 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2015-02-05 11:17:27 +01:00
|
|
|
public <P extends Stanza> P pollResult() {
|
2014-08-15 10:49:05 +02:00
|
|
|
return (P) resultQueue.poll();
|
2003-01-13 17:58:47 +01:00
|
|
|
}
|
|
|
|
|
2014-12-07 23:41:17 +01:00
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* Polls to see if a stanza is currently available and returns it, or
|
2014-12-07 23:41:17 +01:00
|
|
|
* immediately returns <tt>null</tt> if no packets are currently in the
|
|
|
|
* result queue.
|
|
|
|
* <p>
|
|
|
|
* Throws an XMPPErrorException in case the polled stanzas did contain an XMPPError.
|
|
|
|
* </p>
|
2017-12-23 20:21:19 +01:00
|
|
|
*
|
|
|
|
* @param <P> type of the result stanza.
|
2014-12-07 23:41:17 +01:00
|
|
|
* @return the next available packet.
|
|
|
|
* @throws XMPPErrorException in case an error response.
|
|
|
|
*/
|
2015-02-05 11:17:27 +01:00
|
|
|
public <P extends Stanza> P pollResultOrThrow() throws XMPPErrorException {
|
2014-12-07 23:41:17 +01:00
|
|
|
P result = pollResult();
|
|
|
|
if (result != null) {
|
|
|
|
XMPPErrorException.ifHasErrorThenThrow(result);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-01-17 08:12:57 +01:00
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* Returns the next available packet. The method call will block (not return) until a stanza is
|
2014-02-18 15:05:19 +01:00
|
|
|
* available.
|
2017-12-23 20:21:19 +01:00
|
|
|
*
|
|
|
|
* @param <P> type of the result stanza.
|
2003-01-17 08:12:57 +01:00
|
|
|
* @return the next available packet.
|
2018-05-09 23:06:12 +02:00
|
|
|
* @throws InterruptedException
|
2003-01-17 08:12:57 +01:00
|
|
|
*/
|
2014-08-15 10:49:05 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2015-02-14 09:43:44 +01:00
|
|
|
public <P extends Stanza> P nextResultBlockForever() throws InterruptedException {
|
2015-01-14 20:14:48 +01:00
|
|
|
throwIfCancelled();
|
2014-09-05 22:06:58 +02:00
|
|
|
P res = null;
|
2014-08-29 18:06:22 +02:00
|
|
|
while (res == null) {
|
2015-02-14 09:43:44 +01:00
|
|
|
res = (P) resultQueue.take();
|
2014-02-18 15:05:19 +01:00
|
|
|
}
|
2014-08-29 18:06:22 +02:00
|
|
|
return res;
|
2014-02-18 15:05:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the next available packet. The method call will block until the connection's default
|
|
|
|
* timeout has elapsed.
|
2017-12-23 20:21:19 +01:00
|
|
|
*
|
|
|
|
* @param <P> type of the result stanza.
|
2015-01-16 17:24:59 +01:00
|
|
|
* @return the next available packet.
|
2018-05-09 23:06:12 +02:00
|
|
|
* @throws InterruptedException
|
2014-02-18 15:05:19 +01:00
|
|
|
*/
|
2015-02-14 09:43:44 +01:00
|
|
|
public <P extends Stanza> P nextResult() throws InterruptedException {
|
2017-01-12 20:57:19 +01:00
|
|
|
return nextResult(connection.getReplyTimeout());
|
2003-01-13 17:58:47 +01:00
|
|
|
}
|
|
|
|
|
2015-01-16 17:24:59 +01:00
|
|
|
private volatile long waitStart;
|
|
|
|
|
2003-01-17 08:12:57 +01:00
|
|
|
/**
|
|
|
|
* Returns the next available packet. The method call will block (not return)
|
2018-03-31 14:17:30 +02:00
|
|
|
* until a stanza is available or the <tt>timeout</tt> has elapsed. If the
|
2003-01-17 08:12:57 +01:00
|
|
|
* timeout elapses without a result, <tt>null</tt> will be returned.
|
|
|
|
*
|
2017-12-23 20:21:19 +01:00
|
|
|
* @param <P> type of the result stanza.
|
2015-01-10 18:00:18 +01:00
|
|
|
* @param timeout the timeout in milliseconds.
|
2003-01-17 08:12:57 +01:00
|
|
|
* @return the next available packet.
|
2018-05-09 23:06:12 +02:00
|
|
|
* @throws InterruptedException
|
2003-01-17 08:12:57 +01:00
|
|
|
*/
|
2014-08-04 18:01:05 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2015-02-14 09:43:44 +01:00
|
|
|
public <P extends Stanza> P nextResult(long timeout) throws InterruptedException {
|
2015-01-14 20:14:48 +01:00
|
|
|
throwIfCancelled();
|
2014-09-05 22:06:58 +02:00
|
|
|
P res = null;
|
2014-08-29 18:06:22 +02:00
|
|
|
long remainingWait = timeout;
|
2015-01-16 17:24:59 +01:00
|
|
|
waitStart = System.currentTimeMillis();
|
|
|
|
do {
|
2015-02-14 09:43:44 +01:00
|
|
|
res = (P) resultQueue.poll(remainingWait, TimeUnit.MILLISECONDS);
|
2015-01-16 17:24:59 +01:00
|
|
|
if (res != null) {
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
remainingWait = timeout - (System.currentTimeMillis() - waitStart);
|
|
|
|
} while (remainingWait > 0);
|
|
|
|
return null;
|
2003-01-13 17:58:47 +01:00
|
|
|
}
|
|
|
|
|
2014-02-18 15:05:19 +01:00
|
|
|
/**
|
2016-08-01 16:18:01 +02:00
|
|
|
* Returns the next available stanza. The method in equivalent to
|
|
|
|
* {@link #nextResultOrThrow(long)} where the timeout argument is the default reply timeout of
|
|
|
|
* the connection associated with this collector.
|
2017-12-23 20:21:19 +01:00
|
|
|
*
|
|
|
|
* @param <P> type of the result stanza.
|
2016-08-01 16:18:01 +02:00
|
|
|
* @return the next available stanza.
|
|
|
|
* @throws XMPPErrorException in case an error response was received.
|
2014-03-12 11:50:05 +01:00
|
|
|
* @throws NoResponseException if there was no response from the server.
|
2016-08-01 16:18:01 +02:00
|
|
|
* @throws InterruptedException
|
|
|
|
* @throws NotConnectedException
|
|
|
|
* @see #nextResultOrThrow(long)
|
2014-02-18 15:05:19 +01:00
|
|
|
*/
|
2015-07-03 12:57:30 +02:00
|
|
|
public <P extends Stanza> P nextResultOrThrow() throws NoResponseException, XMPPErrorException,
|
|
|
|
InterruptedException, NotConnectedException {
|
2017-01-12 20:57:19 +01:00
|
|
|
return nextResultOrThrow(connection.getReplyTimeout());
|
2014-02-18 15:05:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-01 16:18:01 +02:00
|
|
|
* Returns the next available stanza. The method call will block until a stanza is
|
|
|
|
* available or the <tt>timeout</tt> has elapsed. This method does also cancel the
|
|
|
|
* collector in every case.
|
|
|
|
* <p>
|
|
|
|
* Three things can happen when waiting for an response:
|
|
|
|
* </p>
|
|
|
|
* <ol>
|
|
|
|
* <li>A result response arrives.</li>
|
|
|
|
* <li>An error response arrives.</li>
|
|
|
|
* <li>An timeout occurs.</li>
|
|
|
|
* <li>The thread is interrupted</li>
|
|
|
|
* </ol>
|
|
|
|
* <p>
|
|
|
|
* in which this method will
|
|
|
|
* </p>
|
|
|
|
* <ol>
|
|
|
|
* <li>return with the result.</li>
|
|
|
|
* <li>throw an {@link XMPPErrorException}.</li>
|
|
|
|
* <li>throw an {@link NoResponseException}.</li>
|
|
|
|
* <li>throw an {@link InterruptedException}.</li>
|
|
|
|
* </ol>
|
|
|
|
* <p>
|
|
|
|
* Additionally the method will throw a {@link NotConnectedException} if no response was
|
|
|
|
* received and the connection got disconnected.
|
|
|
|
* </p>
|
|
|
|
*
|
|
|
|
* @param timeout the amount of time to wait for the next stanza in milliseconds.
|
2017-12-23 20:21:19 +01:00
|
|
|
* @param <P> type of the result stanza.
|
2016-08-01 16:18:01 +02:00
|
|
|
* @return the next available stanza.
|
2014-03-12 11:50:05 +01:00
|
|
|
* @throws NoResponseException if there was no response from the server.
|
2016-08-01 16:18:01 +02:00
|
|
|
* @throws XMPPErrorException in case an error response was received.
|
|
|
|
* @throws InterruptedException if the calling thread was interrupted.
|
|
|
|
* @throws NotConnectedException if there was no response and the connection got disconnected.
|
2014-02-18 15:05:19 +01:00
|
|
|
*/
|
2015-07-03 12:57:30 +02:00
|
|
|
public <P extends Stanza> P nextResultOrThrow(long timeout) throws NoResponseException,
|
|
|
|
XMPPErrorException, InterruptedException, NotConnectedException {
|
2014-08-04 18:01:05 +02:00
|
|
|
P result = nextResult(timeout);
|
2014-02-18 15:05:19 +01:00
|
|
|
cancel();
|
|
|
|
if (result == null) {
|
2015-07-03 12:57:30 +02:00
|
|
|
if (!connection.isConnected()) {
|
|
|
|
throw new NotConnectedException(connection, packetFilter);
|
|
|
|
}
|
2019-03-05 08:21:59 +01:00
|
|
|
throw NoResponseException.newWith(timeout, this);
|
2014-02-18 15:05:19 +01:00
|
|
|
}
|
|
|
|
|
2014-08-16 00:04:24 +02:00
|
|
|
XMPPErrorException.ifHasErrorThenThrow(result);
|
2014-02-18 15:05:19 +01:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-06-11 18:25:07 +02:00
|
|
|
private List<Stanza> collectedCache;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a list of all collected stanzas. This method must be invoked after the collector has been cancelled.
|
|
|
|
*
|
|
|
|
* @return a list of collected stanzas.
|
|
|
|
* @since 4.3.0
|
|
|
|
*/
|
|
|
|
public List<Stanza> getCollectedStanzasAfterCancelled() {
|
|
|
|
if (!cancelled) {
|
|
|
|
throw new IllegalStateException("Stanza collector was not yet cancelled");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (collectedCache == null) {
|
|
|
|
collectedCache = new ArrayList<>(getCollectedCount());
|
|
|
|
resultQueue.drainTo(collectedCache);
|
|
|
|
}
|
|
|
|
|
|
|
|
return collectedCache;
|
|
|
|
}
|
|
|
|
|
2015-01-10 18:00:18 +01:00
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* Get the number of collected stanzas this stanza collector has collected so far.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2015-01-10 18:00:18 +01:00
|
|
|
* @return the count of collected stanzas.
|
|
|
|
* @since 4.1
|
|
|
|
*/
|
|
|
|
public int getCollectedCount() {
|
|
|
|
return resultQueue.size();
|
|
|
|
}
|
|
|
|
|
2003-01-13 17:58:47 +01:00
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* Processes a stanza to see if it meets the criteria for this stanza collector.
|
|
|
|
* If so, the stanza is added to the result queue.
|
2003-01-13 17:58:47 +01:00
|
|
|
*
|
2018-03-31 14:17:30 +02:00
|
|
|
* @param packet the stanza to process.
|
2003-01-13 17:58:47 +01:00
|
|
|
*/
|
2017-01-03 11:12:34 +01:00
|
|
|
protected void processStanza(Stanza packet) {
|
2003-01-13 17:58:47 +01:00
|
|
|
if (packetFilter == null || packetFilter.accept(packet)) {
|
2015-03-17 21:19:06 +01:00
|
|
|
// CHECKSTYLE:OFF
|
2013-02-07 04:42:33 +01:00
|
|
|
while (!resultQueue.offer(packet)) {
|
|
|
|
// Since we know the queue is full, this poll should never actually block.
|
|
|
|
resultQueue.poll();
|
|
|
|
}
|
2015-03-17 21:19:06 +01:00
|
|
|
// CHECKSTYLE:ON
|
2015-01-16 17:24:59 +01:00
|
|
|
if (collectorToReset != null) {
|
|
|
|
collectorToReset.waitStart = System.currentTimeMillis();
|
|
|
|
}
|
2003-01-13 17:58:47 +01:00
|
|
|
}
|
|
|
|
}
|
2015-01-14 20:14:48 +01:00
|
|
|
|
2017-12-13 23:10:11 +01:00
|
|
|
private void throwIfCancelled() {
|
2015-01-14 20:14:48 +01:00
|
|
|
if (cancelled) {
|
2018-06-11 18:24:37 +02:00
|
|
|
throw new IllegalStateException("Stanza collector already cancelled");
|
2015-01-14 20:14:48 +01:00
|
|
|
}
|
|
|
|
}
|
2015-01-16 17:24:59 +01:00
|
|
|
|
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* Get a new stanza collector configuration instance.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2018-03-31 14:17:30 +02:00
|
|
|
* @return a new stanza collector configuration.
|
2015-01-16 17:24:59 +01:00
|
|
|
*/
|
|
|
|
public static Configuration newConfiguration() {
|
|
|
|
return new Configuration();
|
|
|
|
}
|
|
|
|
|
2015-04-06 10:45:12 +02:00
|
|
|
public static final class Configuration {
|
2015-02-26 18:41:17 +01:00
|
|
|
private StanzaFilter packetFilter;
|
2017-01-03 11:12:34 +01:00
|
|
|
private int size = SmackConfiguration.getStanzaCollectorSize();
|
|
|
|
private StanzaCollector collectorToReset;
|
2018-04-23 20:56:54 +02:00
|
|
|
private Stanza request;
|
2015-01-16 17:24:59 +01:00
|
|
|
|
|
|
|
private Configuration() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* Set the stanza filter used by this collector. If <code>null</code>, then all packets will
|
2015-01-16 17:24:59 +01:00
|
|
|
* get collected by this collector.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2015-01-16 17:24:59 +01:00
|
|
|
* @param packetFilter
|
|
|
|
* @return a reference to this configuration.
|
2015-02-26 18:41:17 +01:00
|
|
|
* @deprecated use {@link #setStanzaFilter(StanzaFilter)} instead.
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public Configuration setPacketFilter(StanzaFilter packetFilter) {
|
|
|
|
return setStanzaFilter(packetFilter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the stanza filter used by this collector. If <code>null</code>, then all stanzas will
|
|
|
|
* get collected by this collector.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2015-02-26 18:41:17 +01:00
|
|
|
* @param stanzaFilter
|
|
|
|
* @return a reference to this configuration.
|
2015-01-16 17:24:59 +01:00
|
|
|
*/
|
2015-02-26 18:41:17 +01:00
|
|
|
public Configuration setStanzaFilter(StanzaFilter stanzaFilter) {
|
|
|
|
this.packetFilter = stanzaFilter;
|
2015-01-16 17:24:59 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the maximum size of this collector, i.e. how many stanzas this collector will collect
|
|
|
|
* before dropping old ones.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2015-01-16 17:24:59 +01:00
|
|
|
* @param size
|
|
|
|
* @return a reference to this configuration.
|
|
|
|
*/
|
|
|
|
public Configuration setSize(int size) {
|
|
|
|
this.size = size;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the collector which timeout for the next result is reset once this collector collects
|
|
|
|
* a packet.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2015-01-16 17:24:59 +01:00
|
|
|
* @param collector
|
|
|
|
* @return a reference to this configuration.
|
|
|
|
*/
|
2017-01-03 11:12:34 +01:00
|
|
|
public Configuration setCollectorToReset(StanzaCollector collector) {
|
2015-01-16 17:24:59 +01:00
|
|
|
this.collectorToReset = collector;
|
|
|
|
return this;
|
|
|
|
}
|
2018-04-23 20:56:54 +02:00
|
|
|
|
|
|
|
public Configuration setRequest(Stanza request) {
|
|
|
|
this.request = request;
|
|
|
|
return this;
|
|
|
|
}
|
2015-01-16 17:24:59 +01:00
|
|
|
}
|
2003-01-13 17:58:47 +01:00
|
|
|
}
|