Commit 8a9df3ff authored by Tom Evans's avatar Tom Evans Committed by tevans

OF-205: Prevent recursion when canceling subscriptions across cluster members

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches/pubsub_clustering@13278 b35dd754-fafc-0310-a699-88a17e54d16e
parent 7a18f0f0
...@@ -30,6 +30,7 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -30,6 +30,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.openfire.cluster.ClusterManager;
import org.jivesoftware.openfire.pubsub.cluster.CancelSubscriptionTask; import org.jivesoftware.openfire.pubsub.cluster.CancelSubscriptionTask;
import org.jivesoftware.openfire.pubsub.cluster.ModifySubscriptionTask; import org.jivesoftware.openfire.pubsub.cluster.ModifySubscriptionTask;
import org.jivesoftware.openfire.pubsub.cluster.NewSubscriptionTask; import org.jivesoftware.openfire.pubsub.cluster.NewSubscriptionTask;
...@@ -2097,8 +2098,9 @@ public abstract class Node { ...@@ -2097,8 +2098,9 @@ public abstract class Node {
* remove the existing affiliation too. * remove the existing affiliation too.
* *
* @param subscription the subscription to cancel. * @param subscription the subscription to cancel.
* @param sendToCluster True to forward cancel order to cluster peers
*/ */
public void cancelSubscription(NodeSubscription subscription) { public void cancelSubscription(NodeSubscription subscription, boolean sendToCluster) {
// Remove subscription from memory // Remove subscription from memory
subscriptionsByID.remove(subscription.getID()); subscriptionsByID.remove(subscription.getID());
subscriptionsByJID.remove(subscription.getJID().toString()); subscriptionsByJID.remove(subscription.getJID().toString());
...@@ -2113,7 +2115,9 @@ public abstract class Node { ...@@ -2113,7 +2115,9 @@ public abstract class Node {
// Remove the subscription from the database // Remove the subscription from the database
PubSubPersistenceManager.removeSubscription(subscription); PubSubPersistenceManager.removeSubscription(subscription);
} }
if (sendToCluster) {
CacheFactory.doClusterTask(new CancelSubscriptionTask(subscription)); CacheFactory.doClusterTask(new CancelSubscriptionTask(subscription));
}
// Check if we need to unsubscribe from the presence of the owner // Check if we need to unsubscribe from the presence of the owner
if (isPresenceBasedDelivery() && getSubscriptions(subscription.getOwner()).isEmpty()) { if (isPresenceBasedDelivery() && getSubscriptions(subscription.getOwner()).isEmpty()) {
...@@ -2121,6 +2125,17 @@ public abstract class Node { ...@@ -2121,6 +2125,17 @@ public abstract class Node {
} }
} }
/**
* Cancels an existing subscription to the node. If the subscriber does not have any
* other subscription to the node and his affiliation was of type <tt>none</tt> then
* remove the existing affiliation too.
*
* @param subscription the subscription to cancel.
*/
public void cancelSubscription(NodeSubscription subscription) {
cancelSubscription(subscription, ClusterManager.isClusteringEnabled());
}
/** /**
* Returns the {@link PublishedItem} whose ID matches the specified item ID or <tt>null</tt> * Returns the {@link PublishedItem} whose ID matches the specified item ID or <tt>null</tt>
* if none was found. Item ID may or may not exist and it depends on the node's configuration. * if none was found. Item ID may or may not exist and it depends on the node's configuration.
......
...@@ -32,6 +32,6 @@ public class CancelSubscriptionTask extends SubscriptionTask ...@@ -32,6 +32,6 @@ public class CancelSubscriptionTask extends SubscriptionTask
// This method will make a db call, but it will simply do nothing since // This method will make a db call, but it will simply do nothing since
// the record will already be deleted. // the record will already be deleted.
node.cancelSubscription(getSubscription()); node.cancelSubscription(getSubscription(), false);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment