1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-25 21:42:07 +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; package org.jivesoftware.smackx.ping.android;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.WeakHashMap; 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 String PING_ALARM_ACTION = "org.igniterealtime.smackx.ping.ACTION";
private static final Map<XMPPConnection, ServerPingWithAlarmManager> INSTANCES = Collections private static final Map<XMPPConnection, ServerPingWithAlarmManager> INSTANCES = new WeakHashMap<XMPPConnection, ServerPingWithAlarmManager>();
.synchronizedMap(new WeakHashMap<XMPPConnection, ServerPingWithAlarmManager>());
static { static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { 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.jivesoftware.smackx.xdata.packet.DataForm;
import org.jxmpp.util.cache.LruCache; import org.jxmpp.util.cache.LruCache;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
@ -89,8 +88,7 @@ public class EntityCapsManager extends Manager {
private static boolean autoEnableEntityCaps = true; private static boolean autoEnableEntityCaps = true;
private static Map<XMPPConnection, EntityCapsManager> instances = Collections private static Map<XMPPConnection, EntityCapsManager> instances = new WeakHashMap<>();
.synchronizedMap(new WeakHashMap<XMPPConnection, EntityCapsManager>());
private static final PacketFilter PRESENCES_WITH_CAPS = new AndFilter(new PacketTypeFilter(Presence.class), new PacketExtensionFilter( private static final PacketFilter PRESENCES_WITH_CAPS = new AndFilter(new PacketTypeFilter(Presence.class), new PacketExtensionFilter(
ELEMENT, NAMESPACE)); ELEMENT, NAMESPACE));

View file

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

View file

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

View file

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