1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-22 20:47:57 +01:00

Don't use synchonrizedMap() for INSTANCES

in Managers. The getInstanceFor() method is already synchronized.
This commit is contained in:
Florian Schmaus 2014-12-27 13:37:02 +01:00
parent 6334733dae
commit 56bf54eab5
6 changed files with 12 additions and 21 deletions

View file

@ -17,7 +17,6 @@
package org.jivesoftware.smackx.ping.android;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.WeakHashMap;
@ -67,8 +66,7 @@ public class ServerPingWithAlarmManager extends Manager {
private static final String PING_ALARM_ACTION = "org.igniterealtime.smackx.ping.ACTION";
private static final Map<XMPPConnection, ServerPingWithAlarmManager> INSTANCES = Collections
.synchronizedMap(new WeakHashMap<XMPPConnection, ServerPingWithAlarmManager>());
private static final Map<XMPPConnection, ServerPingWithAlarmManager> INSTANCES = new WeakHashMap<XMPPConnection, ServerPingWithAlarmManager>();
static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {

View file

@ -47,7 +47,6 @@ import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.jxmpp.util.cache.LruCache;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
@ -89,8 +88,7 @@ public class EntityCapsManager extends Manager {
private static boolean autoEnableEntityCaps = true;
private static Map<XMPPConnection, EntityCapsManager> instances = Collections
.synchronizedMap(new WeakHashMap<XMPPConnection, EntityCapsManager>());
private static Map<XMPPConnection, EntityCapsManager> instances = new WeakHashMap<>();
private static final PacketFilter PRESENCES_WITH_CAPS = new AndFilter(new PacketTypeFilter(Presence.class), new PacketExtensionFilter(
ELEMENT, NAMESPACE));

View file

@ -19,7 +19,6 @@ package org.jivesoftware.smackx.commands;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
@ -71,8 +70,7 @@ public class AdHocCommandManager extends Manager {
* Map a XMPPConnection with it AdHocCommandManager. This map have a key-value
* pair for every active connection.
*/
private static Map<XMPPConnection, AdHocCommandManager> instances =
Collections.synchronizedMap(new WeakHashMap<XMPPConnection, AdHocCommandManager>());
private static Map<XMPPConnection, AdHocCommandManager> instances = new WeakHashMap<>();
/**
* Register the listener for all the connection creations. When a new
@ -96,7 +94,10 @@ public class AdHocCommandManager extends Manager {
*/
public static synchronized AdHocCommandManager getAddHocCommandsManager(XMPPConnection connection) {
AdHocCommandManager ahcm = instances.get(connection);
if (ahcm == null) ahcm = new AdHocCommandManager(connection);
if (ahcm == null) {
ahcm = new AdHocCommandManager(connection);
instances.put(connection, ahcm);
}
return ahcm;
}
@ -125,9 +126,6 @@ public class AdHocCommandManager extends Manager {
private AdHocCommandManager(XMPPConnection connection) {
super(connection);
this.serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
// Register the new instance and associate it with the connection
instances.put(connection, this);
// Add the feature to the service discovery manage to show that this
// connection supports the AdHoc-Commands protocol.

View file

@ -82,8 +82,7 @@ public class ServiceDiscoveryManager extends Manager {
private EntityCapsManager capsManager;
private static Map<XMPPConnection, ServiceDiscoveryManager> instances =
Collections.synchronizedMap(new WeakHashMap<XMPPConnection, ServiceDiscoveryManager>());
private static Map<XMPPConnection, ServiceDiscoveryManager> instances = new WeakHashMap<>();
private final Set<String> features = new HashSet<String>();
private DataForm extendedInfo = null;

View file

@ -18,7 +18,6 @@
package org.jivesoftware.smackx.xevent;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
@ -51,8 +50,7 @@ import org.jivesoftware.smackx.xevent.packet.MessageEvent;
public class MessageEventManager extends Manager {
private static final Logger LOGGER = Logger.getLogger(MessageEventManager.class.getName());
private static final Map<XMPPConnection, MessageEventManager> INSTANCES = Collections
.synchronizedMap(new WeakHashMap<XMPPConnection, MessageEventManager>());
private static final Map<XMPPConnection, MessageEventManager> INSTANCES = new WeakHashMap<>();
private static final PacketFilter PACKET_FILTER = new AndFilter(new PacketExtensionFilter(
new MessageEvent()), new NotFilter(MessageTypeFilter.ERROR));
@ -64,6 +62,7 @@ public class MessageEventManager extends Manager {
MessageEventManager messageEventManager = INSTANCES.get(connection);
if (messageEventManager == null) {
messageEventManager = new MessageEventManager(connection);
INSTANCES.put(connection, messageEventManager);
}
return messageEventManager;
}
@ -97,7 +96,6 @@ public class MessageEventManager extends Manager {
eventType.concat("Notification"));
}
}, PACKET_FILTER);
INSTANCES.put(connection, this);
}
/**

View file

@ -50,8 +50,7 @@ public class RosterExchangeManager {
public final static String NAMESPACE = "jabber:x:roster";
public final static String ELEMENT = "x";
private final static Map<XMPPConnection, RosterExchangeManager> INSTANCES =
Collections.synchronizedMap(new WeakHashMap<XMPPConnection, RosterExchangeManager>());
private final static Map<XMPPConnection, RosterExchangeManager> INSTANCES = new WeakHashMap<>();
private final static PacketFilter PACKET_FILTER = new PacketExtensionFilter(ELEMENT, NAMESPACE);
@ -64,6 +63,7 @@ public class RosterExchangeManager {
RosterExchangeManager rosterExchangeManager = INSTANCES.get(connection);
if (rosterExchangeManager == null) {
rosterExchangeManager = new RosterExchangeManager(connection);
INSTANCES.put(connection, rosterExchangeManager);
}
return rosterExchangeManager;
}