1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-26 16:22:06 +01:00

Adds notifications of new established connections

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2181 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2003-12-19 17:54:38 +00:00 committed by gdombiak
parent 7f25821f8b
commit a42e3c2742

View file

@ -58,6 +58,7 @@ import org.jivesoftware.smack.filter.*;
import java.lang.reflect.Constructor;
import java.net.*;
import java.util.*;
import java.io.*;
/**
@ -100,6 +101,9 @@ public class XMPPConnection {
catch (Exception e) {
}
}
private static List connectionEstablishedListeners = new ArrayList();
private SmackDebugger debugger = null;
String host;
@ -632,6 +636,31 @@ public class XMPPConnection {
}
}
/**
* Adds a connection established listener that will be notified when a new connection
* is established.
*
* @param connectionEstablishedListener a listener interested on connection established events.
*/
public static void addConnectionListener(ConnectionEstablishedListener connectionEstablishedListener) {
synchronized (connectionEstablishedListeners) {
if (!connectionEstablishedListeners.contains(connectionEstablishedListener)) {
connectionEstablishedListeners.add(connectionEstablishedListener);
}
}
}
/**
* Removes a listener on new established connections.
*
* @param connectionEstablishedListener a listener interested on connection established events.
*/
public static void removeConnectionListener(ConnectionEstablishedListener connectionEstablishedListener) {
synchronized (connectionEstablishedListeners) {
connectionEstablishedListeners.remove(connectionEstablishedListener);
}
}
/**
* Initializes the connection by creating a packet reader and writer and opening a
* XMPP stream to the server.
@ -704,5 +733,22 @@ public class XMPPConnection {
// Make note of the fact that we're now connected.
connected = true;
// Notify that a new connection has been established
connectionEstablished(this);
}
/**
* Fires listeners on connection established events.
*/
private static void connectionEstablished(XMPPConnection connection) {
ConnectionEstablishedListener[] listeners = null;
synchronized (connectionEstablishedListeners) {
listeners = new ConnectionEstablishedListener[connectionEstablishedListeners.size()];
connectionEstablishedListeners.toArray(listeners);
}
for (int i = 0; i < listeners.length; i++) {
listeners[i].connectionEstablished(connection);
}
}
}