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

@ -1,14 +1,38 @@
<?xml version="1.0"?>
<?xml version="1.0"?>
<!-- Configuration file to load at system start up -->
<smackSystem>
<!-- Classes to load at start up -->
<classesToLoad>
<className>org.jivesoftware.smackx.ServiceDiscoveryManager</className>
<className>org.jivesoftware.smackx.XHTMLManager</className>
</classesToLoad>
<smackSystem>
<!-- Smack Release -->
<versionNumber>1.3.0</versionNumber>
<versionNumber>1.3.0</versionNumber>
<!-- Classes to load at start up -->
<classesToLoad>
<className>org.jivesoftware.smackx.ServiceDiscoveryManager</className>
<className>org.jivesoftware.smackx.XHTMLManager</className>
</classesToLoad>
<!-- Default reply timeout milliseconds -->
<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>

View File

@ -67,6 +67,16 @@ import java.util.*;
*/
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 Registration info = null;
@ -207,7 +217,7 @@ public class AccountManager {
new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(5000);
IQ result = (IQ)collector.nextResult(REPLY_TIMEOUT);
if (result == null) {
throw new XMPPException("No response from server.");
}
@ -234,7 +244,7 @@ public class AccountManager {
new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(5000);
IQ result = (IQ)collector.nextResult(REPLY_TIMEOUT);
if (result == null) {
throw new XMPPException("No response from server.");
}
@ -266,7 +276,7 @@ public class AccountManager {
new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(5000);
IQ result = (IQ)collector.nextResult(REPLY_TIMEOUT);
if (result == null) {
throw new XMPPException("No response from server.");
}
@ -287,7 +297,7 @@ public class AccountManager {
new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(5000);
IQ result = (IQ)collector.nextResult(REPLY_TIMEOUT);
if (result == null) {
throw new XMPPException("No response from server.");
}

View File

@ -69,6 +69,16 @@ import java.util.*;
*/
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 String room;
private String nickname = null;
@ -151,7 +161,7 @@ public class GroupChat {
* nickname.
*/
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);
// Send join packet.
connection.sendPacket(joinPresence);
// Wait up to five seconds for a reply.
Presence presence = (Presence)response.nextResult(5000);
// Wait up to a certain number of seconds for a reply.
Presence presence = (Presence)response.nextResult(timeout);
if (presence == null) {
throw new XMPPException("No response from server.");
}

View File

@ -96,6 +96,16 @@ public class Roster {
*/
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 Map groups;
private List entries;
@ -237,11 +247,11 @@ public class Roster {
}
}
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(
new PacketIDFilter(rosterPacket.getPacketID()));
connection.sendPacket(rosterPacket);
IQ response = (IQ)collector.nextResult(5000);
IQ response = (IQ)collector.nextResult(REPLY_TIMEOUT);
if (response == null) {
throw new XMPPException("No response from the server.");
}

View File

@ -53,6 +53,7 @@
package org.jivesoftware.smack;
import java.io.*;
import java.lang.reflect.*;
import java.net.*;
import java.util.*;
@ -104,18 +105,15 @@ public final class SmackConfiguration {
do {
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("className")) {
String className = parser.nextText();
// Attempt to load the class so that the class can get initialized
try {
Class provider = Class.forName(className);
}
catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
parseClassToLoad(parser);
}
else if (parser.getName().equals("versionNumber")) {
versionNumber = parser.nextText();
}
else if (parser.getName().equals("replyTimeout")) {
parseReplyTimeout(parser);
}
}
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
* 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;
/**
* 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();
static {
// 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()));
// Send the packet
packetWriter.sendPacket(discoveryAuth);
// Wait up to five seconds for a response from the server.
IQ response = (IQ) collector.nextResult(5000);
// Wait up to a certain number of seconds for a response from the server.
IQ response = (IQ) collector.nextResult(REPLY_TIMEOUT);
if (response == null) {
throw new XMPPException("No response from the server.");
}
@ -302,8 +312,8 @@ public class XMPPConnection {
collector = packetReader.createPacketCollector(new PacketIDFilter(auth.getPacketID()));
// Send the packet.
packetWriter.sendPacket(auth);
// Wait up to five seconds for a response from the server.
response = (IQ) collector.nextResult(5000);
// Wait up to a certain number of seconds for a response from the server.
response = (IQ) collector.nextResult(REPLY_TIMEOUT);
if (response == null) {
throw new XMPPException("Authentication failed.");
}
@ -366,8 +376,8 @@ public class XMPPConnection {
packetReader.createPacketCollector(new PacketIDFilter(auth.getPacketID()));
// Send the packet.
packetWriter.sendPacket(auth);
// Wait up to five seconds for a response from the server.
IQ response = (IQ) collector.nextResult(5000);
// Wait up to a certain number of seconds for a response from the server.
IQ response = (IQ) collector.nextResult(REPLY_TIMEOUT);
if (response == null) {
throw new XMPPException("Anonymous login failed.");
}