From d53f0e94923e5f85ff329e9674fec1c9b5d55937 Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Fri, 16 Jul 2004 20:46:16 +0000 Subject: [PATCH] Cancel opened collectors. SMACK-145 git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2344 b35dd754-fafc-0310-a699-88a17e54d16e --- source/org/jivesoftware/smack/AccountManager.java | 8 ++++++++ source/org/jivesoftware/smack/Chat.java | 10 ++++++++++ source/org/jivesoftware/smack/GroupChat.java | 11 +++++++++++ .../org/jivesoftware/smackx/PrivateDataManager.java | 4 ++++ .../jivesoftware/smackx/ServiceDiscoveryManager.java | 6 ++++++ 5 files changed, 39 insertions(+) diff --git a/source/org/jivesoftware/smack/AccountManager.java b/source/org/jivesoftware/smack/AccountManager.java index 5efdd87c6..390632f49 100644 --- a/source/org/jivesoftware/smack/AccountManager.java +++ b/source/org/jivesoftware/smack/AccountManager.java @@ -208,6 +208,8 @@ public class AccountManager { PacketCollector collector = connection.createPacketCollector(filter); connection.sendPacket(reg); IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); + // Stop queuing results + collector.cancel(); if (result == null) { throw new XMPPException("No response from server."); } @@ -235,6 +237,8 @@ public class AccountManager { PacketCollector collector = connection.createPacketCollector(filter); connection.sendPacket(reg); IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); + // Stop queuing results + collector.cancel(); if (result == null) { throw new XMPPException("No response from server."); } @@ -267,6 +271,8 @@ public class AccountManager { PacketCollector collector = connection.createPacketCollector(filter); connection.sendPacket(reg); IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); + // Stop queuing results + collector.cancel(); if (result == null) { throw new XMPPException("No response from server."); } @@ -288,6 +294,8 @@ public class AccountManager { PacketCollector collector = connection.createPacketCollector(filter); connection.sendPacket(reg); IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); + // Stop queuing results + collector.cancel(); if (result == null) { throw new XMPPException("No response from server."); } diff --git a/source/org/jivesoftware/smack/Chat.java b/source/org/jivesoftware/smack/Chat.java index e795d14f9..d2b2f76cb 100644 --- a/source/org/jivesoftware/smack/Chat.java +++ b/source/org/jivesoftware/smack/Chat.java @@ -285,4 +285,14 @@ public class Chat { public void addMessageListener(PacketListener listener) { connection.addPacketListener(listener, messageFilter); } + + public void finalize() throws Throwable { + super.finalize(); + try { + if (messageCollector != null) { + messageCollector.cancel(); + } + } + catch (Exception e) {} + } } \ No newline at end of file diff --git a/source/org/jivesoftware/smack/GroupChat.java b/source/org/jivesoftware/smack/GroupChat.java index a66828202..13c4231f9 100644 --- a/source/org/jivesoftware/smack/GroupChat.java +++ b/source/org/jivesoftware/smack/GroupChat.java @@ -188,6 +188,7 @@ public class GroupChat { connection.sendPacket(joinPresence); // Wait up to a certain number of seconds for a reply. Presence presence = (Presence)response.nextResult(timeout); + response.cancel(); if (presence == null) { throw new XMPPException("No response from server."); } @@ -364,4 +365,14 @@ public class GroupChat { public void addMessageListener(PacketListener listener) { connection.addPacketListener(listener, messageFilter); } + + public void finalize() throws Throwable { + super.finalize(); + try { + if (messageCollector != null) { + messageCollector.cancel(); + } + } + catch (Exception e) {} + } } \ No newline at end of file diff --git a/source/org/jivesoftware/smackx/PrivateDataManager.java b/source/org/jivesoftware/smackx/PrivateDataManager.java index 1e75a8af9..5b5f84b83 100644 --- a/source/org/jivesoftware/smackx/PrivateDataManager.java +++ b/source/org/jivesoftware/smackx/PrivateDataManager.java @@ -220,6 +220,8 @@ public class PrivateDataManager { // Wait up to five seconds for a response from the server. IQ response = (IQ)collector.nextResult(5000); + // Stop queuing results + collector.cancel(); if (response == null) { throw new XMPPException("No response from the server."); } @@ -264,6 +266,8 @@ public class PrivateDataManager { // Wait up to five seconds for a response from the server. IQ response = (IQ)collector.nextResult(5000); + // Stop queuing results + collector.cancel(); if (response == null) { throw new XMPPException("No response from the server."); } diff --git a/source/org/jivesoftware/smackx/ServiceDiscoveryManager.java b/source/org/jivesoftware/smackx/ServiceDiscoveryManager.java index 949914e9d..3b69a7010 100644 --- a/source/org/jivesoftware/smackx/ServiceDiscoveryManager.java +++ b/source/org/jivesoftware/smackx/ServiceDiscoveryManager.java @@ -310,6 +310,8 @@ public class ServiceDiscoveryManager { // Wait up to 5 seconds for a result. IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); + // Stop queuing results + collector.cancel(); if (result == null) { throw new XMPPException("No response from the server."); } @@ -355,6 +357,8 @@ public class ServiceDiscoveryManager { // Wait up to 5 seconds for a result. IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); + // Stop queuing results + collector.cancel(); if (result == null) { throw new XMPPException("No response from the server."); } @@ -386,6 +390,8 @@ public class ServiceDiscoveryManager { // Wait up to 5 seconds for a result. IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); + // Stop queuing results + collector.cancel(); if (result == null) { throw new XMPPException("No response from the server."); }