mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-09 18:29:45 +02:00
Refactor reconnection callbacks into an extra class
Fixes SMACK-775
This commit is contained in:
parent
d804d4ed6d
commit
2edbc64957
12 changed files with 176 additions and 50 deletions
|
@ -17,12 +17,15 @@
|
|||
|
||||
package org.jivesoftware.smackx.debugger.slf4j;
|
||||
|
||||
import org.jivesoftware.smack.ConnectionListener;
|
||||
import org.jivesoftware.smack.AbstractConnectionListener;
|
||||
import org.jivesoftware.smack.ReconnectionListener;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
class SLF4JLoggingConnectionListener implements ConnectionListener {
|
||||
// TODO: The suppression of deprecated API can be removed in Smack 4.3.
|
||||
@SuppressWarnings("deprecation")
|
||||
class SLF4JLoggingConnectionListener extends AbstractConnectionListener implements ReconnectionListener {
|
||||
private final XMPPConnection connection;
|
||||
private final Logger logger;
|
||||
|
||||
|
@ -56,11 +59,6 @@ class SLF4JLoggingConnectionListener implements ConnectionListener {
|
|||
logger.debug("({}) Reconnection failed due to an exception: {}", connection.hashCode(), e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reconnectionSuccessful() {
|
||||
logger.debug("({}) Connection reconnected", connection.hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reconnectingIn(int seconds) {
|
||||
logger.debug("({}) Connection will reconnect in {}", connection.hashCode(), seconds);
|
||||
|
|
|
@ -21,6 +21,8 @@ import java.io.Reader;
|
|||
import java.io.Writer;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.jivesoftware.smack.AbstractXMPPConnection;
|
||||
import org.jivesoftware.smack.ReconnectionManager;
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.StanzaListener;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
|
@ -39,6 +41,9 @@ import org.slf4j.LoggerFactory;
|
|||
* See SLF4J manual for more details about bindings usage.
|
||||
*/
|
||||
public class SLF4JSmackDebugger implements SmackDebugger {
|
||||
|
||||
private static final java.util.logging.Logger LOGGER = java.util.logging.Logger.getLogger(SLF4JSmackDebugger.class.getName());
|
||||
|
||||
public static final String LOGGER_NAME = "SMACK";
|
||||
private static final Logger logger = LoggerFactory.getLogger(LOGGER_NAME);
|
||||
public static final AtomicBoolean printInterpreted = new AtomicBoolean(true);
|
||||
|
@ -74,7 +79,17 @@ public class SLF4JSmackDebugger implements SmackDebugger {
|
|||
this.writer.addWriterListener(slf4JRawXmlListener);
|
||||
this.reader = new ObservableReader(Validate.notNull(reader));
|
||||
this.reader.addReaderListener(slf4JRawXmlListener);
|
||||
this.connection.addConnectionListener(new SLF4JLoggingConnectionListener(connection, logger));
|
||||
|
||||
final SLF4JLoggingConnectionListener loggingConnectionListener = new SLF4JLoggingConnectionListener(connection, logger);
|
||||
this.connection.addConnectionListener(loggingConnectionListener);
|
||||
|
||||
if (connection instanceof AbstractXMPPConnection) {
|
||||
AbstractXMPPConnection abstractXmppConnection = (AbstractXMPPConnection) connection;
|
||||
ReconnectionManager.getInstanceFor(abstractXmppConnection).addReconnectionListener(loggingConnectionListener);
|
||||
} else {
|
||||
LOGGER.info("The connection instance " + connection
|
||||
+ " is not an instance of AbstractXMPPConnection, thus we can not install the ReconnectionListener");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue