From f410ece468b98ae9f8681ac9c1da82f5f1b8e044 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Tue, 17 Mar 2015 12:06:55 +0100 Subject: [PATCH] Call connection created listeners in constructor Fixes SMACK-638. --- .../jivesoftware/smack/bosh/XMPPBOSHConnection.java | 4 ---- .../jivesoftware/smack/AbstractXMPPConnection.java | 13 ++++--------- .../jivesoftware/smack/tcp/XMPPTCPConnection.java | 8 -------- 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java index e543b6ff8..3ba697897 100644 --- a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java +++ b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java @@ -31,7 +31,6 @@ import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.SmackException.ConnectionException; import org.jivesoftware.smack.XMPPException.StreamErrorException; import org.jivesoftware.smack.XMPPConnection; -import org.jivesoftware.smack.ConnectionCreationListener; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.Element; import org.jivesoftware.smack.packet.IQ; @@ -435,9 +434,6 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection { connected = true; if (isFirstInitialization) { isFirstInitialization = false; - for (ConnectionCreationListener listener : getConnectionCreationListeners()) { - listener.connectionCreated(XMPPBOSHConnection.this); - } } else { if (wasAuthenticated) { diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index 695c3f59b..d15e996ac 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -102,15 +102,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { SmackConfiguration.getVersion(); } - /** - * Get the collection of listeners that are interested in connection creation events. - * - * @return a collection of listeners interested on new connections. - */ - protected static Collection getConnectionCreationListeners() { - return XMPPConnectionRegistry.getConnectionCreationListeners(); - } - /** * A collection of ConnectionListeners which listen for connection closing * and reconnection events. @@ -302,6 +293,10 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { */ protected AbstractXMPPConnection(ConnectionConfiguration configuration) { config = configuration; + // Notify listeners that a new connection has been established + for (ConnectionCreationListener listener : XMPPConnectionRegistry.getConnectionCreationListeners()) { + listener.connectionCreated(this); + } } protected ConnectionConfiguration getConfiguration() { diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java index 1cdbcbb60..edb07b632 100644 --- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java +++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java @@ -19,7 +19,6 @@ package org.jivesoftware.smack.tcp; import org.jivesoftware.smack.AbstractXMPPConnection; import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode; -import org.jivesoftware.smack.ConnectionCreationListener; import org.jivesoftware.smack.StanzaListener; import org.jivesoftware.smack.SmackConfiguration; import org.jivesoftware.smack.SmackException; @@ -633,13 +632,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { // Start the packet reader. The startup() method will block until we // get an opening stream packet back from server packetReader.init(); - - if (isFirstInitialization) { - // Notify listeners that a new connection has been established - for (ConnectionCreationListener listener : getConnectionCreationListeners()) { - listener.connectionCreated(this); - } - } } private void initReaderAndWriter() throws IOException {