001/**
002 *
003 * Copyright 2003-2007 Jive Software, 2020 Paul Schaub
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 is in the process of connecting.
033     * This method is called when {@link AbstractXMPPConnection#connect()} is executed.
034     *
035     * @param connection connection
036     * @since 4.4
037     */
038    default void connecting(XMPPConnection connection) {
039    }
040
041    /**
042     * Notification that the connection has been successfully connected to the remote endpoint (e.g. the XMPP server).
043     * <p>
044     * Note that the connection is likely not yet authenticated and therefore only limited operations like registering
045     * an account may be possible.
046     * </p>
047     *
048     * @param connection the XMPPConnection which successfully connected to its endpoint.
049     */
050    default void connected(XMPPConnection connection) {
051    }
052
053    /**
054     * Notification that the connection has been authenticated.
055     *
056     * @param connection the XMPPConnection which successfully authenticated.
057     * @param resumed true if a previous XMPP session's stream was resumed.
058     */
059    default void authenticated(XMPPConnection connection, boolean resumed) {
060    }
061
062    /**
063     * Notification that the connection was closed normally.
064     */
065    default void connectionClosed() {
066    }
067
068    /**
069     * Notification that the connection was closed due to an exception. When
070     * abruptly disconnected it is possible for the connection to try reconnecting
071     * to the server.
072     *
073     * @param e the exception.
074     */
075    default void connectionClosedOnError(Exception e) {
076    }
077
078}