1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-29 07:22:07 +01:00

Use standard manager pattern in PingManager

- No need to use a synchronized map, as the getInstanceFor method is
  synchronized
- Put the PingManager in the map where it's created and not in the
  constructor
This commit is contained in:
Florian Schmaus 2014-12-26 21:25:28 +01:00
parent 0293ca2bcd
commit b17ecb4555

View file

@ -60,8 +60,7 @@ import org.jivesoftware.smackx.ping.packet.Ping;
public class PingManager extends Manager {
private static final Logger LOGGER = Logger.getLogger(PingManager.class.getName());
private static final Map<XMPPConnection, PingManager> INSTANCES = Collections
.synchronizedMap(new WeakHashMap<XMPPConnection, PingManager>());
private static final Map<XMPPConnection, PingManager> INSTANCES = new WeakHashMap<XMPPConnection, PingManager>();
private static final PacketFilter PING_PACKET_FILTER = new AndFilter(
new PacketTypeFilter(Ping.class), IQTypeFilter.GET);
@ -86,6 +85,7 @@ public class PingManager extends Manager {
PingManager pingManager = INSTANCES.get(connection);
if (pingManager == null) {
pingManager = new PingManager(connection);
INSTANCES.put(connection, pingManager);
}
return pingManager;
}
@ -119,7 +119,6 @@ public class PingManager extends Manager {
new SmackExecutorThreadFactory(connection.getConnectionCounter(), "Ping"));
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
sdm.addFeature(Ping.NAMESPACE);
INSTANCES.put(connection, this);
connection.addPacketListener(new PacketListener() {
// Send a Pong for every Ping