org.jivesoftware.smack.XMPPConnectionRegistry Maven / Gradle / Ivy
The newest version!
/**
*
* Copyright 2014-2018 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smack;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
public class XMPPConnectionRegistry {
/**
* A set of listeners which will be invoked if a new connection is created.
*/
private static final Set connectionEstablishedListeners =
new CopyOnWriteArraySet<>();
/**
* Adds a new listener that will be notified when new Connections are created. Note
* that newly created connections will not be actually connected to the server.
*
* @param connectionCreationListener a listener interested on new connections.
*/
public static void addConnectionCreationListener(
ConnectionCreationListener connectionCreationListener) {
connectionEstablishedListeners.add(connectionCreationListener);
}
/**
* Removes a listener that was interested in connection creation events.
*
* @param connectionCreationListener a listener interested on new connections.
*/
public static void removeConnectionCreationListener(
ConnectionCreationListener connectionCreationListener) {
connectionEstablishedListeners.remove(connectionCreationListener);
}
/**
* Get the collection of listeners that are interested in connection creation events.
*
* @return a collection of listeners interested on new connections.
*/
protected static Collection getConnectionCreationListeners() {
return Collections.unmodifiableCollection(connectionEstablishedListeners);
}
}