diff --git a/source/org/jivesoftware/smackx/ChatStateManager.java b/source/org/jivesoftware/smackx/ChatStateManager.java index d452a9f35..759d1d06a 100644 --- a/source/org/jivesoftware/smackx/ChatStateManager.java +++ b/source/org/jivesoftware/smackx/ChatStateManager.java @@ -20,19 +20,25 @@ package org.jivesoftware.smackx; -import org.jivesoftware.smack.*; -import org.jivesoftware.smack.util.collections.ReferenceMap; -import org.jivesoftware.smack.filter.PacketFilter; +import java.lang.ref.WeakReference; +import java.util.Map; +import java.util.WeakHashMap; + +import org.jivesoftware.smack.Chat; +import org.jivesoftware.smack.ChatManagerListener; +import org.jivesoftware.smack.Connection; +import org.jivesoftware.smack.MessageListener; +import org.jivesoftware.smack.PacketInterceptor; +import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.filter.NotFilter; import org.jivesoftware.smack.filter.PacketExtensionFilter; +import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.PacketExtension; +import org.jivesoftware.smack.util.collections.ReferenceMap; import org.jivesoftware.smackx.packet.ChatStateExtension; -import java.util.Map; -import java.util.WeakHashMap; - /** * Handles chat state for all chats on a particular Connection. This class manages both the * packet extensions and the disco response neccesary for compliance with @@ -48,8 +54,8 @@ import java.util.WeakHashMap; */ public class ChatStateManager { - private static final Map managers = - new WeakHashMap(); + private static final Map> managers = + new WeakHashMap>(); private static final PacketFilter filter = new NotFilter( new PacketExtensionFilter("http://jabber.org/protocol/chatstates")); @@ -66,12 +72,16 @@ public class ChatStateManager { return null; } synchronized (managers) { - ChatStateManager manager = managers.get(connection); - if (manager == null) { + ChatStateManager manager; + WeakReference ref = managers.get(connection); + + if (ref == null) { manager = new ChatStateManager(connection); manager.init(); - managers.put(connection, manager); + managers.put(connection, new WeakReference(manager)); } + else + manager = ref.get(); return manager; }