From 67c0a7089bfa70e56578d787605c8b70c72e7308 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 7 Jan 2015 20:02:01 +0100 Subject: [PATCH] Move notifyReconnection in AbstractXMPPConnection --- .../smack/bosh/XMPPBOSHConnection.java | 4 +--- .../smack/AbstractXMPPConnection.java | 17 +++++++++++++++++ .../jivesoftware/smack/DummyConnection.java | 4 +--- .../smack/tcp/XMPPTCPConnection.java | 18 ------------------ 4 files changed, 19 insertions(+), 24 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 1dd20c3d0..7e7980ee8 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 @@ -479,9 +479,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection { if (wasAuthenticated) { login(); } - for (ConnectionListener listener : getConnectionListeners()) { - listener.reconnectionSuccessful(); - } + notifyReconnection(); } catch (Exception e) { for (ConnectionListener listener : getConnectionListeners()) { 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 b8694d255..10515ff7c 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -1073,6 +1073,23 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { } } + /** + * Sends a notification indicating that the connection was reconnected successfully. + */ + protected void notifyReconnection() { + // Notify connection listeners of the reconnection. + for (ConnectionListener listener : getConnectionListeners()) { + try { + listener.reconnectionSuccessful(); + } + catch (Exception e) { + // Catch and print any exception so we can recover + // from a faulty listener + LOGGER.log(Level.WARNING, "notifyReconnection()", e); + } + } + } + /** * A wrapper class to associate a packet filter with a listener. */ diff --git a/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java b/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java index eebeeeb34..ed07f5e03 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java @@ -81,9 +81,7 @@ public class DummyConnection extends AbstractXMPPConnection { connectionID = "dummy-" + new Random(new Date().getTime()).nextInt(); if (reconnect) { - for (ConnectionListener listener : getConnectionListeners()) { - listener.reconnectionSuccessful(); - } + notifyReconnection(); } } 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 3747ec685..03f035fbf 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 @@ -20,7 +20,6 @@ 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.ConnectionListener; import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.SmackConfiguration; import org.jivesoftware.smack.SmackException; @@ -843,23 +842,6 @@ public class XMPPTCPConnection extends AbstractXMPPConnection { callConnectionClosedOnErrorListener(e); } - /** - * Sends a notification indicating that the connection was reconnected successfully. - */ - private void notifyReconnection() { - // Notify connection listeners of the reconnection. - for (ConnectionListener listener : getConnectionListeners()) { - try { - listener.reconnectionSuccessful(); - } - catch (Exception e) { - // Catch and print any exception so we can recover - // from a faulty listener - LOGGER.log(Level.WARNING, "notifyReconnection()", e); - } - } - } - /** * For unit testing purposes *