コード例 #1
0
  /**
   * Called from AsteriskServerImpl whenever a new entry appears in a queue.
   *
   * @param event the JoinEvent received
   */
  void handleJoinEvent(JoinEvent event) {
    final AsteriskQueueImpl queue = getInternalQueueByName(event.getQueue());
    final AsteriskChannelImpl channel = channelManager.getChannelImplByName(event.getChannel());

    if (queue == null) {
      logger.error("Ignored JoinEvent for unknown queue " + event.getQueue());
      return;
    }
    if (channel == null) {
      logger.error("Ignored JoinEvent for unknown channel " + event.getChannel());
      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 event in AMI.
    // (and refreshing the whole queue is too intensive and suffers incoherencies
    // due to asynchronous shift that leaves holes if requested too fast)
    int reportedPosition = event.getPosition();

    queue.createNewEntry(channel, reportedPosition, event.getDateReceived());
  }
コード例 #2
0
  /**
   * Called from AsteriskServerImpl whenever an enty leaves a queue.
   *
   * @param event - the LeaveEvent received
   */
  void handleLeaveEvent(LeaveEvent event) {
    final AsteriskQueueImpl queue = getInternalQueueByName(event.getQueue());
    final AsteriskChannelImpl channel = channelManager.getChannelImplByName(event.getChannel());

    if (queue == null) {
      logger.error("Ignored LeaveEvent for unknown queue " + event.getQueue());
      return;
    }
    if (channel == null) {
      logger.error("Ignored LeaveEvent for unknown channel " + event.getChannel());
      return;
    }

    final AsteriskQueueEntryImpl existingQueueEntry = queue.getEntry(event.getChannel());
    if (existingQueueEntry == null) {
      logger.error(
          "Ignored leave event for non existing queue entry in queue "
              + event.getQueue()
              + " for channel "
              + event.getChannel());
      return;
    }

    queue.removeEntry(existingQueueEntry, event.getDateReceived());
  }
コード例 #3
0
  /**
   * Called during initialization to populate the members of the queues.
   *
   * @param event the QueueMemberEvent received
   */
  private void handleQueueMemberEvent(QueueMemberEvent event) {
    final AsteriskQueueImpl queue = getInternalQueueByName(event.getQueue());
    if (queue == null) {
      logger.error("Ignored QueueEntryEvent for unknown queue " + event.getQueue());
      return;
    }

    AsteriskQueueMemberImpl member = queue.getMember(event.getLocation());
    if (member == null) {
      member =
          new AsteriskQueueMemberImpl(
              server,
              queue,
              event.getLocation(),
              QueueMemberState.valueOf(event.getStatus()),
              event.getPaused(),
              event.getPenalty(),
              event.getMembership(),
              event.getCallsTaken(),
              event.getLastCall());

      queue.addMember(member);
    } else {
      if (member.stateChanged(QueueMemberState.valueOf(event.getStatus()))
          | member.pausedChanged(event.getPaused())
          | member.penaltyChanged(event.getPenalty())
          | member.callsTakenChanged(event.getCallsTaken())
          | member.lastCallChanged(event.getLastCall())) {
        queue.stampLastUpdate();
      }
    }
  }
コード例 #4
0
 void disconnected() {
   synchronized (queuesLRU) {
     for (AsteriskQueueImpl queue : queuesLRU.values()) {
       queue.cancelServiceLevelTimer();
     }
     queuesLRU.clear();
   }
 }
コード例 #5
0
  void handleQueueMemberPenaltyEvent(QueueMemberPenaltyEvent event) {
    AsteriskQueueImpl queue = getInternalQueueByName(event.getQueue());

    if (queue == null) {
      logger.error("Ignored QueueMemberStatusEvent for unknown queue " + event.getQueue());
      return;
    }

    AsteriskQueueMemberImpl member = queue.getMemberByLocation(event.getLocation());
    if (member == null) {
      logger.error("Ignored QueueMemberStatusEvent for unknown member " + event.getLocation());
      return;
    }

    member.penaltyChanged(event.getPenalty());
  }
コード例 #6
0
  /**
   * Challange a QueueMemberRemovedEvent.
   *
   * @param event - the generated QueueMemberRemovedEvent.
   */
  public void handleQueueMemberRemovedEvent(QueueMemberRemovedEvent event) {
    final AsteriskQueueImpl queue = getInternalQueueByName(event.getQueue());
    if (queue == null) {
      logger.error("Ignored QueueMemberRemovedEvent for unknown queue " + event.getQueue());
      return;
    }

    final AsteriskQueueMemberImpl member = queue.getMember(event.getLocation());
    if (member == null) {
      logger.error(
          "Ignored QueueMemberRemovedEvent for unknown agent name: "
              + event.getMemberName()
              + " location: "
              + event.getLocation()
              + " queue: "
              + event.getQueue());
      return;
    }

    queue.removeMember(member);
  }
コード例 #7
0
  public List<AsteriskQueue> getQueuesUpdatedAfter(Date date) {
    refreshQueuesIfForced();

    List<AsteriskQueue> copy = new ArrayList<AsteriskQueue>();
    synchronized (queuesLRU) {
      List<Entry<String, AsteriskQueueImpl>> list =
          new ArrayList<Entry<String, AsteriskQueueImpl>>(queuesLRU.entrySet());
      ListIterator<Entry<String, AsteriskQueueImpl>> iter = list.listIterator(list.size());

      Entry<String, AsteriskQueueImpl> entry;
      while (iter.hasPrevious()) {
        entry = iter.previous();
        AsteriskQueueImpl astQueue = entry.getValue();
        if (astQueue.getLastUpdateMillis() <= date.getTime()) {
          break;
        }
        copy.add(astQueue);
      }
    }

    return copy;
  }
コード例 #8
0
  /**
   * Challange a QueueMemberStatusEvent. Called from AsteriskServerImpl whenever a member state
   * changes.
   *
   * @param event that was triggered by Asterisk server.
   */
  void handleQueueMemberStatusEvent(QueueMemberStatusEvent event) {
    AsteriskQueueImpl queue = getInternalQueueByName(event.getQueue());

    if (queue == null) {
      logger.error("Ignored QueueMemberStatusEvent for unknown queue " + event.getQueue());
      return;
    }

    AsteriskQueueMemberImpl member = queue.getMemberByLocation(event.getLocation());
    if (member == null) {
      logger.error("Ignored QueueMemberStatusEvent for unknown member " + event.getLocation());
      return;
    }

    updateQueue(queue.getName());

    member.stateChanged(QueueMemberState.valueOf(event.getStatus()));
    member.penaltyChanged(event.getPenalty());
    member.lastCallChanged(event.getLastCall());
    member.callsTakenChanged(event.getCallsTaken());

    queue.fireMemberStateChanged(member);
  }
コード例 #9
0
  /**
   * Challange a QueueMemberAddedEvent.
   *
   * @param event - the generated QueueMemberAddedEvent.
   */
  public void handleQueueMemberAddedEvent(QueueMemberAddedEvent event) {
    final AsteriskQueueImpl queue = getInternalQueueByName(event.getQueue());
    if (queue == null) {
      logger.error("Ignored QueueMemberAddedEvent for unknown queue " + event.getQueue());
      return;
    }

    AsteriskQueueMemberImpl member = queue.getMember(event.getLocation());
    if (member == null) {
      member =
          new AsteriskQueueMemberImpl(
              server,
              queue,
              event.getLocation(),
              QueueMemberState.valueOf(event.getStatus()),
              event.getPaused(),
              event.getPenalty(),
              event.getMembership(),
              event.getCallsTaken(),
              event.getLastCall());
    }

    queue.addMember(member);
  }
コード例 #10
0
  /**
   * Called during initialization to populate the list of queues.
   *
   * @param event the event received
   */
  private void handleQueueParamsEvent(QueueParamsEvent event) {
    AsteriskQueueImpl queue;

    final String name = event.getQueue();
    final Integer max = event.getMax();
    final String strategy = event.getStrategy();
    final Integer serviceLevel = event.getServiceLevel();
    final Integer weight = event.getWeight();
    final Integer calls = event.getCalls();
    final Integer holdTime = event.getHoldTime();
    final Integer talkTime = event.getTalkTime();
    final Integer completed = event.getCompleted();
    final Integer abandoned = event.getAbandoned();
    final Double serviceLevelPerf = event.getServiceLevelPerf();

    queue = getInternalQueueByName(name);

    if (queue == null) {
      queue =
          new AsteriskQueueImpl(
              server,
              name,
              max,
              strategy,
              serviceLevel,
              weight,
              calls,
              holdTime,
              talkTime,
              completed,
              abandoned,
              serviceLevelPerf);
      logger.info("Adding new queue " + queue);
      addQueue(queue);
    } else {
      // We should never reach that code as this method is only called for initialization
      // So the queue should never be in the queues list
      synchronized (queue) {
        synchronized (queuesLRU) {
          if (queue.setMax(max)
              | queue.setServiceLevel(serviceLevel)
              | queue.setWeight(weight)
              | queue.setCalls(calls)
              | queue.setHoldTime(holdTime)
              | queue.setTalkTime(talkTime)
              | queue.setCompleted(completed)
              | queue.setAbandoned(abandoned)
              | queue.setServiceLevelPerf(serviceLevelPerf)) {

            queuesLRU.remove(queue.getName());
            queuesLRU.put(queue.getName(), queue);
          }
        }
      }
    }
  }
コード例 #11
0
 /**
  * Adds a queue to the internal map, keyed by name.
  *
  * @param queue the AsteriskQueueImpl to be added
  */
 private void addQueue(AsteriskQueueImpl queue) {
   synchronized (queuesLRU) {
     queuesLRU.put(queue.getName(), queue);
   }
 }