made presences synchronized

This commit is contained in:
iNPUTmice 2014-11-13 14:44:19 +01:00
parent e6a4fa031b
commit 2db569b20f

View File

@ -22,25 +22,33 @@ public class Presences {
} }
public void updatePresence(String resource, int status) { public void updatePresence(String resource, int status) {
synchronized (this.presences) {
this.presences.put(resource, status); this.presences.put(resource, status);
} }
}
public void removePresence(String resource) { public void removePresence(String resource) {
synchronized (this.presences) {
this.presences.remove(resource); this.presences.remove(resource);
} }
}
public void clearPresences() { public void clearPresences() {
synchronized (this.presences) {
this.presences.clear(); this.presences.clear();
} }
}
public int getMostAvailableStatus() { public int getMostAvailableStatus() {
int status = OFFLINE; int status = OFFLINE;
synchronized (this.presences) {
Iterator<Entry<String, Integer>> it = presences.entrySet().iterator(); Iterator<Entry<String, Integer>> it = presences.entrySet().iterator();
while (it.hasNext()) { while (it.hasNext()) {
Entry<String, Integer> entry = it.next(); Entry<String, Integer> entry = it.next();
if (entry.getValue() < status) if (entry.getValue() < status)
status = entry.getValue(); status = entry.getValue();
} }
}
return status; return status;
} }
@ -61,16 +69,22 @@ public class Presences {
} }
public int size() { public int size() {
synchronized (this.presences) {
return presences.size(); return presences.size();
} }
}
public String[] asStringArray() { public String[] asStringArray() {
synchronized (this.presences) {
final String[] presencesArray = new String[presences.size()]; final String[] presencesArray = new String[presences.size()];
presences.keySet().toArray(presencesArray); presences.keySet().toArray(presencesArray);
return presencesArray; return presencesArray;
} }
}
public boolean has(String presence) { public boolean has(String presence) {
synchronized (this.presences) {
return presences.containsKey(presence); return presences.containsKey(presence);
} }
}
} }