mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 22:32:06 +01:00
Fixed Exception in packet listener Workgroup
Prevent java.util.ConcurrentModificationException by using a CopyOnWriteArraySet.
This commit is contained in:
parent
6d7f3904d9
commit
79fe40bf97
1 changed files with 19 additions and 46 deletions
|
@ -16,7 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.workgroup.user;
|
package org.jivesoftware.smackx.workgroup.user;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -76,8 +76,8 @@ public class Workgroup {
|
||||||
private String workgroupJID;
|
private String workgroupJID;
|
||||||
private XMPPConnection connection;
|
private XMPPConnection connection;
|
||||||
private boolean inQueue;
|
private boolean inQueue;
|
||||||
private List<WorkgroupInvitationListener> invitationListeners;
|
private CopyOnWriteArraySet<WorkgroupInvitationListener> invitationListeners;
|
||||||
private List<QueueListener> queueListeners;
|
private CopyOnWriteArraySet<QueueListener> queueListeners;
|
||||||
|
|
||||||
private int queuePosition = -1;
|
private int queuePosition = -1;
|
||||||
private int queueRemainingTime = -1;
|
private int queueRemainingTime = -1;
|
||||||
|
@ -101,8 +101,8 @@ public class Workgroup {
|
||||||
this.workgroupJID = workgroupJID;
|
this.workgroupJID = workgroupJID;
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
inQueue = false;
|
inQueue = false;
|
||||||
invitationListeners = new ArrayList<WorkgroupInvitationListener>();
|
invitationListeners = new CopyOnWriteArraySet<>();
|
||||||
queueListeners = new ArrayList<QueueListener>();
|
queueListeners = new CopyOnWriteArraySet<>();
|
||||||
|
|
||||||
// Register as a queue listener for internal usage by this instance.
|
// Register as a queue listener for internal usage by this instance.
|
||||||
addQueueListener(new QueueListener() {
|
addQueueListener(new QueueListener() {
|
||||||
|
@ -429,11 +429,7 @@ public class Workgroup {
|
||||||
* @param queueListener the queue listener.
|
* @param queueListener the queue listener.
|
||||||
*/
|
*/
|
||||||
public void addQueueListener(QueueListener queueListener) {
|
public void addQueueListener(QueueListener queueListener) {
|
||||||
synchronized (queueListeners) {
|
queueListeners.add(queueListener);
|
||||||
if (!queueListeners.contains(queueListener)) {
|
|
||||||
queueListeners.add(queueListener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -442,9 +438,7 @@ public class Workgroup {
|
||||||
* @param queueListener the queue listener.
|
* @param queueListener the queue listener.
|
||||||
*/
|
*/
|
||||||
public void removeQueueListener(QueueListener queueListener) {
|
public void removeQueueListener(QueueListener queueListener) {
|
||||||
synchronized (queueListeners) {
|
queueListeners.remove(queueListener);
|
||||||
queueListeners.remove(queueListener);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -454,11 +448,7 @@ public class Workgroup {
|
||||||
* @param invitationListener the invitation listener.
|
* @param invitationListener the invitation listener.
|
||||||
*/
|
*/
|
||||||
public void addInvitationListener(WorkgroupInvitationListener invitationListener) {
|
public void addInvitationListener(WorkgroupInvitationListener invitationListener) {
|
||||||
synchronized (invitationListeners) {
|
invitationListeners.add(invitationListener);
|
||||||
if (!invitationListeners.contains(invitationListener)) {
|
|
||||||
invitationListeners.add(invitationListener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -467,53 +457,36 @@ public class Workgroup {
|
||||||
* @param invitationListener the invitation listener.
|
* @param invitationListener the invitation listener.
|
||||||
*/
|
*/
|
||||||
public void removeQueueListener(WorkgroupInvitationListener invitationListener) {
|
public void removeQueueListener(WorkgroupInvitationListener invitationListener) {
|
||||||
synchronized (invitationListeners) {
|
invitationListeners.remove(invitationListener);
|
||||||
invitationListeners.remove(invitationListener);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireInvitationEvent(WorkgroupInvitation invitation) {
|
private void fireInvitationEvent(WorkgroupInvitation invitation) {
|
||||||
synchronized (invitationListeners) {
|
for (WorkgroupInvitationListener listener : invitationListeners ){
|
||||||
for (Iterator<WorkgroupInvitationListener> i = invitationListeners.iterator(); i.hasNext();) {
|
listener.invitationReceived(invitation);
|
||||||
WorkgroupInvitationListener listener = i.next();
|
|
||||||
listener.invitationReceived(invitation);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireQueueJoinedEvent() {
|
private void fireQueueJoinedEvent() {
|
||||||
synchronized (queueListeners) {
|
for (QueueListener listener : queueListeners){
|
||||||
for (Iterator<QueueListener> i = queueListeners.iterator(); i.hasNext();) {
|
listener.joinedQueue();
|
||||||
QueueListener listener = i.next();
|
|
||||||
listener.joinedQueue();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireQueueDepartedEvent() {
|
private void fireQueueDepartedEvent() {
|
||||||
synchronized (queueListeners) {
|
for (QueueListener listener : queueListeners) {
|
||||||
for (Iterator<QueueListener> i = queueListeners.iterator(); i.hasNext();) {
|
listener.departedQueue();
|
||||||
QueueListener listener = i.next();
|
|
||||||
listener.departedQueue();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireQueuePositionEvent(int currentPosition) {
|
private void fireQueuePositionEvent(int currentPosition) {
|
||||||
synchronized (queueListeners) {
|
for (QueueListener listener : queueListeners) {
|
||||||
for (Iterator<QueueListener> i = queueListeners.iterator(); i.hasNext();) {
|
listener.queuePositionUpdated(currentPosition);
|
||||||
QueueListener listener = i.next();
|
|
||||||
listener.queuePositionUpdated(currentPosition);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireQueueTimeEvent(int secondsRemaining) {
|
private void fireQueueTimeEvent(int secondsRemaining) {
|
||||||
synchronized (queueListeners) {
|
for (QueueListener listener : queueListeners) {
|
||||||
for (Iterator<QueueListener> i = queueListeners.iterator(); i.hasNext();) {
|
listener.queueWaitTimeUpdated(secondsRemaining);
|
||||||
QueueListener listener = i.next();
|
|
||||||
listener.queueWaitTimeUpdated(secondsRemaining);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue