1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-30 10:12:06 +01:00

Packet-reply-timeout is unique in the environment and the configuration filename was renamed to smack-config.xml

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2190 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2004-01-01 23:19:37 +00:00 committed by gdombiak
parent 41dad8658a
commit 36cb521334

View file

@ -70,7 +70,8 @@ import org.xmlpull.v1.*;
*/ */
public final class SmackConfiguration { public final class SmackConfiguration {
private static String versionNumber; private static String versionNumber = "1.3.0";
private static int packetReplyTimeout = -1;
private SmackConfiguration() { private SmackConfiguration() {
} }
@ -88,7 +89,7 @@ public final class SmackConfiguration {
// Get an array of class loaders to try loading the providers files from. // Get an array of class loaders to try loading the providers files from.
ClassLoader[] classLoaders = getClassLoaders(); ClassLoader[] classLoaders = getClassLoaders();
for (int i = 0; i < classLoaders.length; i++) { for (int i = 0; i < classLoaders.length; i++) {
Enumeration enum = classLoaders[i].getResources("META-INF/smack.configuration"); Enumeration enum = classLoaders[i].getResources("META-INF/smack-config.xml");
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
URL url = (URL) enum.nextElement(); URL url = (URL) enum.nextElement();
InputStream systemStream = null; InputStream systemStream = null;
@ -108,11 +109,8 @@ public final class SmackConfiguration {
// Attempt to load the class so that the class can get initialized // Attempt to load the class so that the class can get initialized
parseClassToLoad(parser); parseClassToLoad(parser);
} }
else if (parser.getName().equals("versionNumber")) { else if (parser.getName().equals("packetReplyTimeout")) {
versionNumber = parser.nextText(); parsePacketReplyTimeout(parser);
}
else if (parser.getName().equals("replyTimeout")) {
parseReplyTimeout(parser);
} }
} }
eventType = parser.next(); eventType = parser.next();
@ -144,43 +142,17 @@ public final class SmackConfiguration {
} }
} }
private static void parseReplyTimeout(XmlPullParser parser) throws Exception { private static void parsePacketReplyTimeout(XmlPullParser parser) throws Exception {
boolean done = false; int timeout = Integer.parseInt(parser.nextText());
String timeout = null; // Set the specified timeout value in the file if the user didn't specify
String className = null; // a timeout value before. Don't overwrite user preferences.
// Parse the timeout value to set if (packetReplyTimeout == -1) {
while (!done) { packetReplyTimeout = timeout;
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.
* gets loaded from the smack.configuration file at system startup.
* *
* @return the current Smack release version number * @return the current Smack release version number
*/ */
@ -188,6 +160,26 @@ public final class SmackConfiguration {
return versionNumber; return versionNumber;
} }
/**
* Returns the number of milliseconds to wait for a response from
* the server.
*
* @return the milliseconds to wait for a response from the server
*/
public static int getPacketReplyTimeout() {
return packetReplyTimeout;
}
/**
* Sets the number of milliseconds to wait for a response from
* the server.
*
* @param timeout the milliseconds to wait for a response from the server
*/
public static void setPacketReplyTimeout(int timeout) {
packetReplyTimeout = timeout;
}
/** /**
* Returns an array of class loaders to load resources from. * Returns an array of class loaders to load resources from.
* *