ConnectionListener.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software, 2020 Paul Schaub
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.jivesoftware.smack;

  18. /**
  19.  * Interface that allows for implementing classes to listen for connection closing
  20.  * and reconnection events. Listeners are registered with XMPPConnection objects.
  21.  *
  22.  * @see XMPPConnection#addConnectionListener
  23.  * @see XMPPConnection#removeConnectionListener
  24.  *
  25.  * @author Matt Tucker
  26.  */
  27. public interface ConnectionListener {

  28.     /**
  29.      * Notification that the connection is in the process of connecting.
  30.      * This method is called when {@link AbstractXMPPConnection#connect()} is executed.
  31.      *
  32.      * @param connection connection
  33.      * @since 4.4
  34.      */
  35.     default void connecting(XMPPConnection connection) {
  36.     }

  37.     /**
  38.      * Notification that the connection has been successfully connected to the remote endpoint (e.g. the XMPP server).
  39.      * <p>
  40.      * Note that the connection is likely not yet authenticated and therefore only limited operations like registering
  41.      * an account may be possible.
  42.      * </p>
  43.      *
  44.      * @param connection the XMPPConnection which successfully connected to its endpoint.
  45.      */
  46.     default void connected(XMPPConnection connection) {
  47.     }

  48.     /**
  49.      * Notification that the connection has been authenticated.
  50.      *
  51.      * @param connection the XMPPConnection which successfully authenticated.
  52.      * @param resumed true if a previous XMPP session's stream was resumed.
  53.      */
  54.     default void authenticated(XMPPConnection connection, boolean resumed) {
  55.     }

  56.     /**
  57.      * Notification that the connection was closed normally.
  58.      */
  59.     default void connectionClosed() {
  60.     }

  61.     /**
  62.      * Notification that the connection was closed due to an exception. When
  63.      * abruptly disconnected it is possible for the connection to try reconnecting
  64.      * to the server.
  65.      *
  66.      * @param e the exception.
  67.      */
  68.     default void connectionClosedOnError(Exception e) {
  69.     }

  70. }