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

View File

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

View File

@ -29,20 +29,26 @@ package org.jivesoftware.smack;
public interface ConnectionListener {
/**
* TODO
* @param connection
* Notification that the connection has been successfully connected to the remote endpoint (e.g. the XMPP server).
* <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);
/**
* TODO
* @param connection
* Notification that the connection has been authenticated.
*
* @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);
/**
* Notification that the connection was closed normally or that the reconnection
* process has been aborted.
* Notification that the connection was closed normally.
*/
public void connectionClosed();
@ -54,23 +60,33 @@ public interface ConnectionListener {
* @param e the exception.
*/
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
* 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
/**
* An attempt to connect to the server has failed. The connection will keep trying
* reconnecting to the server in a moment.
* 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.
*/
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.
*/

View File

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