Changeset 128
- Timestamp:
- 11/20/08 12:49:27 (7 weeks ago)
- Location:
- trunk/src/main/java/tigase/pubsub/repository
- Files:
-
- 4 modified
-
NodeAffiliations.java (modified) (4 diffs)
-
NodeSubscriptions.java (modified) (1 diff)
-
cached/CachedPubSubRepository.java (modified) (2 diffs)
-
cached/NodeAffiliations.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/main/java/tigase/pubsub/repository/NodeAffiliations.java
r127 r128 24 24 protected final Map<String, UsersAffiliation> affs = new HashMap<String, UsersAffiliation>(); 25 25 26 pr otectedboolean changed = false;26 private boolean changed = false; 27 27 28 28 protected NodeAffiliations() { … … 40 40 public void changeAffiliation(String jid, Affiliation affiliation) { 41 41 final String bareJid = JIDUtils.getNodeID(jid); 42 UsersAffiliation a = this. affs.get(bareJid);42 UsersAffiliation a = this.get(bareJid); 43 43 if (a != null) { 44 44 a.setAffiliation(affiliation); … … 61 61 } 62 62 63 protected UsersAffiliation get(final String jid) { 64 final String bareJid = JIDUtils.getNodeID(jid); 65 UsersAffiliation s = this.affs.get(bareJid); 66 return s; 67 } 68 63 69 @Override 64 70 public UsersAffiliation[] getAffiliations() { … … 73 79 public UsersAffiliation getSubscriberAffiliation(String jid) { 74 80 final String bareJid = JIDUtils.getNodeID(jid); 75 UsersAffiliation a = this. affs.get(bareJid);81 UsersAffiliation a = this.get(bareJid); 76 82 if (a == null) { 77 83 a = new UsersAffiliation(bareJid, Affiliation.none); -
trunk/src/main/java/tigase/pubsub/repository/NodeSubscriptions.java
r127 r128 60 60 protected UsersSubscription get(final String jid) { 61 61 final String bareJid = JIDUtils.getNodeID(jid); 62 UsersSubscription s = get(bareJid);62 UsersSubscription s = this.subs.get(bareJid); 63 63 return s; 64 64 } -
trunk/src/main/java/tigase/pubsub/repository/cached/CachedPubSubRepository.java
r127 r128 121 121 public IAffiliations getNodeAffiliations(String nodeName) throws RepositoryException { 122 122 Node node = getNode(nodeName); 123 try { 124 return node == null ? null : node.getNodeAffiliations().clone(); 125 } catch (CloneNotSupportedException e) { 126 e.printStackTrace(); 127 return null; 128 } 123 return node == null ? null : node.getNodeAffiliations(); 129 124 } 130 125 … … 196 191 197 192 @Override 198 public void update(String nodeName, IAffiliations affiliations) throws RepositoryException { 199 Node node = getNode(nodeName); 200 if (node != null) { 201 node.getNodeAffiliations().replaceBy(affiliations); 202 ((NodeAffiliations) affiliations).resetChangedFlag(); 203 node.setNodeAffiliationsChangeTimestamp(); 204 synchronized (mutex) { 205 this.nodesToSave.add(node); 206 } 193 public void update(String nodeName, IAffiliations nodeAffiliations) throws RepositoryException { 194 if (nodeAffiliations instanceof NodeAffiliations) { 195 NodeAffiliations affiliations = (NodeAffiliations) nodeAffiliations; 196 197 Node node = getNode(nodeName); 198 if (node != null) { 199 if (node.getNodeAffiliations() != nodeAffiliations) { 200 throw new RuntimeException("INCORRECT"); 201 } 202 affiliations.merge(); 203 node.setNodeAffiliationsChangeTimestamp(); 204 synchronized (mutex) { 205 this.nodesToSave.add(node); 206 } 207 } 208 } else { 209 throw new RuntimeException("Wrong class"); 207 210 } 208 211 } -
trunk/src/main/java/tigase/pubsub/repository/cached/NodeAffiliations.java
r127 r128 2 2 3 3 import java.util.HashMap; 4 import java.util.HashSet; 4 5 import java.util.Map; 6 import java.util.Set; 5 7 6 8 import tigase.pubsub.Affiliation; 7 import tigase.pubsub.repository.IAffiliations;8 9 import tigase.pubsub.repository.stateless.UsersAffiliation; 10 import tigase.util.JIDUtils; 9 11 10 12 class NodeAffiliations extends tigase.pubsub.repository.NodeAffiliations { … … 21 23 @Override 22 24 public void addAffiliation(String jid, Affiliation affiliation) { 23 // TODO Auto-generated method stub 24 super.addAffiliation(jid, affiliation); 25 final String bareJid = JIDUtils.getNodeID(jid); 26 UsersAffiliation a = new UsersAffiliation(bareJid, affiliation); 27 changedAffs.put(bareJid, a); 25 28 } 26 29 27 30 @Override 28 31 public void changeAffiliation(String jid, Affiliation affiliation) { 29 // TODO Auto-generated method stub 30 super.changeAffiliation(jid, affiliation); 32 final String bareJid = JIDUtils.getNodeID(jid); 33 UsersAffiliation a = this.get(bareJid); 34 if (a != null) { 35 a.setAffiliation(affiliation); 36 changedAffs.put(bareJid, a); 37 } else { 38 a = new UsersAffiliation(bareJid, affiliation); 39 changedAffs.put(bareJid, a); 40 } 31 41 } 32 42 … … 37 47 clone.affs.put(a.getJid(), a.clone()); 38 48 } 39 clone.changed = changed; 49 for (UsersAffiliation a : this.changedAffs.values()) { 50 clone.changedAffs.put(a.getJid(), a.clone()); 51 } 40 52 return clone; 41 53 } 42 54 43 55 @Override 44 public UsersAffiliation[] getAffiliations() { 45 // TODO Auto-generated method stub 46 return super.getAffiliations(); 56 protected UsersAffiliation get(String bareJid) { 57 UsersAffiliation us = changedAffs.get(bareJid); 58 if (us == null) { 59 us = affs.get(bareJid); 60 if (us != null) 61 try { 62 return us.clone(); 63 } catch (Exception e) { 64 e.printStackTrace(); 65 return null; 66 } 67 } 68 return us; 47 69 } 48 70 49 71 @Override 50 public Map<String, UsersAffiliation> getAffiliationsMap() { 51 // TODO Auto-generated method stub 52 return super.getAffiliationsMap(); 53 } 54 55 @Override 56 public UsersAffiliation getSubscriberAffiliation(String jid) { 57 // TODO Auto-generated method stub 58 return super.getSubscriberAffiliation(jid); 72 public UsersAffiliation[] getAffiliations() { 73 final Set<UsersAffiliation> result = new HashSet<UsersAffiliation>(); 74 result.addAll(this.affs.values()); 75 result.addAll(this.changedAffs.values()); 76 return result.toArray(new UsersAffiliation[] {}); 59 77 } 60 78 61 79 @Override 62 80 public boolean isChanged() { 63 // TODO Auto-generated method stub 64 return super.isChanged(); 81 return changedAffs.size() > 0; 65 82 } 66 83 67 @Override 68 public void parse(String data) { 69 // TODO Auto-generated method stub 70 super.parse(data); 71 } 72 73 @Override 74 public void replaceBy(IAffiliations nodeAffiliations) { 75 // TODO Auto-generated method stub 76 super.replaceBy(nodeAffiliations); 84 public void merge() { 85 affs.putAll(changedAffs); 86 changedAffs.clear(); 77 87 } 78 88 79 89 @Override 80 90 public void resetChangedFlag() { 81 // TODO Auto-generated method stub 82 super.resetChangedFlag(); 83 } 84 85 @Override 86 public String serialize() { 87 // TODO Auto-generated method stub 88 return super.serialize(); 91 changedAffs.clear(); 89 92 } 90 93
