1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-02 06:45:59 +01:00

Move DEBUG_ENABLED from XMPPConnection to SmackConfiguration

This commit is contained in:
Florian Schmaus 2014-04-03 13:06:43 +02:00
parent 3c2f794522
commit 4a60a68802
5 changed files with 36 additions and 34 deletions

View file

@ -62,7 +62,7 @@ public class ConnectionConfiguration implements Cloneable {
*/ */
private CallbackHandler callbackHandler; private CallbackHandler callbackHandler;
private boolean debuggerEnabled = XMPPConnection.DEBUG_ENABLED; private boolean debuggerEnabled = SmackConfiguration.DEBUG_ENABLED;
// Flag that indicates if a reconnection should be attempted when abruptly disconnected // Flag that indicates if a reconnection should be attempted when abruptly disconnected
private boolean reconnectionAllowed = true; private boolean reconnectionAllowed = true;
@ -332,7 +332,7 @@ public class ConnectionConfiguration implements Cloneable {
/** /**
* Returns true if the new connection about to be establish is going to be debugged. By * Returns true if the new connection about to be establish is going to be debugged. By
* default the value of {@link XMPPConnection#DEBUG_ENABLED} is used. * default the value of {@link SmackConfiguration#DEBUG_ENABLED} is used.
* *
* @return true if the new connection about to be establish is going to be debugged. * @return true if the new connection about to be establish is going to be debugged.
*/ */
@ -342,7 +342,7 @@ public class ConnectionConfiguration implements Cloneable {
/** /**
* Sets if the new connection about to be establish is going to be debugged. By * Sets if the new connection about to be establish is going to be debugged. By
* default the value of {@link XMPPConnection#DEBUG_ENABLED} is used. * default the value of {@link SmackConfiguration#DEBUG_ENABLED} is used.
* *
* @param debuggerEnabled if the new connection about to be establish is going to be debugged. * @param debuggerEnabled if the new connection about to be establish is going to be debugged.
*/ */

View file

@ -70,11 +70,27 @@ public final class SmackConfiguration {
private final static List<XMPPInputOutputStream> compressionHandlers = new ArrayList<XMPPInputOutputStream>(2); private final static List<XMPPInputOutputStream> compressionHandlers = new ArrayList<XMPPInputOutputStream>(2);
/** /**
* Loads the configuration from the smack-config.xml file.<p> * Value that indicates whether debugging is enabled. When enabled, a debug
* * window will apear for each new connection that will contain the following
* information:<ul>
* <li> Client Traffic -- raw XML traffic generated by Smack and sent to the server.
* <li> Server Traffic -- raw XML traffic sent by the server to the client.
* <li> Interpreted Packets -- shows XML packets from the server as parsed by Smack.
* </ul>
* <p/>
* Debugging can be enabled by setting this field to true, or by setting the Java system
* property <tt>smack.debugEnabled</tt> to true. The system property can be set on the
* command line such as "java SomeApp -Dsmack.debugEnabled=true".
*/
public static boolean DEBUG_ENABLED = false;
/**
* Loads the configuration from the smack-config.xml and system properties file.
* <p>
* So far this means that: * So far this means that:
* 1) a set of classes will be loaded in order to execute their static init block * 1) a set of classes will be loaded in order to execute their static init block
* 2) retrieve and set the current Smack release * 2) retrieve and set the current Smack release
* 3) set DEBUG_ENABLED
*/ */
static { static {
String smackVersion; String smackVersion;
@ -137,6 +153,15 @@ public final class SmackConfiguration {
// Add the Java7 compression handler first, since it's preferred // Add the Java7 compression handler first, since it's preferred
compressionHandlers.add(new Java7ZlibInputOutputStream()); compressionHandlers.add(new Java7ZlibInputOutputStream());
// Use try block since we may not have permission to get a system
// property (for example, when an applet).
try {
DEBUG_ENABLED = Boolean.getBoolean("smack.debugEnabled");
}
catch (Exception e) {
// Ignore.
}
} }
/** /**

View file

@ -104,30 +104,7 @@ public abstract class XMPPConnection {
private final static Set<ConnectionCreationListener> connectionEstablishedListeners = private final static Set<ConnectionCreationListener> connectionEstablishedListeners =
new CopyOnWriteArraySet<ConnectionCreationListener>(); new CopyOnWriteArraySet<ConnectionCreationListener>();
/**
* Value that indicates whether debugging is enabled. When enabled, a debug
* window will apear for each new connection that will contain the following
* information:<ul>
* <li> Client Traffic -- raw XML traffic generated by Smack and sent to the server.
* <li> Server Traffic -- raw XML traffic sent by the server to the client.
* <li> Interpreted Packets -- shows XML packets from the server as parsed by Smack.
* </ul>
* <p/>
* Debugging can be enabled by setting this field to true, or by setting the Java system
* property <tt>smack.debugEnabled</tt> to true. The system property can be set on the
* command line such as "java SomeApp -Dsmack.debugEnabled=true".
*/
public static boolean DEBUG_ENABLED = false;
static { static {
// Use try block since we may not have permission to get a system
// property (for example, when an applet).
try {
DEBUG_ENABLED = Boolean.getBoolean("smack.debugEnabled");
}
catch (Exception e) {
// Ignore.
}
// Ensure the SmackConfiguration class is loaded by calling a method in it. // Ensure the SmackConfiguration class is loaded by calling a method in it.
SmackConfiguration.getVersion(); SmackConfiguration.getVersion();
} }

View file

@ -187,7 +187,7 @@ public class DummyConnection extends XMPPConnection {
@Override @Override
void sendPacketInternal(Packet packet) { void sendPacketInternal(Packet packet) {
if (DEBUG_ENABLED) { if (SmackConfiguration.DEBUG_ENABLED) {
System.out.println("[SEND]: " + packet.toXML()); System.out.println("[SEND]: " + packet.toXML());
} }
queue.add(packet); queue.add(packet);
@ -244,7 +244,7 @@ public class DummyConnection extends XMPPConnection {
collector.processPacket(packet); collector.processPacket(packet);
} }
if (DEBUG_ENABLED) { if (SmackConfiguration.DEBUG_ENABLED) {
System.out.println("[RECV]: " + packet.toXML()); System.out.println("[RECV]: " + packet.toXML());
} }

View file

@ -703,7 +703,7 @@ public class RosterTest {
public synchronized void entriesAdded(Collection<String> addresses) { public synchronized void entriesAdded(Collection<String> addresses) {
addressesAdded.addAll(addresses); addressesAdded.addAll(addresses);
if (XMPPConnection.DEBUG_ENABLED) { if (SmackConfiguration.DEBUG_ENABLED) {
for (String address : addresses) { for (String address : addresses) {
System.out.println("Roster entry for " + address + " added."); System.out.println("Roster entry for " + address + " added.");
} }
@ -712,7 +712,7 @@ public class RosterTest {
public synchronized void entriesDeleted(Collection<String> addresses) { public synchronized void entriesDeleted(Collection<String> addresses) {
addressesDeleted.addAll(addresses); addressesDeleted.addAll(addresses);
if (XMPPConnection.DEBUG_ENABLED) { if (SmackConfiguration.DEBUG_ENABLED) {
for (String address : addresses) { for (String address : addresses) {
System.out.println("Roster entry for " + address + " deleted."); System.out.println("Roster entry for " + address + " deleted.");
} }
@ -721,7 +721,7 @@ public class RosterTest {
public synchronized void entriesUpdated(Collection<String> addresses) { public synchronized void entriesUpdated(Collection<String> addresses) {
addressesUpdated.addAll(addresses); addressesUpdated.addAll(addresses);
if (XMPPConnection.DEBUG_ENABLED) { if (SmackConfiguration.DEBUG_ENABLED) {
for (String address : addresses) { for (String address : addresses) {
System.out.println("Roster entry for " + address + " updated."); System.out.println("Roster entry for " + address + " updated.");
} }
@ -729,7 +729,7 @@ public class RosterTest {
} }
public void presenceChanged(Presence presence) { public void presenceChanged(Presence presence) {
if (XMPPConnection.DEBUG_ENABLED) { if (SmackConfiguration.DEBUG_ENABLED) {
System.out.println("Roster presence changed: " + presence.toXML()); System.out.println("Roster presence changed: " + presence.toXML());
} }
} }