mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 18:59:41 +02:00
Added ConnectionListener support.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1983 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
ed14b2a204
commit
b25380282c
3 changed files with 121 additions and 3 deletions
|
@ -90,6 +90,7 @@ class PacketReader {
|
|||
private boolean done = false;
|
||||
protected List collectors = new ArrayList();
|
||||
private List listeners = new ArrayList();
|
||||
protected List connectionListeners = new ArrayList();
|
||||
|
||||
private String connectionID = null;
|
||||
private Object connectionIDLock = new Object();
|
||||
|
@ -271,17 +272,29 @@ class PacketReader {
|
|||
else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (parser.getName().equals("stream")) {
|
||||
connection.close();
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
eventType = parser.next();
|
||||
} while (eventType != XmlPullParser.END_DOCUMENT && !done);
|
||||
synchronized (connectionListeners) {
|
||||
for (Iterator i=connectionListeners.iterator(); i.hasNext(); ) {
|
||||
ConnectionListener listener = (ConnectionListener)i.next();
|
||||
listener.connectionClosed();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (!done) {
|
||||
// An exception occurred while parsing. Print the error an close the
|
||||
// connection.
|
||||
e.printStackTrace();
|
||||
// An exception occurred while parsing. Notify connection listeners of
|
||||
// the error and close the connection.
|
||||
connection.close();
|
||||
synchronized (connectionListeners) {
|
||||
for (Iterator i=connectionListeners.iterator(); i.hasNext(); ) {
|
||||
ConnectionListener listener = (ConnectionListener)i.next();
|
||||
listener.connectionClosedOnError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue