use of org.jivesoftware.smack.AbstractConnectionListener in project Smack by igniterealtime.
the class EnhancedDebugger method createDebug.
/**
* Creates the debug process, which is a GUI window that displays XML traffic.
*/
private void createDebug() {
// We'll arrange the UI into six tabs. The first tab contains all data, the second
// client generated XML, the third server generated XML, the fourth allows to send
// ad-hoc messages and the fifth contains connection information.
tabbedPane = new JTabbedPane();
// Add the All Packets, Sent, Received and Interpreted panels
addBasicPanels();
// Add the panel to send ad-hoc messages
addAdhocPacketPanel();
// Add the connection information panel
addInformationPanel();
// 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
// data as Smack sees it and not as it's coming in as raw XML.
packetReaderListener = new StanzaListener() {
SimpleDateFormat dateFormatter = new SimpleDateFormat("HH:mm:ss:SS");
@Override
public void processStanza(final Stanza packet) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
addReadPacketToTable(dateFormatter, packet);
}
});
}
};
// Create a thread that will listen for all outgoing packets and write them to
// the GUI.
packetWriterListener = new StanzaListener() {
SimpleDateFormat dateFormatter = new SimpleDateFormat("HH:mm:ss:SS");
@Override
public void processStanza(final Stanza packet) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
addSentPacketToTable(dateFormatter, packet);
}
});
}
};
// Create a thread that will listen for any connection closed event
connListener = new AbstractConnectionListener() {
@Override
public void connectionClosed() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
statusField.setValue("Closed");
EnhancedDebuggerWindow.connectionClosed(EnhancedDebugger.this);
}
});
}
@Override
public void connectionClosedOnError(final Exception e) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
statusField.setValue("Closed due to an exception");
EnhancedDebuggerWindow.connectionClosedOnError(EnhancedDebugger.this, e);
}
});
}
@Override
public void reconnectingIn(final int seconds) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
statusField.setValue("Attempt to reconnect in " + seconds + " seconds");
}
});
}
@Override
public void reconnectionSuccessful() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
statusField.setValue("Reconnection stablished");
EnhancedDebuggerWindow.connectionEstablished(EnhancedDebugger.this);
}
});
}
@Override
public void reconnectionFailed(Exception e) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
statusField.setValue("Reconnection failed");
}
});
}
};
}
use of org.jivesoftware.smack.AbstractConnectionListener in project asmack by Flowdalic.
the class AndroidDebugger method createDebug.
/**
* Creates the listeners that will print in the console when new activity is detected.
*/
private void createDebug() {
// Create a special Reader that wraps the main Reader and logs data to the GUI.
ObservableReader debugReader = new ObservableReader(reader);
readerListener = new ReaderListener() {
public void read(String str) {
Log.d("SMACK", "RCV (" + connection.getConnectionCounter() + "): " + str);
}
};
debugReader.addReaderListener(readerListener);
// Create a special Writer that wraps the main Writer and logs data to the GUI.
ObservableWriter debugWriter = new ObservableWriter(writer);
writerListener = new WriterListener() {
public void write(String str) {
Log.d("SMACK", "SENT (" + connection.getConnectionCounter() + "): " + str);
}
};
debugWriter.addWriterListener(writerListener);
// Assign the reader/writer objects to use the debug versions. The packet reader
// and writer will use the debug versions when they are created.
reader = debugReader;
writer = debugWriter;
// 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
// data as Smack sees it and not as it's coming in as raw XML.
listener = new PacketListener() {
public void processPacket(Packet packet) {
if (printInterpreted) {
Log.d("SMACK", "RCV PKT (" + connection.getConnectionCounter() + "): " + packet.toXML());
}
}
};
connListener = new AbstractConnectionListener() {
public void connectionClosed() {
Log.d("SMACK", "Connection closed (" + connection.getConnectionCounter() + ")");
}
public void connectionClosedOnError(Exception e) {
Log.d("SMACK", "Connection closed due to an exception (" + connection.getConnectionCounter() + ")");
}
public void reconnectionFailed(Exception e) {
Log.d("SMACK", "Reconnection failed due to an exception (" + connection.getConnectionCounter() + ")");
}
public void reconnectionSuccessful() {
Log.d("SMACK", "Connection reconnected (" + connection.getConnectionCounter() + ")");
}
public void reconnectingIn(int seconds) {
Log.d("SMACK", "Connection (" + connection.getConnectionCounter() + ") will reconnect in " + seconds);
}
};
}
Aggregations