/**
   * 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());
  }
  /**
   * 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());
  }