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

Remove protected getConnectionListeners()

Also remove reconnectionFailed() from XMPPBOSHConnection, only
ReconnectionManager should call it.

Add and fix javadoc of ConnectionListener.
This commit is contained in:
Florian Schmaus 2015-01-10 01:23:20 +01:00
parent 8f8e0c7138
commit 6a43bab4f5
4 changed files with 45 additions and 43 deletions

View file

@ -34,7 +34,6 @@ import org.jivesoftware.smack.SmackException.ConnectionException;
import org.jivesoftware.smack.XMPPException.StreamErrorException; import org.jivesoftware.smack.XMPPException.StreamErrorException;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.ConnectionCreationListener; import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.Roster; import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Element; import org.jivesoftware.smack.packet.Element;
@ -475,17 +474,15 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
} }
} }
else { else {
try {
if (wasAuthenticated) { if (wasAuthenticated) {
try {
login(); login();
} }
notifyReconnection();
}
catch (Exception e) { catch (Exception e) {
for (ConnectionListener listener : getConnectionListeners()) { throw new RuntimeException(e);
listener.reconnectionFailed(e);
} }
} }
notifyReconnection();
} }
} }
else { else {

View file

@ -679,15 +679,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
connectionListeners.remove(connectionListener); connectionListeners.remove(connectionListener);
} }
/**
* Get the collection of listeners that are interested in connection events.
*
* @return a collection of listeners interested on connection events.
*/
protected Collection<ConnectionListener> getConnectionListeners() {
return connectionListeners;
}
@Override @Override
public PacketCollector createPacketCollectorAndSend(IQ packet) throws NotConnectedException { public PacketCollector createPacketCollectorAndSend(IQ packet) throws NotConnectedException {
PacketFilter packetFilter = new IQReplyFilter(packet, this); PacketFilter packetFilter = new IQReplyFilter(packet, this);
@ -1116,13 +1107,13 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
protected void callConnectionConnectedListener() { protected void callConnectionConnectedListener() {
for (ConnectionListener listener : getConnectionListeners()) { for (ConnectionListener listener : connectionListeners) {
listener.connected(this); listener.connected(this);
} }
} }
protected void callConnectionAuthenticatedListener(boolean resumed) { protected void callConnectionAuthenticatedListener(boolean resumed) {
for (ConnectionListener listener : getConnectionListeners()) { for (ConnectionListener listener : connectionListeners) {
try { try {
listener.authenticated(this, resumed); listener.authenticated(this, resumed);
} catch (Exception e) { } catch (Exception e) {
@ -1134,7 +1125,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
void callConnectionClosedListener() { void callConnectionClosedListener() {
for (ConnectionListener listener : getConnectionListeners()) { for (ConnectionListener listener : connectionListeners) {
try { try {
listener.connectionClosed(); listener.connectionClosed();
} }
@ -1148,7 +1139,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
protected void callConnectionClosedOnErrorListener(Exception e) { protected void callConnectionClosedOnErrorListener(Exception e) {
LOGGER.log(Level.WARNING, "Connection closed with error", e); LOGGER.log(Level.WARNING, "Connection closed with error", e);
for (ConnectionListener listener : getConnectionListeners()) { for (ConnectionListener listener : connectionListeners) {
try { try {
listener.connectionClosedOnError(e); listener.connectionClosedOnError(e);
} }
@ -1165,7 +1156,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
*/ */
protected void notifyReconnection() { protected void notifyReconnection() {
// Notify connection listeners of the reconnection. // Notify connection listeners of the reconnection.
for (ConnectionListener listener : getConnectionListeners()) { for (ConnectionListener listener : connectionListeners) {
try { try {
listener.reconnectionSuccessful(); listener.reconnectionSuccessful();
} }

View file

@ -29,20 +29,26 @@ package org.jivesoftware.smack;
public interface ConnectionListener { public interface ConnectionListener {
/** /**
* TODO * Notification that the connection has been successfully connected to the remote endpoint (e.g. the XMPP server).
* @param connection * <p>
* Note that the connection is likely not yet authenticated and therefore only limited operations like registering
* an account may be possible.
* </p>
*
* @param connection the XMPPConnection which successfully connected to its endpoint.
*/ */
public void connected(XMPPConnection connection); public void connected(XMPPConnection connection);
/** /**
* TODO * Notification that the connection has been authenticated.
* @param connection *
* @param connection the XMPPConnection which successfully authenticated.
* @param resumed true if a previous XMPP session's stream was resumed.
*/ */
public void authenticated(XMPPConnection connection, boolean resumed); public void authenticated(XMPPConnection connection, boolean resumed);
/** /**
* Notification that the connection was closed normally or that the reconnection * Notification that the connection was closed normally.
* process has been aborted.
*/ */
public void connectionClosed(); public void connectionClosed();
@ -55,22 +61,32 @@ public interface ConnectionListener {
*/ */
public void connectionClosedOnError(Exception e); public void connectionClosedOnError(Exception e);
/**
* The connection has reconnected successfully to the server. Connections will
* reconnect to the server when the previous socket connection was abruptly closed.
*/
public void reconnectionSuccessful();
// The next two methods *must* only be invoked by ReconnectionManager
/** /**
* The connection will retry to reconnect in the specified number of seconds. * The connection will retry to reconnect in the specified number of seconds.
* <p>
* Note: This method is only called if {@link ReconnectionManager#isAutomaticReconnectEnabled()} returns true, i.e.
* only when the reconnection manager is enabled for the connection.
* </p>
* *
* @param seconds remaining seconds before attempting a reconnection. * @param seconds remaining seconds before attempting a reconnection.
*/ */
public void reconnectingIn(int seconds); public void reconnectingIn(int seconds);
/** /**
* The connection has reconnected successfully to the server. Connections will * An attempt to connect to the server has failed. The connection will keep trying reconnecting to the server in a
* reconnect to the server when the previous socket connection was abruptly closed. * moment.
*/ * <p>
public void reconnectionSuccessful(); * Note: This method is only called if {@link ReconnectionManager#isAutomaticReconnectEnabled()} returns true, i.e.
* only when the reconnection manager is enabled for the connection.
/** * </p>
* An attempt to connect to the server has failed. The connection will keep trying
* reconnecting to the server in a moment.
* *
* @param e the exception that caused the reconnection to fail. * @param e the exception that caused the reconnection to fail.
*/ */

View file

@ -92,9 +92,7 @@ public class DummyConnection extends AbstractXMPPConnection {
roster = null; roster = null;
authenticated = false; authenticated = false;
for (ConnectionListener listener : getConnectionListeners()) { callConnectionClosedListener();
listener.connectionClosed();
}
reconnect = true; reconnect = true;
} }