1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-22 10:37:59 +01:00

Add StanzaIdFilter, deprecate PacketIDFilter

This commit is contained in:
Florian Schmaus 2015-02-19 14:59:44 +01:00
parent 2856b8ace6
commit 7ebea7ce94
10 changed files with 73 additions and 29 deletions

View file

@ -95,6 +95,7 @@ allprojects {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
}
gradle.taskGraph.whenReady { taskGraph ->

View file

@ -46,7 +46,7 @@ own filters by coding to the `PacketFilter` interface. The default set of
filters includes:
* `PacketTypeFilter` -- filters for packets that are a particular Class type.
* `PacketIDFilter` -- filters for packets with a particular packet ID.
* `StanzaIdFilter` -- filters for packets with a particular packet ID.
* `ThreadFilter` -- filters for message packets with a particular thread ID.
* `ToContainsFilter` -- filters for packets that are sent to a particular address.
* `FromContainsFilter` -- filters for packets that are sent to a particular address.

View file

@ -57,7 +57,7 @@ import org.jivesoftware.smack.compression.XMPPInputOutputStream;
import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.filter.IQReplyFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.StanzaIdFilter;
import org.jivesoftware.smack.iqrequest.IQRequestHandler;
import org.jivesoftware.smack.packet.Bind;
import org.jivesoftware.smack.packet.ErrorIQ;
@ -539,7 +539,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
// Note that we can not use IQReplyFilter here, since the users full JID is not yet
// available. It will become available right after the resource has been successfully bound.
Bind bindResource = Bind.newSet(resource);
PacketCollector packetCollector = createPacketCollectorAndSend(new PacketIDFilter(bindResource), bindResource);
PacketCollector packetCollector = createPacketCollectorAndSend(new StanzaIdFilter(bindResource), bindResource);
Bind response = packetCollector.nextResultOrThrow();
// Set the connections user to the result of resource binding. It is important that we don't infer the user
// from the login() arguments and the configurations service name, as, for example, when SASL External is used,
@ -552,7 +552,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
// For more information see http://tools.ietf.org/html/draft-cridland-xmpp-session-01
if (sessionFeature != null && !sessionFeature.isOptional() && !getConfiguration().isLegacySessionDisabled()) {
Session session = new Session();
packetCollector = createPacketCollectorAndSend(new PacketIDFilter(session), session);
packetCollector = createPacketCollectorAndSend(new StanzaIdFilter(session), session);
packetCollector.nextResultOrThrow();
}
}

View file

@ -99,7 +99,7 @@ public class IQReplyFilter implements PacketFilter {
packetId = iqPacket.getStanzaId();
PacketFilter iqFilter = new OrFilter(IQTypeFilter.ERROR, IQTypeFilter.RESULT);
PacketFilter idFilter = new PacketIDFilter(iqPacket);
PacketFilter idFilter = new StanzaIdFilter(iqPacket);
iqAndIdFilter = new AndFilter(iqFilter, idFilter);
fromFilter = new OrFilter();
fromFilter.addFilter(FromMatchesFilter.createFull(to));

View file

@ -28,7 +28,7 @@ import org.jivesoftware.smack.packet.Stanza;
* packet filtering by using the {@link org.jivesoftware.smack.filter.AndFilter AndFilter} and
* {@link org.jivesoftware.smack.filter.OrFilter OrFilter} filters. It's also possible to define
* your own filters by implementing this interface. The code example below creates a trivial filter
* for packets with a specific ID (real code should use {@link PacketIDFilter} instead).
* for packets with a specific ID (real code should use {@link StanzaIdFilter} instead).
*
* <pre>
* // Use an anonymous inner class to define a packet filter that returns

View file

@ -24,7 +24,9 @@ import org.jivesoftware.smack.util.StringUtils;
* Filters for packets with a particular packet ID.
*
* @author Matt Tucker
* @deprecated use {@link StanzaIdFilter} instead.
*/
@Deprecated
public class PacketIDFilter implements PacketFilter {
private final String packetID;
@ -33,7 +35,9 @@ public class PacketIDFilter implements PacketFilter {
* Creates a new packet ID filter using the specified packet's ID.
*
* @param packet the packet which the ID is taken from.
* @deprecated use {@link StanzaIdfilter(Stanza)} instead.
*/
@Deprecated
public PacketIDFilter(Stanza packet) {
this(packet.getStanzaId());
}
@ -42,7 +46,9 @@ public class PacketIDFilter implements PacketFilter {
* Creates a new packet ID filter using the specified packet ID.
*
* @param packetID the packet ID to filter for.
* @deprecated use {@link StanzaIdFilter(String)} instead.
*/
@Deprecated
public PacketIDFilter(String packetID) {
StringUtils.requireNotNullOrEmpty(packetID, "Packet ID must not be null or empty.");
this.packetID = packetID;

View file

@ -0,0 +1,57 @@
/**
*
* Copyright 2003-2007 Jive Software.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package org.jivesoftware.smack.filter;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.StringUtils;
/**
* Filters for Stanzas with a particular stanza ID.
*
* @author Matt Tucker
*/
public class StanzaIdFilter implements PacketFilter {
private final String stanzaId;
/**
* Creates a new stanza ID filter using the specified stanza's ID.
*
* @param stanza the stanza which the ID is taken from.
*/
public StanzaIdFilter(Stanza stanza) {
this(stanza.getStanzaId());
}
/**
* Creates a new stanza ID filter using the specified stanza ID.
*
* @param stanzaID the stanza ID to filter for.
*/
public StanzaIdFilter(String stanzaID) {
this.stanzaId = StringUtils.requireNotNullOrEmpty(stanzaID, "Stanza ID must not be null or empty.");
}
public boolean accept(Stanza stanza) {
return stanzaId.equals(stanza.getStanzaId());
}
public String toString() {
return getClass().getSimpleName() + ": id=" + stanzaId;
}
}

View file

@ -31,7 +31,7 @@ import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.StanzaIdFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.iqregister.packet.Registration;
import org.jxmpp.util.XmppStringUtils;
@ -290,7 +290,7 @@ public class AccountManager extends Manager {
}
private PacketCollector createPacketCollectorAndSend(IQ req) throws NotConnectedException {
PacketCollector collector = connection().createPacketCollectorAndSend(new PacketIDFilter(req.getStanzaId()), req);
PacketCollector collector = connection().createPacketCollectorAndSend(new StanzaIdFilter(req.getStanzaId()), req);
return collector;
}
}

View file

@ -26,26 +26,6 @@ import org.jivesoftware.smack.util.StringUtils;
* A Version IQ packet, which is used by XMPP clients to discover version information
* about the software running at another entity's JID.<p>
*
* An example to discover the version of the server:
* <pre>
* // Request the version from the server.
* Version versionRequest = new Version();
* timeRequest.setType(IQ.Type.get);
* timeRequest.setTo("example.com");
*
* // Create a packet collector to listen for a response.
* PacketCollector collector = con.createPacketCollector(
* new PacketIDFilter(versionRequest.getStanzaId()));
*
* con.sendPacket(versionRequest);
*
* // Wait up to 5 seconds for a result.
* IQ result = (IQ)collector.nextResult(5000);
* if (result != null && result.getType() == IQ.Type.result) {
* Version versionResult = (Version)result;
* // Do something with result...
* }</pre><p>
*
* @author Gaston Dombiak
*/
public class Version extends IQ {

View file

@ -51,7 +51,7 @@ import org.jivesoftware.smack.packet.Stanza;
* <code>
* public void methodToTest() {
* Packet packet = new Packet(); // create an XMPP packet
* PacketCollector collector = connection.createPacketCollector(new PacketIDFilter());
* PacketCollector collector = connection.createPacketCollector(new StanzaIdFilter());
* connection.sendPacket(packet);
* Packet reply = collector.nextResult();
* }