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) {
login(); try {
login();
}
catch (Exception e) {
throw new RuntimeException(e);
}
} }
notifyReconnection(); notifyReconnection();
}
catch (Exception e) {
for (ConnectionListener listener : getConnectionListeners()) {
listener.reconnectionFailed(e);
}
}
} }
} }
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();
@ -54,23 +60,33 @@ public interface ConnectionListener {
* @param e the exception. * @param e the exception.
*/ */
public void connectionClosedOnError(Exception e); public void connectionClosedOnError(Exception e);
/**
* The connection will retry to reconnect in the specified number of seconds.
*
* @param seconds remaining seconds before attempting a reconnection.
*/
public void reconnectingIn(int seconds);
/** /**
* The connection has reconnected successfully to the server. Connections will * The connection has reconnected successfully to the server. Connections will
* reconnect to the server when the previous socket connection was abruptly closed. * reconnect to the server when the previous socket connection was abruptly closed.
*/ */
public void reconnectionSuccessful(); public void reconnectionSuccessful();
// The next two methods *must* only be invoked by ReconnectionManager
/** /**
* An attempt to connect to the server has failed. The connection will keep trying * The connection will retry to reconnect in the specified number of seconds.
* reconnecting to the server in a moment. * <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.
*/
public void reconnectingIn(int seconds);
/**
* An attempt to connect to the server has failed. The connection will keep trying reconnecting to the server in a
* moment.
* <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 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;
} }