XMPPConnectionRegistry.java

  1. /**
  2.  *
  3.  * Copyright 2014-2018 Florian Schmaus
  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. import java.util.Collection;
  19. import java.util.Collections;
  20. import java.util.Set;
  21. import java.util.concurrent.CopyOnWriteArraySet;

  22. public class XMPPConnectionRegistry {

  23.     /**
  24.      * A set of listeners which will be invoked if a new connection is created.
  25.      */
  26.     private static final Set<ConnectionCreationListener> connectionEstablishedListeners =
  27.             new CopyOnWriteArraySet<>();

  28.     /**
  29.      * Adds a new listener that will be notified when new Connections are created. Note
  30.      * that newly created connections will not be actually connected to the server.
  31.      *
  32.      * @param connectionCreationListener a listener interested on new connections.
  33.      */
  34.     public static void addConnectionCreationListener(
  35.             ConnectionCreationListener connectionCreationListener) {
  36.         connectionEstablishedListeners.add(connectionCreationListener);
  37.     }

  38.     /**
  39.      * Removes a listener that was interested in connection creation events.
  40.      *
  41.      * @param connectionCreationListener a listener interested on new connections.
  42.      */
  43.     public static void removeConnectionCreationListener(
  44.             ConnectionCreationListener connectionCreationListener) {
  45.         connectionEstablishedListeners.remove(connectionCreationListener);
  46.     }



  47.     /**
  48.      * Get the collection of listeners that are interested in connection creation events.
  49.      *
  50.      * @return a collection of listeners interested on new connections.
  51.      */
  52.     protected static Collection<ConnectionCreationListener> getConnectionCreationListeners() {
  53.         return Collections.unmodifiableCollection(connectionEstablishedListeners);
  54.     }

  55. }