made presences synchronized

This commit is contained in:
iNPUTmice 2014-11-13 14:44:19 +01:00
parent e6a4fa031b
commit 2db569b20f
1 changed files with 27 additions and 13 deletions

View File

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