Skip to content

Commit

Permalink
Fixing possibility of adding duplicate entries to list of AsteriskQue…
Browse files Browse the repository at this point in the history
…ueEntryImpl.
  • Loading branch information
bbankowski committed Jul 16, 2020
1 parent 2d33283 commit 87595c2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 39 deletions.
31 changes: 19 additions & 12 deletions src/main/java/org/asteriskjava/live/internal/AsteriskQueueImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,27 +354,34 @@ void createNewEntry(AsteriskChannelImpl channel, int reportedPosition, Date date
{
AsteriskQueueEntryImpl qe = new AsteriskQueueEntryImpl(server, this, channel, reportedPosition, dateReceived);

long delay = serviceLevel * 1000L;
if (delay > 0)
{
ServiceLevelTimerTask timerTask = new ServiceLevelTimerTask(qe);
timer.schedule(timerTask, delay);
synchronized (serviceLevelTimerTasks)
{
serviceLevelTimerTasks.put(qe, timerTask);
}
}

synchronized (entries)
{
entries.add(qe); // at the end of the list
if (getEntry(channel.getName()) != null)
{
logger.debug("Ignored duplicate queue entry during population in queue " + name + " for channel "
+ channel.getName());
return;
}

entries.add(qe); // at the end of the list

// Keep the lock !
// This will fire PCE on the newly created queue entry
// but hopefully this one has no listeners yet
shift();
}

long delay = serviceLevel * 1000L;
if (delay > 0)
{
ServiceLevelTimerTask timerTask = new ServiceLevelTimerTask(qe);
timer.schedule(timerTask, delay);
synchronized (serviceLevelTimerTasks)
{
serviceLevelTimerTasks.put(qe, timerTask);
}
}

// Set the channel property ony here as queue entries and channels
// maintain a reciprocal reference.
// That way property change on channel and new entry event on queue will be
Expand Down
40 changes: 13 additions & 27 deletions src/main/java/org/asteriskjava/live/internal/QueueManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

/**
* Manages queue events on behalf of an AsteriskServer.
*
*
* @author srt
* @version $Id$
*/
Expand Down Expand Up @@ -117,7 +117,7 @@ else if (event instanceof QueueEntryEvent)

/**
* Method to ask for a Queue data update
*
*
* @author Octavio Luna
* @param queue
* @throws ManagerCommunicationException
Expand Down Expand Up @@ -182,7 +182,7 @@ void disconnected()

/**
* Gets (a copy of) the list of the queues.
*
*
* @return a copy of the list of the queues.
*/
Collection<AsteriskQueue> getQueues()
Expand Down Expand Up @@ -227,7 +227,7 @@ public List<AsteriskQueue> getQueuesUpdatedAfter(Date date)

/**
* Adds a queue to the internal map, keyed by name.
*
*
* @param queue the AsteriskQueueImpl to be added
*/
private void addQueue(AsteriskQueueImpl queue)
Expand All @@ -240,7 +240,7 @@ private void addQueue(AsteriskQueueImpl queue)

/**
* Called during initialization to populate the list of queues.
*
*
* @param event the event received
*/
private void handleQueueParamsEvent(QueueParamsEvent event)
Expand Down Expand Up @@ -294,7 +294,7 @@ private void handleQueueParamsEvent(QueueParamsEvent event)

/**
* Called during initialization to populate the members of the queues.
*
*
* @param event the QueueMemberEvent received
*/
private void handleQueueMemberEvent(QueueMemberEvent event)
Expand Down Expand Up @@ -335,7 +335,7 @@ private void manageQueueMemberChange(AsteriskQueueImpl queue, AsteriskQueueMembe
/**
* Called during initialization to populate entries of the queues. Currently
* does the same as handleJoinEvent()
*
*
* @param event - the QueueEntryEvent received
*/
private void handleQueueEntryEvent(QueueEntryEvent event)
Expand All @@ -354,13 +354,6 @@ private void handleQueueEntryEvent(QueueEntryEvent event)
return;
}

if (queue.getEntry(event.getChannel()) != null)
{
logger.debug("Ignored duplicate queue entry during population in queue " + event.getQueue() + " for channel "
+ event.getChannel());
return;
}

// Asterisk gives us an initial position but doesn't tell us when he
// shifts the others
// We won't use this data for ordering until there is a appropriate
Expand All @@ -375,7 +368,7 @@ private void handleQueueEntryEvent(QueueEntryEvent event)

/**
* Called from AsteriskServerImpl whenever a new entry appears in a queue.
*
*
* @param event the JoinEvent received
*/
void handleJoinEvent(JoinEvent event)
Expand All @@ -394,13 +387,6 @@ void handleJoinEvent(JoinEvent event)
return;
}

if (queue.getEntry(event.getChannel()) != null)
{
logger.error(
"Ignored duplicate queue entry in queue " + event.getQueue() + " for channel " + event.getChannel());
return;
}

// Asterisk gives us an initial position but doesn't tell us when he
// shifts the others
// We won't use this data for ordering until there is a appropriate
Expand All @@ -415,7 +401,7 @@ void handleJoinEvent(JoinEvent event)

/**
* Called from AsteriskServerImpl whenever an enty leaves a queue.
*
*
* @param event - the LeaveEvent received
*/
void handleLeaveEvent(LeaveEvent event)
Expand Down Expand Up @@ -448,7 +434,7 @@ void handleLeaveEvent(LeaveEvent event)
/**
* Challange a QueueMemberStatusEvent. Called from AsteriskServerImpl
* whenever a member state changes.
*
*
* @param event that was triggered by Asterisk server.
*/
void handleQueueMemberStatusEvent(QueueMemberStatusEvent event)
Expand Down Expand Up @@ -514,7 +500,7 @@ void handleQueueMemberPenaltyEvent(QueueMemberPenaltyEvent event)

/**
* Retrieves a queue by its name.
*
*
* @param queueName name of the queue.
* @return the requested queue or <code>null</code> if there is no queue
* with the given name.
Expand Down Expand Up @@ -562,7 +548,7 @@ private void refreshQueuesIfForced()

/**
* Challange a QueueMemberAddedEvent.
*
*
* @param event - the generated QueueMemberAddedEvent.
*/
public void handleQueueMemberAddedEvent(QueueMemberAddedEvent event)
Expand All @@ -587,7 +573,7 @@ public void handleQueueMemberAddedEvent(QueueMemberAddedEvent event)

/**
* Challange a QueueMemberRemovedEvent.
*
*
* @param event - the generated QueueMemberRemovedEvent.
*/
public void handleQueueMemberRemovedEvent(QueueMemberRemovedEvent event)
Expand Down

0 comments on commit 87595c2

Please sign in to comment.