Smack/smack-experimental/src/main/java/org/jivesoftware/smackx/mix/core/MixManager.java

55 lines
1.8 KiB
Java
Raw Normal View History

2020-03-02 17:04:04 +01:00
/**
*
* Copyright 2020 Paul Schaub
*
* 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.
*/
2020-02-29 01:46:54 +01:00
package org.jivesoftware.smackx.mix.core;
import java.util.Map;
import java.util.WeakHashMap;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPConnectionRegistry;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
public final class MixManager extends Manager {
private static final Map<XMPPConnection, MixManager> INSTANCES = new WeakHashMap<>();
static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) {
MixManager.getInstanceFor(connection);
}
});
}
public static MixManager getInstanceFor(XMPPConnection connection) {
MixManager manager = INSTANCES.get(connection);
if (manager == null) {
manager = new MixManager(connection);
INSTANCES.put(connection, manager);
}
return manager;
}
private MixManager(XMPPConnection connection) {
super(connection);
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(MixCoreConstants.FEATURE_CORE_1);
}
}