Permalink
Browse files

SMACK-383: Use WeakReferences

  • Loading branch information...
1 parent 8512ae1 commit 0ffd380698bca3502a6f25c4d755fe79f6977b49 @Flowdalic committed Aug 27, 2012
View
@@ -27,6 +27,7 @@ Here's a list of patches that are included in master. If there is a issue on the
- [Roster Versioning XEP-0237](http://xmpp.org/extensions/xep-0237.html)
- BOSH support (XMPP over HTTP aka. HTTP Binding) [SMACK-187](http://issues.igniterealtime.org/browse/SMACK-187)
- Fix for [SMACK-384 Endless waiting for connection to be established](http://issues.igniterealtime.org/browse/SMACK-384)
+- Fix for [SMACK-383 Connection can't be collected by GC](http://issues.igniterealtime.org/browse/SMACK-383)
- Some more fixes I can't remeber atm
xep0198
@@ -43,7 +43,8 @@
public class PrivacyListManager {
// Keep the list of instances of this class.
- private static Map<Connection, PrivacyListManager> instances = new Hashtable<Connection, PrivacyListManager>();
+ private static Map<Connection, PrivacyListManager> instances = Collections
+ .synchronizedMap(new WeakHashMap<Connection, PrivacyListManager>());
private Connection connection;
private final List<PrivacyListListener> listeners = new ArrayList<PrivacyListListener>();
@@ -14,15 +14,16 @@
package org.jivesoftware.smackx.bytestreams.socks5;
import java.io.IOException;
+import java.lang.ref.WeakReference;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
+import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeoutException;
@@ -89,7 +90,7 @@
static {
Connection.addConnectionCreationListener(new ConnectionCreationListener() {
- public void connectionCreated(Connection connection) {
+ public void connectionCreated(final Connection connection) {
final Socks5BytestreamManager manager;
manager = Socks5BytestreamManager.getBytestreamManager(connection);
@@ -99,6 +100,14 @@ public void connectionCreated(Connection connection) {
public void connectionClosed() {
manager.disableService();
}
+
+ public void connectionClosedOnError(Exception e) {
+ manager.disableService();
+ }
+
+ public void reconnectionSuccessful() {
+ managers.put(connection, manager);
+ }
});
}
@@ -118,7 +127,7 @@ public void connectionClosed() {
private final static Random randomGenerator = new Random();
/* stores one Socks5BytestreamManager for each XMPP connection */
- private final static Map<Connection, Socks5BytestreamManager> managers = new HashMap<Connection, Socks5BytestreamManager>();
+ private final static Map<Connection, Socks5BytestreamManager> managers = new WeakHashMap<Connection, Socks5BytestreamManager>();
/* XMPP connection */
private final Connection connection;
@@ -39,8 +39,10 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -110,7 +112,8 @@ public static AdHocCommandManager getAddHocCommandsManager(Connection connection
* Value=command. Command node matches the node attribute sent by command
* requesters.
*/
- private Map<String, AdHocCommandInfo> commands = new ConcurrentHashMap<String, AdHocCommandInfo>();
+ private Map<String, AdHocCommandInfo> commands = Collections
+ .synchronizedMap(new WeakHashMap<String, AdHocCommandInfo>());
/**
* Map a command session ID with the instance LocalCommand. The LocalCommand

0 comments on commit 0ffd380

Please sign in to comment.