aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-11-13 14:44:19 +0100
committeriNPUTmice <daniel@gultsch.de>2014-11-13 14:44:41 +0100
commit17c2ed411d747f3206e0e4ea4cd7c4e8331f7d11 (patch)
treebcb6fabcb8b4c439b92a607f10f4c49795014571 /src/main/java/eu/siacs/conversations
parent77ba68d61f11235f7cbe426a1c26a7f79be90aa1 (diff)
made presences synchronized
Diffstat (limited to 'src/main/java/eu/siacs/conversations')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Presences.java40
1 files changed, 27 insertions, 13 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Presences.java b/src/main/java/eu/siacs/conversations/entities/Presences.java
index b58998473..bccf31170 100644
--- a/src/main/java/eu/siacs/conversations/entities/Presences.java
+++ b/src/main/java/eu/siacs/conversations/entities/Presences.java
@@ -22,24 +22,32 @@ public class Presences {
}
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) {
- this.presences.remove(resource);
+ synchronized (this.presences) {
+ this.presences.remove(resource);
+ }
}
public void clearPresences() {
- this.presences.clear();
+ synchronized (this.presences) {
+ this.presences.clear();
+ }
}
public int getMostAvailableStatus() {
int status = OFFLINE;
- Iterator<Entry<String, Integer>> it = presences.entrySet().iterator();
- while (it.hasNext()) {
- Entry<String, Integer> entry = it.next();
- if (entry.getValue() < status)
- status = entry.getValue();
+ synchronized (this.presences) {
+ Iterator<Entry<String, Integer>> it = presences.entrySet().iterator();
+ while (it.hasNext()) {
+ Entry<String, Integer> entry = it.next();
+ if (entry.getValue() < status)
+ status = entry.getValue();
+ }
}
return status;
}
@@ -61,16 +69,22 @@ public class Presences {
}
public int size() {
- return presences.size();
+ synchronized (this.presences) {
+ return presences.size();
+ }
}
public String[] asStringArray() {
- final String[] presencesArray = new String[presences.size()];
- presences.keySet().toArray(presencesArray);
- return presencesArray;
+ synchronized (this.presences) {
+ final String[] presencesArray = new String[presences.size()];
+ presences.keySet().toArray(presencesArray);
+ return presencesArray;
+ }
}
public boolean has(String presence) {
- return presences.containsKey(presence);
+ synchronized (this.presences) {
+ return presences.containsKey(presence);
+ }
}
}