mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 05:52:06 +01:00
Use WeakReference in MUC NodeInformationProvider
MultiUserChat's NodeInformationProvider must not hold a strong reference to the Connection instance. Fixes SMACK-540.
This commit is contained in:
parent
1df3841a41
commit
68a570b4fe
1 changed files with 5 additions and 0 deletions
|
@ -27,6 +27,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
@ -116,12 +117,16 @@ public class MultiUserChat {
|
||||||
// Chat protocol. This information will be used when another client tries to
|
// Chat protocol. This information will be used when another client tries to
|
||||||
// discover whether this client supports MUC or not.
|
// discover whether this client supports MUC or not.
|
||||||
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(discoNamespace);
|
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(discoNamespace);
|
||||||
|
|
||||||
// Set the NodeInformationProvider that will provide information about the
|
// Set the NodeInformationProvider that will provide information about the
|
||||||
// joined rooms whenever a disco request is received
|
// joined rooms whenever a disco request is received
|
||||||
|
final WeakReference<Connection> weakRefConnection = new WeakReference<Connection>(connection);
|
||||||
ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider(
|
ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider(
|
||||||
discoNode,
|
discoNode,
|
||||||
new NodeInformationProvider() {
|
new NodeInformationProvider() {
|
||||||
public List<DiscoverItems.Item> getNodeItems() {
|
public List<DiscoverItems.Item> getNodeItems() {
|
||||||
|
Connection connection = weakRefConnection.get();
|
||||||
|
if (connection == null) return new LinkedList<DiscoverItems.Item>();
|
||||||
List<DiscoverItems.Item> answer = new ArrayList<DiscoverItems.Item>();
|
List<DiscoverItems.Item> answer = new ArrayList<DiscoverItems.Item>();
|
||||||
Iterator<String> rooms=MultiUserChat.getJoinedRooms(connection);
|
Iterator<String> rooms=MultiUserChat.getJoinedRooms(connection);
|
||||||
while (rooms.hasNext()) {
|
while (rooms.hasNext()) {
|
||||||
|
|
Loading…
Reference in a new issue