From 1df3841a41b9e2c43ea0d3abb6b1e4551921709e Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 5 Feb 2014 19:59:57 +0100 Subject: [PATCH 01/14] Eclipse: Add build/resources to classpath So that SmackConfiguration is able to load files from META-INF --- build/eclipse/classpath | 1 + 1 file changed, 1 insertion(+) diff --git a/build/eclipse/classpath b/build/eclipse/classpath index 135c0ca29..30a67022b 100644 --- a/build/eclipse/classpath +++ b/build/eclipse/classpath @@ -33,5 +33,6 @@ + From 68a570b4fea470a79fe5acd349697e7a8520f9d4 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 5 Feb 2014 20:04:13 +0100 Subject: [PATCH 02/14] Use WeakReference in MUC NodeInformationProvider MultiUserChat's NodeInformationProvider must not hold a strong reference to the Connection instance. Fixes SMACK-540. --- source/org/jivesoftware/smackx/muc/MultiUserChat.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/org/jivesoftware/smackx/muc/MultiUserChat.java b/source/org/jivesoftware/smackx/muc/MultiUserChat.java index db8a80f73..85d1aa8e1 100644 --- a/source/org/jivesoftware/smackx/muc/MultiUserChat.java +++ b/source/org/jivesoftware/smackx/muc/MultiUserChat.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.WeakHashMap; @@ -116,12 +117,16 @@ public class MultiUserChat { // Chat protocol. This information will be used when another client tries to // discover whether this client supports MUC or not. ServiceDiscoveryManager.getInstanceFor(connection).addFeature(discoNamespace); + // Set the NodeInformationProvider that will provide information about the // joined rooms whenever a disco request is received + final WeakReference weakRefConnection = new WeakReference(connection); ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider( discoNode, new NodeInformationProvider() { public List getNodeItems() { + Connection connection = weakRefConnection.get(); + if (connection == null) return new LinkedList(); List answer = new ArrayList(); Iterator rooms=MultiUserChat.getJoinedRooms(connection); while (rooms.hasNext()) { From c4edd1f27c9ac2c00863c5116cf21436fdeaefca Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 6 Feb 2014 09:45:26 +0100 Subject: [PATCH 03/14] Untabify build.xml Only non-semantic whitespace fixes --- build/build.xml | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/build/build.xml b/build/build.xml index 574660cc3..4b50f27ba 100644 --- a/build/build.xml +++ b/build/build.xml @@ -29,33 +29,33 @@ - + - + - - + + - - + + - - + + - + - - + + @@ -140,7 +140,7 @@ - + - + - + @@ -228,8 +228,8 @@ - - + + - - - + + + @@ -270,8 +270,8 @@ - - + + @@ -289,7 +289,7 @@ - + - + + + + + + + + + + + + + + + + + + + @@ -52,6 +73,14 @@ + + + + + + + + From f125077f34401edb18c2f9c4af6a1f570c1b88e6 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 6 Feb 2014 10:18:27 +0100 Subject: [PATCH 05/14] Add file local variables to build.xml --- build/build.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build/build.xml b/build/build.xml index 79ea47ae0..7867407c0 100644 --- a/build/build.xml +++ b/build/build.xml @@ -597,3 +597,7 @@ + + + + From 05ccada19588ee70bdf930ef6509b62e4d8542a7 Mon Sep 17 00:00:00 2001 From: rcollier Date: Mon, 3 Feb 2014 02:03:54 +0000 Subject: [PATCH 06/14] Updated version for post release git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_4_0@13893 b35dd754-fafc-0310-a699-88a17e54d16e --- build/build.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/build.xml b/build/build.xml index 7867407c0..a0b38dc34 100644 --- a/build/build.xml +++ b/build/build.xml @@ -27,9 +27,9 @@ - - - + + + From f021d7efb1016c4e187a33cbf7237a724f71babd Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 6 Feb 2014 18:10:15 +0100 Subject: [PATCH 07/14] Cleanup of build.xml's release target no.test wasn't used in that path anyways, so remove it. And release-exists will always return true since the release.xml Ant script is part of the repository. --- build/build.xml | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/build/build.xml b/build/build.xml index a0b38dc34..c26cdf209 100644 --- a/build/build.xml +++ b/build/build.xml @@ -544,13 +544,7 @@ - - - - - - - + @@ -574,13 +568,6 @@ - - - - - - - From f9d125127ba23840aa9e49ab63fe031c55c0c14d Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 6 Feb 2014 18:18:27 +0100 Subject: [PATCH 08/14] Fix javadoc Java API link --- build/build.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build/build.xml b/build/build.xml index c26cdf209..3164c18a4 100644 --- a/build/build.xml +++ b/build/build.xml @@ -408,8 +408,7 @@ Smack ${version}]]>
Smack]]>
Copyright © 2003-2007 Jive Software. ]]> - - +
From 89838f5843cc983d014cb3f616a7f8d1a2109347 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 6 Feb 2014 18:19:27 +0100 Subject: [PATCH 09/14] Format build.xml's checkcode target Whitespace fix only. No semantic changes --- build/build.xml | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/build/build.xml b/build/build.xml index 3164c18a4..152b03b9e 100644 --- a/build/build.xml +++ b/build/build.xml @@ -547,25 +547,25 @@ - - - - - - - - - - - - migrating - finalizers - - - - - - + + + + + + + + + + + + migrating + finalizers + + + + + + From 4c8af8c17f7fefc02743c6606339df4efb46b4e7 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 7 Feb 2014 12:15:04 +0100 Subject: [PATCH 10/14] Don't use manager's constructor in connectionCreated This could cause duplicate managers. Use getInstanceFor() instead. SMACK-403. --- .../source/org/jivesoftware/smackx/carbons/CarbonManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/experimental/source/org/jivesoftware/smackx/carbons/CarbonManager.java b/experimental/source/org/jivesoftware/smackx/carbons/CarbonManager.java index 9217860ce..bdc00a31e 100644 --- a/experimental/source/org/jivesoftware/smackx/carbons/CarbonManager.java +++ b/experimental/source/org/jivesoftware/smackx/carbons/CarbonManager.java @@ -51,7 +51,7 @@ public class CarbonManager { static { Connection.addConnectionCreationListener(new ConnectionCreationListener() { public void connectionCreated(Connection connection) { - new CarbonManager(connection); + getInstanceFor(connection); } }); } @@ -73,7 +73,7 @@ public class CarbonManager { * * @return a CarbonManager instance */ - public static CarbonManager getInstanceFor(Connection connection) { + public static synchronized CarbonManager getInstanceFor(Connection connection) { CarbonManager carbonManager = instances.get(connection); if (carbonManager == null) { From 666f555733adf4e87edbaf93e751ecf542c302f7 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 7 Feb 2014 12:40:48 +0100 Subject: [PATCH 11/14] Update eclipse project name --- build/eclipse/project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/eclipse/project b/build/eclipse/project index 4d04574a8..b4051fde4 100644 --- a/build/eclipse/project +++ b/build/eclipse/project @@ -1,6 +1,6 @@ - smack-3.4.x + Smack From 9c61c6c945eed3c9b070d9fbd96b8836c1571490 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 7 Feb 2014 13:17:36 +0100 Subject: [PATCH 12/14] Convert Connection references to weak references If a Manager is strong referenced from a gc root, usually the instances map, it should not hold itself a strong reference the connection in order to avoid a cycle that prevents the Connection instance from being gc'ed. SMACK-383 --- .../smackx/carbons/CarbonManager.java | 8 ++- .../smack/keepalive/KeepAliveManager.java | 53 ++++++++++--------- .../smackx/MessageEventManager.java | 1 - .../jivesoftware/smackx/ping/PingManager.java | 12 +++-- .../receipts/DeliveryReceiptManager.java | 7 ++- 5 files changed, 46 insertions(+), 35 deletions(-) diff --git a/experimental/source/org/jivesoftware/smackx/carbons/CarbonManager.java b/experimental/source/org/jivesoftware/smackx/carbons/CarbonManager.java index bdc00a31e..dc2159925 100644 --- a/experimental/source/org/jivesoftware/smackx/carbons/CarbonManager.java +++ b/experimental/source/org/jivesoftware/smackx/carbons/CarbonManager.java @@ -16,6 +16,7 @@ package org.jivesoftware.smackx.carbons; +import java.lang.ref.WeakReference; import java.util.Collections; import java.util.Map; import java.util.WeakHashMap; @@ -56,13 +57,13 @@ public class CarbonManager { }); } - private Connection connection; + private WeakReference weakRefConnection; private volatile boolean enabled_state = false; private CarbonManager(Connection connection) { ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); sdm.addFeature(Carbon.NAMESPACE); - this.connection = connection; + weakRefConnection = new WeakReference(connection); instances.put(connection, this); } @@ -99,6 +100,7 @@ public class CarbonManager { * @return true if supported */ public boolean isSupportedByServer() { + Connection connection = weakRefConnection.get(); try { DiscoverInfo result = ServiceDiscoveryManager .getInstanceFor(connection).discoverInfo(connection.getServiceName()); @@ -118,6 +120,7 @@ public class CarbonManager { * @param new_state whether carbons should be enabled or disabled */ public void sendCarbonsEnabled(final boolean new_state) { + final Connection connection = weakRefConnection.get(); IQ setIQ = carbonsEnabledIQ(new_state); connection.addPacketListener(new PacketListener() { @@ -148,6 +151,7 @@ public class CarbonManager { if (enabled_state == new_state) return true; + Connection connection = weakRefConnection.get(); IQ setIQ = carbonsEnabledIQ(new_state); PacketCollector collector = diff --git a/source/org/jivesoftware/smack/keepalive/KeepAliveManager.java b/source/org/jivesoftware/smack/keepalive/KeepAliveManager.java index 254a0419b..3560bc1c3 100644 --- a/source/org/jivesoftware/smack/keepalive/KeepAliveManager.java +++ b/source/org/jivesoftware/smack/keepalive/KeepAliveManager.java @@ -16,12 +16,12 @@ package org.jivesoftware.smack.keepalive; +import java.lang.ref.WeakReference; import java.util.Collections; -import java.util.Date; -import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.WeakHashMap; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; @@ -52,7 +52,7 @@ import org.jivesoftware.smack.ping.packet.Ping; * @author Florian Schmaus */ public class KeepAliveManager { - private static Map instances = new HashMap(); + private static Map instances = Collections.synchronizedMap(new WeakHashMap()); private static volatile ScheduledExecutorService periodicPingExecutorService; static { @@ -65,7 +65,7 @@ public class KeepAliveManager { } } - private Connection connection; + private WeakReference weakRefConnection; private long pingInterval = SmackConfiguration.getKeepAliveInterval(); private Set pingFailedListeners = Collections.synchronizedSet(new HashSet()); private volatile ScheduledFuture periodicPingTask; @@ -120,40 +120,21 @@ public class KeepAliveManager { } private KeepAliveManager(Connection connection) { - this.connection = connection; - init(); - handleConnect(); - } + weakRefConnection = new WeakReference(connection); - /* - * Call after every connection to add the packet listener. - */ - private void handleConnect() { - // Listen for all incoming packets and reset the scheduled ping whenever - // one arrives. - connection.addPacketListener(new PacketListener() { - - @Override - public void processPacket(Packet packet) { - // reschedule the ping based on this last server contact - lastSuccessfulContact = System.currentTimeMillis(); - schedulePingServerTask(); - } - }, null); - } - - private void init() { connection.addConnectionListener(new ConnectionListener() { @Override public void connectionClosed() { stopPingServerTask(); + Connection connection = weakRefConnection.get(); handleDisconnect(connection); } @Override public void connectionClosedOnError(Exception arg0) { stopPingServerTask(); + Connection connection = weakRefConnection.get(); handleDisconnect(connection); } @@ -174,6 +155,25 @@ public class KeepAliveManager { instances.put(connection, this); schedulePingServerTask(); + handleConnect(); + } + + /* + * Call after every connection to add the packet listener. + */ + private void handleConnect() { + Connection connection = weakRefConnection.get(); + // Listen for all incoming packets and reset the scheduled ping whenever + // one arrives. + connection.addPacketListener(new PacketListener() { + + @Override + public void processPacket(Packet packet) { + // reschedule the ping based on this last server contact + lastSuccessfulContact = System.currentTimeMillis(); + schedulePingServerTask(); + } + }, null); } /** @@ -276,6 +276,7 @@ public class KeepAliveManager { public void run() { Ping ping = new Ping(); PacketFilter responseFilter = new PacketIDFilter(ping.getPacketID()); + Connection connection = weakRefConnection.get(); final PacketCollector response = pingFailedListeners.isEmpty() ? null : connection.createPacketCollector(responseFilter); connection.sendPacket(ping); diff --git a/source/org/jivesoftware/smackx/MessageEventManager.java b/source/org/jivesoftware/smackx/MessageEventManager.java index 900914b3d..7ad7adfeb 100644 --- a/source/org/jivesoftware/smackx/MessageEventManager.java +++ b/source/org/jivesoftware/smackx/MessageEventManager.java @@ -20,7 +20,6 @@ package org.jivesoftware.smackx; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Iterator; diff --git a/source/org/jivesoftware/smackx/ping/PingManager.java b/source/org/jivesoftware/smackx/ping/PingManager.java index 068206698..4c34f9223 100644 --- a/source/org/jivesoftware/smackx/ping/PingManager.java +++ b/source/org/jivesoftware/smackx/ping/PingManager.java @@ -16,6 +16,7 @@ package org.jivesoftware.smackx.ping; +import java.lang.ref.WeakReference; import java.util.Collections; import java.util.Map; import java.util.WeakHashMap; @@ -65,7 +66,7 @@ public class PingManager { }); } - private Connection connection; + private WeakReference weakRefConnection; /** * Retrieves a {@link PingManager} for the specified {@link Connection}, creating one if it doesn't already @@ -84,8 +85,8 @@ public class PingManager { return pingManager; } - private PingManager(Connection con) { - this.connection = con; + private PingManager(Connection connection) { + weakRefConnection = new WeakReference(connection); ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); // The ServiceDiscoveryManager was not pre-initialized @@ -101,6 +102,7 @@ public class PingManager { * Sends a Pong for every Ping */ public void processPacket(Packet packet) { + Connection connection = weakRefConnection.get(); IQ pong = IQ.createResultIQ((Ping) packet); connection.sendPacket(pong); } @@ -121,7 +123,7 @@ public class PingManager { */ public boolean ping(String jid, long pingTimeout) { Ping ping = new Ping(jid); - + Connection connection = weakRefConnection.get(); try { SyncPacketSend.getReply(connection, ping); } @@ -151,6 +153,7 @@ public class PingManager { * @throws XMPPException An XMPP related error occurred during the request */ public boolean isPingSupported(String jid) throws XMPPException { + Connection connection = weakRefConnection.get(); DiscoverInfo result = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(jid); return result.containsFeature(Ping.NAMESPACE); } @@ -165,6 +168,7 @@ public class PingManager { * @return true if a reply was received from the server, false otherwise. */ public boolean pingMyServer() { + Connection connection = weakRefConnection.get(); return ping(connection.getServiceName()); } } diff --git a/source/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java b/source/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java index 0b4a6aae6..e628b20e5 100644 --- a/source/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java +++ b/source/org/jivesoftware/smackx/receipts/DeliveryReceiptManager.java @@ -16,6 +16,7 @@ package org.jivesoftware.smackx.receipts; +import java.lang.ref.WeakReference; import java.util.Collections; import java.util.HashSet; import java.util.Map; @@ -52,7 +53,7 @@ public class DeliveryReceiptManager implements PacketListener { }); } - private Connection connection; + private WeakReference weakRefConnection; private boolean auto_receipts_enabled = false; private Set receiptReceivedListeners = Collections .synchronizedSet(new HashSet()); @@ -60,7 +61,7 @@ public class DeliveryReceiptManager implements PacketListener { private DeliveryReceiptManager(Connection connection) { ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); sdm.addFeature(DeliveryReceipt.NAMESPACE); - this.connection = connection; + weakRefConnection = new WeakReference(connection); instances.put(connection, this); // register listener for delivery receipts and requests @@ -91,6 +92,7 @@ public class DeliveryReceiptManager implements PacketListener { * @return true if supported */ public boolean isSupported(String jid) { + Connection connection = weakRefConnection.get(); try { DiscoverInfo result = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(jid); @@ -119,6 +121,7 @@ public class DeliveryReceiptManager implements PacketListener { DeliveryReceiptRequest drr = (DeliveryReceiptRequest)packet.getExtension( DeliveryReceiptRequest.ELEMENT, DeliveryReceipt.NAMESPACE); if (drr != null) { + Connection connection = weakRefConnection.get(); Message ack = new Message(packet.getFrom(), Message.Type.normal); ack.addExtension(new DeliveryReceipt(packet.getPacketID())); connection.sendPacket(ack); From fc26b83efd36bc23d0896d40035695a2b0d463ad Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 8 Feb 2014 13:21:55 +0100 Subject: [PATCH 13/14] Use '-' as separator for $version.extra in build.xml --- build/build.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/build.xml b/build/build.xml index 152b03b9e..10ebb1f7a 100644 --- a/build/build.xml +++ b/build/build.xml @@ -57,8 +57,8 @@ - - + + From 0cec5713d1f93ee99a2226702d64a963e9981933 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 9 Feb 2014 14:09:55 +0100 Subject: [PATCH 14/14] Smack 3.4.1 --- build/build.xml | 2 +- build/resources/releasedocs/changelog.html | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/build/build.xml b/build/build.xml index 10ebb1f7a..973427380 100644 --- a/build/build.xml +++ b/build/build.xml @@ -28,7 +28,7 @@ - + diff --git a/build/resources/releasedocs/changelog.html b/build/resources/releasedocs/changelog.html index 96e5dd8c2..9e857550c 100644 --- a/build/resources/releasedocs/changelog.html +++ b/build/resources/releasedocs/changelog.html @@ -141,6 +141,14 @@ hr {
+

3.4.1 -- Feb 9, 2014

+ +

Bug

+
    +
  • [SMACK-540] - Memory leak in MultiUserChat +
  • +
+

3.4.0 -- Feb 2, 2014

Bug Fixes