mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 05:52:06 +01:00
Use listener for debug tool.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1807 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
1c40c3c348
commit
8322f022cc
1 changed files with 20 additions and 24 deletions
|
@ -369,8 +369,8 @@ public class XMPPConnection {
|
||||||
* Creates a new packet collector for this connection. A packet filter determines
|
* Creates a new packet collector for this connection. A packet filter determines
|
||||||
* which packets will be accumulated by the collector.
|
* which packets will be accumulated by the collector.
|
||||||
*
|
*
|
||||||
* @param packetFilter
|
* @param packetFilter the packet filter to use.
|
||||||
* @return
|
* @return a new packet collector.
|
||||||
*/
|
*/
|
||||||
public PacketCollector createPacketCollector(PacketFilter packetFilter) {
|
public PacketCollector createPacketCollector(PacketFilter packetFilter) {
|
||||||
return packetReader.createPacketCollector(packetFilter);
|
return packetReader.createPacketCollector(packetFilter);
|
||||||
|
@ -392,11 +392,11 @@ public class XMPPConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If debugging is enabled, we open a window and write out all network traffic.
|
// If debugging is enabled, we open a window and write out all network traffic.
|
||||||
// The method that creates the debug GUI returns a thread that we must start after
|
// The method that creates the debug GUI returns PacketListener that we must add
|
||||||
// the packet reader and writer are created.
|
// after the packet reader and writer are created.
|
||||||
Thread allPacketListener = null;
|
PacketListener debugListener = null;
|
||||||
if (DEBUG_ENABLED) {
|
if (DEBUG_ENABLED) {
|
||||||
allPacketListener = createDebug();
|
debugListener = createDebug();
|
||||||
}
|
}
|
||||||
|
|
||||||
packetWriter = new PacketWriter(this);
|
packetWriter = new PacketWriter(this);
|
||||||
|
@ -405,7 +405,7 @@ public class XMPPConnection {
|
||||||
// If debugging is enabled, we should start the thread that will listen for
|
// If debugging is enabled, we should start the thread that will listen for
|
||||||
// all packets and then log them.
|
// all packets and then log them.
|
||||||
if (DEBUG_ENABLED) {
|
if (DEBUG_ENABLED) {
|
||||||
allPacketListener.start();
|
packetReader.addPacketListener(debugListener, null);
|
||||||
}
|
}
|
||||||
// Start the packet writer. This will open a Jabber stream to the server
|
// Start the packet writer. This will open a Jabber stream to the server
|
||||||
packetWriter.startup();
|
packetWriter.startup();
|
||||||
|
@ -419,15 +419,15 @@ public class XMPPConnection {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the debug process, which is a GUI window that displays XML traffic.
|
* Creates the debug process, which is a GUI window that displays XML traffic.
|
||||||
* This method must be called before the packet reader and writer are called because
|
* This method must be called before the packet reader and writer are created because
|
||||||
* it wraps the reader and writer objects with special logging implementations.
|
* it wraps the reader and writer objects with special logging implementations.
|
||||||
* The method returns a Thread that must be started after the packet reader and writer
|
* The method returns a PacketListner that must be added after the packet reader is
|
||||||
* are started.
|
* created.
|
||||||
*
|
*
|
||||||
* @return a Thread used by the debugging process that must be started after the packet
|
* @return a PacketListener used by the debugging process that must be added after the packet
|
||||||
* reader and writer are created.
|
* reader is created.
|
||||||
*/
|
*/
|
||||||
private Thread createDebug() {
|
private PacketListener createDebug() {
|
||||||
// Use the native look and feel.
|
// Use the native look and feel.
|
||||||
try {
|
try {
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
|
@ -603,18 +603,14 @@ public class XMPPConnection {
|
||||||
// Create a thread that will listen for all incoming packets and write them to
|
// Create a thread that will listen for all incoming packets and write them to
|
||||||
// the GUI. This is what we call "interpreted" packet data, since it's the packet
|
// the GUI. This is what we call "interpreted" packet data, since it's the packet
|
||||||
// data as Smack sees it and not as it's coming in as raw XML.
|
// data as Smack sees it and not as it's coming in as raw XML.
|
||||||
Thread allPacketListener = new Thread() {
|
PacketListener debugListener = new PacketListener() {
|
||||||
public void run() {
|
public void processPacket(Packet packet) {
|
||||||
PacketCollector collector = packetReader.createPacketCollector(null);
|
|
||||||
while (true) {
|
|
||||||
Packet packet = collector.nextResult();
|
|
||||||
interpretedText1.append(packet.toXML());
|
interpretedText1.append(packet.toXML());
|
||||||
interpretedText2.append(packet.toXML());
|
interpretedText2.append(packet.toXML());
|
||||||
interpretedText1.append(NEWLINE);
|
interpretedText1.append(NEWLINE);
|
||||||
interpretedText2.append(NEWLINE);
|
interpretedText2.append(NEWLINE);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
return allPacketListener;
|
return debugListener;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue