mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-25 21:42:07 +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,12 +429,8 @@ 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) {
|
|
||||||
if (!queueListeners.contains(queueListener)) {
|
|
||||||
queueListeners.add(queueListener);
|
queueListeners.add(queueListener);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a queue listener.
|
* Removes a queue listener.
|
||||||
|
@ -442,10 +438,8 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an invitation listener that will be notified of groupchat invitations
|
* Adds an invitation listener that will be notified of groupchat invitations
|
||||||
|
@ -454,12 +448,8 @@ 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) {
|
|
||||||
if (!invitationListeners.contains(invitationListener)) {
|
|
||||||
invitationListeners.add(invitationListener);
|
invitationListeners.add(invitationListener);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes an invitation listener.
|
* Removes an invitation listener.
|
||||||
|
@ -467,55 +457,38 @@ 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();) {
|
|
||||||
WorkgroupInvitationListener listener = i.next();
|
|
||||||
listener.invitationReceived(invitation);
|
listener.invitationReceived(invitation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void fireQueueJoinedEvent() {
|
private void fireQueueJoinedEvent() {
|
||||||
synchronized (queueListeners) {
|
for (QueueListener listener : queueListeners){
|
||||||
for (Iterator<QueueListener> i = queueListeners.iterator(); i.hasNext();) {
|
|
||||||
QueueListener listener = i.next();
|
|
||||||
listener.joinedQueue();
|
listener.joinedQueue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void fireQueueDepartedEvent() {
|
private void fireQueueDepartedEvent() {
|
||||||
synchronized (queueListeners) {
|
for (QueueListener listener : queueListeners) {
|
||||||
for (Iterator<QueueListener> i = queueListeners.iterator(); i.hasNext();) {
|
|
||||||
QueueListener listener = i.next();
|
|
||||||
listener.departedQueue();
|
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();) {
|
|
||||||
QueueListener listener = i.next();
|
|
||||||
listener.queuePositionUpdated(currentPosition);
|
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();) {
|
|
||||||
QueueListener listener = i.next();
|
|
||||||
listener.queueWaitTimeUpdated(secondsRemaining);
|
listener.queueWaitTimeUpdated(secondsRemaining);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// PacketListener Implementation.
|
// PacketListener Implementation.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue