1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-26 22:12:05 +01:00

Small tweaks.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@6183 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Alex Wenckus 2006-11-20 23:09:11 +00:00 committed by alex
parent b34d338b31
commit 1f3ab16aad
4 changed files with 35 additions and 26 deletions

View file

@ -448,13 +448,21 @@ public class MultiUserChat {
new AndFilter( new AndFilter(
new FromMatchesFilter(room + "/" + nickname), new FromMatchesFilter(room + "/" + nickname),
new PacketTypeFilter(Presence.class)); new PacketTypeFilter(Presence.class));
PacketCollector response = connection.createPacketCollector(responseFilter); PacketCollector response = null;
Presence presence;
try {
response = connection.createPacketCollector(responseFilter);
// Send join packet. // Send join packet.
connection.sendPacket(joinPresence); connection.sendPacket(joinPresence);
// Wait up to a certain number of seconds for a reply. // Wait up to a certain number of seconds for a reply.
Presence presence = (Presence) response.nextResult(timeout); presence = (Presence) response.nextResult(timeout);
}
finally {
// Stop queuing results // Stop queuing results
if (response != null) {
response.cancel(); response.cancel();
}
}
if (presence == null) { if (presence == null) {
throw new XMPPException("No response from server."); throw new XMPPException("No response from server.");
@ -795,6 +803,9 @@ public class MultiUserChat {
/** /**
* Fires invitation rejection listeners. * Fires invitation rejection listeners.
*
* @param invitee the user being invited.
* @param reason the reason for the rejection
*/ */
private void fireInvitationRejectionListeners(String invitee, String reason) { private void fireInvitationRejectionListeners(String invitee, String reason) {
InvitationRejectionListener[] listeners; InvitationRejectionListener[] listeners;

View file

@ -22,10 +22,10 @@ package org.jivesoftware.smackx.packet;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/** /**
* A DiscoverInfo IQ packet, which is used by XMPP clients to request and receive information * A DiscoverInfo IQ packet, which is used by XMPP clients to request and receive information
@ -38,8 +38,8 @@ import java.util.List;
*/ */
public class DiscoverInfo extends IQ { public class DiscoverInfo extends IQ {
private final List<Feature> features = new ArrayList<Feature>(); private final List<Feature> features = new CopyOnWriteArrayList<Feature>();
private final List<Identity> identities = new ArrayList<Identity>(); private final List<Identity> identities = new CopyOnWriteArrayList<Identity>();
private String node; private String node;
/** /**
@ -48,7 +48,7 @@ public class DiscoverInfo extends IQ {
* @param feature the discovered feature * @param feature the discovered feature
*/ */
public void addFeature(String feature) { public void addFeature(String feature) {
addFeature(new DiscoverInfo.Feature(feature)); addFeature(new Feature(feature));
} }
private void addFeature(Feature feature) { private void addFeature(Feature feature) {
@ -64,7 +64,7 @@ public class DiscoverInfo extends IQ {
*/ */
Iterator<Feature> getFeatures() { Iterator<Feature> getFeatures() {
synchronized (features) { synchronized (features) {
return Collections.unmodifiableList(new ArrayList<Feature>(features)).iterator(); return Collections.unmodifiableList(features).iterator();
} }
} }
@ -86,7 +86,7 @@ public class DiscoverInfo extends IQ {
*/ */
public Iterator<Identity> getIdentities() { public Iterator<Identity> getIdentities() {
synchronized (identities) { synchronized (identities) {
return Collections.unmodifiableList(new ArrayList<Identity>(identities)).iterator(); return Collections.unmodifiableList(identities).iterator();
} }
} }

View file

@ -22,10 +22,10 @@ package org.jivesoftware.smackx.packet;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/** /**
* A DiscoverItems IQ packet, which is used by XMPP clients to request and receive items * A DiscoverItems IQ packet, which is used by XMPP clients to request and receive items
@ -38,7 +38,7 @@ import java.util.List;
*/ */
public class DiscoverItems extends IQ { public class DiscoverItems extends IQ {
private final List<DiscoverItems.Item> items = new ArrayList<DiscoverItems.Item>(); private final List<Item> items = new CopyOnWriteArrayList<Item>();
private String node; private String node;
/** /**
@ -59,8 +59,7 @@ public class DiscoverItems extends IQ {
*/ */
public Iterator<DiscoverItems.Item> getItems() { public Iterator<DiscoverItems.Item> getItems() {
synchronized (items) { synchronized (items) {
return Collections.unmodifiableList(new ArrayList<DiscoverItems.Item>(items)) return Collections.unmodifiableList(items).iterator();
.iterator();
} }
} }
@ -100,8 +99,7 @@ public class DiscoverItems extends IQ {
} }
buf.append(">"); buf.append(">");
synchronized (items) { synchronized (items) {
for (int i = 0; i < items.size(); i++) { for (Item item : items) {
Item item = items.get(i);
buf.append(item.toXML()); buf.append(item.toXML());
} }
} }

View file

@ -35,7 +35,7 @@ public class DiscoverItemsProvider implements IQProvider {
public IQ parseIQ(XmlPullParser parser) throws Exception { public IQ parseIQ(XmlPullParser parser) throws Exception {
DiscoverItems discoverItems = new DiscoverItems(); DiscoverItems discoverItems = new DiscoverItems();
boolean done = false; boolean done = false;
DiscoverItems.Item item = null; DiscoverItems.Item item;
String jid = ""; String jid = "";
String name = ""; String name = "";
String action = ""; String action = "";
@ -44,7 +44,7 @@ public class DiscoverItemsProvider implements IQProvider {
while (!done) { while (!done) {
int eventType = parser.next(); int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) { if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("item")) { if ("item".equals(parser.getName())) {
// Initialize the variables from the parsed XML // Initialize the variables from the parsed XML
jid = parser.getAttributeValue("", "jid"); jid = parser.getAttributeValue("", "jid");
name = parser.getAttributeValue("", "name"); name = parser.getAttributeValue("", "name");
@ -52,7 +52,7 @@ public class DiscoverItemsProvider implements IQProvider {
action = parser.getAttributeValue("", "action"); action = parser.getAttributeValue("", "action");
} }
} else if (eventType == XmlPullParser.END_TAG) { } else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("item")) { if ("item".equals(parser.getName())) {
// Create a new Item and add it to DiscoverItems. // Create a new Item and add it to DiscoverItems.
item = new DiscoverItems.Item(jid); item = new DiscoverItems.Item(jid);
item.setName(name); item.setName(name);
@ -60,7 +60,7 @@ public class DiscoverItemsProvider implements IQProvider {
item.setAction(action); item.setAction(action);
discoverItems.addItem(item); discoverItems.addItem(item);
} }
if (parser.getName().equals("query")) { if ("query".equals(parser.getName())) {
done = true; done = true;
} }
} }