001/**
002 *
003 * Copyright 2003-2007 Jive Software.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.jivesoftware.smack;
019
020/**
021 * Interface that allows for implementing classes to listen for connection closing
022 * and reconnection events. Listeners are registered with XMPPConnection objects.
023 *
024 * @see XMPPConnection#addConnectionListener
025 * @see XMPPConnection#removeConnectionListener
026 * 
027 * @author Matt Tucker
028 */
029public interface ConnectionListener {
030
031    /**
032     * Notification that the connection has been successfully connected to the remote endpoint (e.g. the XMPP server).
033     * <p>
034     * Note that the connection is likely not yet authenticated and therefore only limited operations like registering
035     * an account may be possible.
036     * </p>
037     *
038     * @param connection the XMPPConnection which successfully connected to its endpoint.
039     */
040    void connected(XMPPConnection connection);
041
042    /**
043     * Notification that the connection has been authenticated.
044     *
045     * @param connection the XMPPConnection which successfully authenticated.
046     * @param resumed true if a previous XMPP session's stream was resumed.
047     */
048    void authenticated(XMPPConnection connection, boolean resumed);
049
050    /**
051     * Notification that the connection was closed normally.
052     */
053    void connectionClosed();
054
055    /**
056     * Notification that the connection was closed due to an exception. When
057     * abruptly disconnected it is possible for the connection to try reconnecting
058     * to the server.
059     *
060     * @param e the exception.
061     */
062    void connectionClosedOnError(Exception e);
063
064    /**
065     * The connection has reconnected successfully to the server. Connections will
066     * reconnect to the server when the previous socket connection was abruptly closed.
067     * @deprecated use {@link #connected(XMPPConnection)} or {@link #authenticated(XMPPConnection, boolean)} instead.
068     */
069    // TODO: Remove in Smack 4.3
070    @Deprecated
071    void reconnectionSuccessful();
072
073    // The next two methods *must* only be invoked by ReconnectionManager
074
075    /**
076     * The connection will retry to reconnect in the specified number of seconds.
077     * <p>
078     * Note: This method is only called if {@link ReconnectionManager#isAutomaticReconnectEnabled()} returns true, i.e.
079     * only when the reconnection manager is enabled for the connection.
080     * </p>
081     * 
082     * @param seconds remaining seconds before attempting a reconnection.
083     */
084    // TODO: Remove in Smack 4.3
085    @Deprecated
086    void reconnectingIn(int seconds);
087
088    /**
089     * An attempt to connect to the server has failed. The connection will keep trying reconnecting to the server in a
090     * moment.
091     * <p>
092     * Note: This method is only called if {@link ReconnectionManager#isAutomaticReconnectEnabled()} returns true, i.e.
093     * only when the reconnection manager is enabled for the connection.
094     * </p>
095     *
096     * @param e the exception that caused the reconnection to fail.
097     */
098    // TODO: Remove in Smack 4.3
099    @Deprecated
100    void reconnectionFailed(Exception e);
101}