Author: mjakl
Date: Sun Jul 5 17:02:56 2009
New Revision: 791276
URL: http://svn.apache.org/viewvc?rev=791276&view=rev
Log:
The in-memory storage provider did not differentiate between different nodes,
fixed.
Modified:
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/CollectionNode.java
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNode.java
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/CollectionnodeInMemoryStorageProvider.java
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeInMemoryStorageProvider.java
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeStorageProvider.java
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNodeTestCase.java
Modified:
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/CollectionNode.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/CollectionNode.java?rev=791276&r1=791275&r2=791276&view=diff
==============================================================================
---
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/CollectionNode.java
(original)
+++
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/CollectionNode.java
Sun Jul 5 17:02:56 2009
@@ -78,6 +78,7 @@
public LeafNode createNode(Entity serverJID, String nodeName, String
givenName) throws DuplicateNodeException {
LeafNode node = new LeafNode(serverJID, nodeName, givenName);
node.setPersistenceManager(leafNodeStorage);
+ node.initialize();
if(collectionNodeStorage.containsNode(nodeName)) {
throw new DuplicateNodeException(serverJID.getFullQualifiedName()
+ nodeName + " " + givenName + " already present");
Modified:
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNode.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNode.java?rev=791276&r1=791275&r2=791276&view=diff
==============================================================================
---
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNode.java
(original)
+++
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNode.java
Sun Jul 5 17:02:56 2009
@@ -220,4 +220,12 @@
public void acceptItems(ItemVisitor iv) {
storage.acceptForEachItem(name, iv);
}
+
+ /**
+ * Called after all information, including the persistencemanager for the
+ * node is set.
+ */
+ public void initialize() {
+ storage.initialize(this);
+ }
}
Modified:
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/CollectionnodeInMemoryStorageProvider.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/CollectionnodeInMemoryStorageProvider.java?rev=791276&r1=791275&r2=791276&view=diff
==============================================================================
---
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/CollectionnodeInMemoryStorageProvider.java
(original)
+++
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/CollectionnodeInMemoryStorageProvider.java
Sun Jul 5 17:02:56 2009
@@ -59,7 +59,7 @@
/**
* Add the given LeafNode with the given JID to the storage.
- * An existing ode with the same JID will be replaced.
+ * An existing node with the same JID will be replaced.
*/
public void storeNode(LeafNode node) {
nodes.put(node.getName(), node);
Modified:
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeInMemoryStorageProvider.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeInMemoryStorageProvider.java?rev=791276&r1=791275&r2=791276&view=diff
==============================================================================
---
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeInMemoryStorageProvider.java
(original)
+++
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeInMemoryStorageProvider.java
Sun Jul 5 17:02:56 2009
@@ -25,6 +25,7 @@
import org.apache.vysper.xmpp.addressing.Entity;
import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.ItemVisitor;
import
org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.SubscriberVisitor;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode;
import
org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.PayloadItem;
import org.apache.vysper.xmpp.xmlfragment.XMLElement;
@@ -36,23 +37,24 @@
*/
public class LeafNodeInMemoryStorageProvider implements
LeafNodeStorageProvider {
- // stores subscribers, access via subid
- protected Map<String, Entity> subscribers;
- // stores messages, access via itemid
- protected Map<String, PayloadItem> messages;
+ // stores subscribers to a node, access via subid
+ protected Map<String,Map<String, Entity>> nodeSubscribers;
+ // stores messages to a node, access via itemid
+ protected Map<String,Map<String, PayloadItem>> nodeMessages;
/**
* Initialize the storage maps.
*/
public LeafNodeInMemoryStorageProvider() {
- this.subscribers = new TreeMap<String, Entity>();
- this.messages = new TreeMap<String, PayloadItem>();
+ this.nodeSubscribers = new TreeMap<String, Map<String, Entity>>();
+ this.nodeMessages = new TreeMap<String, Map<String, PayloadItem>>();
}
/**
* Add a subscriber with given subID.
*/
public void addSubscriber(String nodeName, String subscriptionID, Entity
subscriber) {
+ Map<String, Entity> subscribers = nodeSubscribers.get(nodeName);
subscribers.put(subscriptionID, subscriber);
}
@@ -60,6 +62,7 @@
* Check if a subscriber is already known.
*/
public boolean containsSubscriber(String nodeName, Entity subscriber) {
+ Map<String, Entity> subscribers = nodeSubscribers.get(nodeName);
return subscribers.containsValue(subscriber);
}
@@ -67,6 +70,7 @@
* Check if a subscriptionId is already known.
*/
public boolean containsSubscriber(String nodeName, String subscriptionId) {
+ Map<String, Entity> subscribers = nodeSubscribers.get(nodeName);
return subscribers.containsKey(subscriptionId);
}
@@ -74,6 +78,7 @@
* Retrieve a subscriber via its subsriptionId.
*/
public Entity getSubscriber(String nodeName, String subscriptionId) {
+ Map<String, Entity> subscribers = nodeSubscribers.get(nodeName);
return subscribers.get(subscriptionId);
}
@@ -81,6 +86,7 @@
* Remove a subscriber via its subscriptionId.
*/
public boolean removeSubscription(String nodeName, String subscriptionId) {
+ Map<String, Entity> subscribers = nodeSubscribers.get(nodeName);
return subscribers.remove(subscriptionId) != null;
}
@@ -88,6 +94,7 @@
* Remove a subscriber via its JID. This removes all subscriptions of the
JID.
*/
public boolean removeSubscriber(String nodeName, Entity subscriber) {
+ Map<String, Entity> subscribers = nodeSubscribers.get(nodeName);
return subscribers.values().remove(subscriber);
}
@@ -95,6 +102,7 @@
* Count how often a given subscriber is subscribed.
*/
public int countSubscriptions(String nodeName, Entity subscriber) {
+ Map<String, Entity> subscribers = nodeSubscribers.get(nodeName);
int count = 0;
for(Entity sub : subscribers.values()) {
if(subscriber.equals(sub)) {
@@ -108,6 +116,7 @@
* Count how many subscriptions this node has.
*/
public int countSubscriptions(String nodeName) {
+ Map<String, Entity> subscribers = nodeSubscribers.get(nodeName);
return subscribers.size();
}
@@ -115,6 +124,7 @@
* Add a message to the storage.
*/
public void addMessage(Entity publisher, String nodeName, String itemID,
XMLElement payload) {
+ Map<String, PayloadItem> messages = nodeMessages.get(nodeName);
messages.put(itemID, new PayloadItem(publisher, payload, itemID));
}
@@ -122,6 +132,7 @@
* Accept method (see visitor pattern) to visit all subscribers of this
node.
*/
public void acceptForEachSubscriber(String nodeName, SubscriberVisitor
subscriberVisitor) {
+ Map<String, Entity> subscribers = nodeSubscribers.get(nodeName);
for(Entity sub : subscribers.values()) {
subscriberVisitor.visit(nodeName, sub);
}
@@ -135,8 +146,14 @@
}
public void acceptForEachItem(String nodeName, ItemVisitor iv) {
+ Map<String, PayloadItem> messages = nodeMessages.get(nodeName);
for(String itemID : messages.keySet()) {
iv.visit(itemID, messages.get(itemID));
}
}
+
+ public void initialize(LeafNode leafNode) {
+ nodeMessages.put(leafNode.getName(), new TreeMap<String,
PayloadItem>());
+ nodeSubscribers.put(leafNode.getName(), new TreeMap<String, Entity>());
+ }
}
Modified:
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeStorageProvider.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeStorageProvider.java?rev=791276&r1=791275&r2=791276&view=diff
==============================================================================
---
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeStorageProvider.java
(original)
+++
mina/sandbox/vysper/trunk/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeStorageProvider.java
Sun Jul 5 17:02:56 2009
@@ -24,6 +24,7 @@
import org.apache.vysper.xmpp.addressing.Entity;
import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.ItemVisitor;
import
org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.SubscriberVisitor;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode;
import org.apache.vysper.xmpp.xmlfragment.XMLElement;
/**
@@ -122,8 +123,14 @@
/**
* Visits each item ever published to the node.
*
- * @param iv the Visidor.
+ * @param iv the Visitor.
*/
public void acceptForEachItem(String nodeName, ItemVisitor iv);
+ /**
+ * When a new LeafNode is created, initialize will be called with it as a
parameter.
+ * @param leafNode
+ */
+ public void initialize(LeafNode leafNode);
+
}
Modified:
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNodeTestCase.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNodeTestCase.java?rev=791276&r1=791275&r2=791276&view=diff
==============================================================================
---
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNodeTestCase.java
(original)
+++
mina/sandbox/vysper/trunk/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNodeTestCase.java
Sun Jul 5 17:02:56 2009
@@ -37,6 +37,7 @@
super.setUp();
Entity nodeJID = new EntityImpl(null, "pubsub.vysper.org", null);
node = new LeafNode(nodeJID, "node", "Some test node");
+ node.initialize();
}
public void testSubscribe() throws Exception {