1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-27 00:32:07 +01:00

Allows reply timeout to be set

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2189 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2003-12-20 12:20:30 +00:00 committed by gdombiak
parent 129f0a0bd2
commit 41dad8658a
6 changed files with 139 additions and 32 deletions

View file

@ -2,13 +2,37 @@
<!-- Configuration file to load at system start up --> <!-- Configuration file to load at system start up -->
<smackSystem> <smackSystem>
<!-- Smack Release -->
<versionNumber>1.3.0</versionNumber>
<!-- Classes to load at start up --> <!-- Classes to load at start up -->
<classesToLoad> <classesToLoad>
<className>org.jivesoftware.smackx.ServiceDiscoveryManager</className> <className>org.jivesoftware.smackx.ServiceDiscoveryManager</className>
<className>org.jivesoftware.smackx.XHTMLManager</className> <className>org.jivesoftware.smackx.XHTMLManager</className>
</classesToLoad> </classesToLoad>
<!-- Smack Release --> <!-- Default reply timeout milliseconds -->
<versionNumber>1.3.0</versionNumber> <replyTimeout>
<value>5000</value>
<className>org.jivesoftware.smack.AccountManager</className>
</replyTimeout>
<!-- Default reply timeout milliseconds -->
<replyTimeout>
<value>5000</value>
<className>org.jivesoftware.smack.GroupChat</className>
</replyTimeout>
<!-- Default reply timeout milliseconds -->
<replyTimeout>
<value>5000</value>
<className>org.jivesoftware.smack.Roster</className>
</replyTimeout>
<!-- Default reply timeout milliseconds -->
<replyTimeout>
<value>5000</value>
<className>org.jivesoftware.smack.XMPPConnection</className>
</replyTimeout>
</smackSystem> </smackSystem>

View file

@ -67,6 +67,16 @@ import java.util.*;
*/ */
public class AccountManager { public class AccountManager {
/**
* Value that indicates the number of milliseconds to wait for a response from
* the server.
*
* The reply timeout value can be assigned by setting this field to the required
* timeout, or by modifying the smack.configuration file that holds the default value
* to use.
*/
public static int REPLY_TIMEOUT = 5000;
private XMPPConnection connection; private XMPPConnection connection;
private Registration info = null; private Registration info = null;
@ -207,7 +217,7 @@ public class AccountManager {
new PacketTypeFilter(IQ.class)); new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter); PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg); connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(5000); IQ result = (IQ)collector.nextResult(REPLY_TIMEOUT);
if (result == null) { if (result == null) {
throw new XMPPException("No response from server."); throw new XMPPException("No response from server.");
} }
@ -234,7 +244,7 @@ public class AccountManager {
new PacketTypeFilter(IQ.class)); new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter); PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg); connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(5000); IQ result = (IQ)collector.nextResult(REPLY_TIMEOUT);
if (result == null) { if (result == null) {
throw new XMPPException("No response from server."); throw new XMPPException("No response from server.");
} }
@ -266,7 +276,7 @@ public class AccountManager {
new PacketTypeFilter(IQ.class)); new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter); PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg); connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(5000); IQ result = (IQ)collector.nextResult(REPLY_TIMEOUT);
if (result == null) { if (result == null) {
throw new XMPPException("No response from server."); throw new XMPPException("No response from server.");
} }
@ -287,7 +297,7 @@ public class AccountManager {
new PacketTypeFilter(IQ.class)); new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter); PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg); connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(5000); IQ result = (IQ)collector.nextResult(REPLY_TIMEOUT);
if (result == null) { if (result == null) {
throw new XMPPException("No response from server."); throw new XMPPException("No response from server.");
} }

View file

@ -69,6 +69,16 @@ import java.util.*;
*/ */
public class GroupChat { public class GroupChat {
/**
* Value that indicates the number of milliseconds to wait for a response from
* the server.
*
* The reply timeout value can be assigned by setting this field to the required
* timeout, or by modifying the smack.configuration file that holds the default value
* to use.
*/
public static int REPLY_TIMEOUT = 5000;
private XMPPConnection connection; private XMPPConnection connection;
private String room; private String room;
private String nickname = null; private String nickname = null;
@ -151,7 +161,7 @@ public class GroupChat {
* nickname. * nickname.
*/ */
public synchronized void join(String nickname) throws XMPPException { public synchronized void join(String nickname) throws XMPPException {
join(nickname, 5000); join(nickname, REPLY_TIMEOUT);
} }
/** /**
@ -186,8 +196,8 @@ public class GroupChat {
PacketCollector response = connection.createPacketCollector(responseFilter); PacketCollector response = connection.createPacketCollector(responseFilter);
// Send join packet. // Send join packet.
connection.sendPacket(joinPresence); connection.sendPacket(joinPresence);
// Wait up to five seconds for a reply. // Wait up to a certain number of seconds for a reply.
Presence presence = (Presence)response.nextResult(5000); Presence presence = (Presence)response.nextResult(timeout);
if (presence == null) { if (presence == null) {
throw new XMPPException("No response from server."); throw new XMPPException("No response from server.");
} }

View file

@ -96,6 +96,16 @@ public class Roster {
*/ */
public static final int SUBSCRIPTION_MANUAL = 2; public static final int SUBSCRIPTION_MANUAL = 2;
/**
* Value that indicates the number of milliseconds to wait for a response from
* the server.
*
* The reply timeout value can be assigned by setting this field to the required
* timeout, or by modifying the smack.configuration file that holds the default value
* to use.
*/
public static int REPLY_TIMEOUT = 5000;
private XMPPConnection connection; private XMPPConnection connection;
private Map groups; private Map groups;
private List entries; private List entries;
@ -237,11 +247,11 @@ public class Roster {
} }
} }
rosterPacket.addRosterItem(item); rosterPacket.addRosterItem(item);
// Wait up to 5 seconds for a reply from the server. // Wait up to a certain number of seconds for a reply from the server.
PacketCollector collector = connection.createPacketCollector( PacketCollector collector = connection.createPacketCollector(
new PacketIDFilter(rosterPacket.getPacketID())); new PacketIDFilter(rosterPacket.getPacketID()));
connection.sendPacket(rosterPacket); connection.sendPacket(rosterPacket);
IQ response = (IQ)collector.nextResult(5000); IQ response = (IQ)collector.nextResult(REPLY_TIMEOUT);
if (response == null) { if (response == null) {
throw new XMPPException("No response from the server."); throw new XMPPException("No response from the server.");
} }

View file

@ -53,6 +53,7 @@
package org.jivesoftware.smack; package org.jivesoftware.smack;
import java.io.*; import java.io.*;
import java.lang.reflect.*;
import java.net.*; import java.net.*;
import java.util.*; import java.util.*;
@ -104,18 +105,15 @@ public final class SmackConfiguration {
do { do {
if (eventType == XmlPullParser.START_TAG) { if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("className")) { if (parser.getName().equals("className")) {
String className = parser.nextText();
// Attempt to load the class so that the class can get initialized // Attempt to load the class so that the class can get initialized
try { parseClassToLoad(parser);
Class provider = Class.forName(className);
}
catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
} }
else if (parser.getName().equals("versionNumber")) { else if (parser.getName().equals("versionNumber")) {
versionNumber = parser.nextText(); versionNumber = parser.nextText();
} }
else if (parser.getName().equals("replyTimeout")) {
parseReplyTimeout(parser);
}
} }
eventType = parser.next(); eventType = parser.next();
} }
@ -135,6 +133,51 @@ public final class SmackConfiguration {
} }
} }
private static void parseClassToLoad(XmlPullParser parser) throws Exception {
String className = parser.nextText();
// Attempt to load the class so that the class can get initialized
try {
Class.forName(className);
}
catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
}
private static void parseReplyTimeout(XmlPullParser parser) throws Exception {
boolean done = false;
String timeout = null;
String className = null;
// Parse the timeout value to set
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
String elementName = parser.getName();
if (elementName.equals("value")) {
timeout = parser.nextText();
}
else if (elementName.equals("className")) {
className = parser.nextText();
}
}
else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("replyTimeout")) {
done = true;
}
}
}
// Set the reply timeout value
try {
Class classToConfigure = Class.forName(className);
Field field = classToConfigure.getDeclaredField("REPLY_TIMEOUT");
field.set(null, new Integer(timeout));
}
catch (Exception e) {
e.printStackTrace();
}
}
/** /**
* Returns the current Smack release version. The version number value * Returns the current Smack release version. The version number value
* gets loaded from the smack.configuration file at system startup. * gets loaded from the smack.configuration file at system startup.

View file

@ -93,6 +93,16 @@ public class XMPPConnection {
*/ */
public static boolean DEBUG_ENABLED = false; public static boolean DEBUG_ENABLED = false;
/**
* Value that indicates the number of milliseconds to wait for a response from
* the server.
*
* The reply timeout value can be assigned by setting this field to the required
* timeout, or by modifying the smack.configuration file that holds the default value
* to use.
*/
public static int REPLY_TIMEOUT = 5000;
private static List connectionEstablishedListeners = new ArrayList(); private static List connectionEstablishedListeners = new ArrayList();
static { static {
// Use try block since we may not have permission to get a system // Use try block since we may not have permission to get a system
@ -269,8 +279,8 @@ public class XMPPConnection {
packetReader.createPacketCollector(new PacketIDFilter(discoveryAuth.getPacketID())); packetReader.createPacketCollector(new PacketIDFilter(discoveryAuth.getPacketID()));
// Send the packet // Send the packet
packetWriter.sendPacket(discoveryAuth); packetWriter.sendPacket(discoveryAuth);
// Wait up to five seconds for a response from the server. // Wait up to a certain number of seconds for a response from the server.
IQ response = (IQ) collector.nextResult(5000); IQ response = (IQ) collector.nextResult(REPLY_TIMEOUT);
if (response == null) { if (response == null) {
throw new XMPPException("No response from the server."); throw new XMPPException("No response from the server.");
} }
@ -302,8 +312,8 @@ public class XMPPConnection {
collector = packetReader.createPacketCollector(new PacketIDFilter(auth.getPacketID())); collector = packetReader.createPacketCollector(new PacketIDFilter(auth.getPacketID()));
// Send the packet. // Send the packet.
packetWriter.sendPacket(auth); packetWriter.sendPacket(auth);
// Wait up to five seconds for a response from the server. // Wait up to a certain number of seconds for a response from the server.
response = (IQ) collector.nextResult(5000); response = (IQ) collector.nextResult(REPLY_TIMEOUT);
if (response == null) { if (response == null) {
throw new XMPPException("Authentication failed."); throw new XMPPException("Authentication failed.");
} }
@ -366,8 +376,8 @@ public class XMPPConnection {
packetReader.createPacketCollector(new PacketIDFilter(auth.getPacketID())); packetReader.createPacketCollector(new PacketIDFilter(auth.getPacketID()));
// Send the packet. // Send the packet.
packetWriter.sendPacket(auth); packetWriter.sendPacket(auth);
// Wait up to five seconds for a response from the server. // Wait up to a certain number of seconds for a response from the server.
IQ response = (IQ) collector.nextResult(5000); IQ response = (IQ) collector.nextResult(REPLY_TIMEOUT);
if (response == null) { if (response == null) {
throw new XMPPException("Anonymous login failed."); throw new XMPPException("Anonymous login failed.");
} }