예제 #1
0
  /**
   * Returns a NON-HUNGUP channel from the ChannelManager's cache with the given name.
   *
   * @param name the name of the requested channel.
   * @return the NON-HUNGUP channel if found, or null if none is found.
   */
  AsteriskChannelImpl getChannelImplByNameAndActive(String name) {

    // In non bristuffed AST 1.2, we don't have uniqueid header to match the channel
    // So we must use the channel name
    // Channel name is unique at any give moment in the  * server
    // But asterisk-java keeps Hungup channels for a while.
    // We don't want to retrieve hungup channels.

    AsteriskChannelImpl channel = null;

    if (name == null) {
      return null;
    }

    synchronized (channels) {
      for (AsteriskChannelImpl tmp : channels) {
        if (tmp.getName() != null
            && tmp.getName().equals(name)
            && tmp.getState() != ChannelState.HUNGUP) {
          channel = tmp;
        }
      }
    }
    return channel;
  }
예제 #2
0
  /**
   * Returns a channel from the ChannelManager's cache with the given name If multiple channels are
   * found, returns the most recently CREATED one. If two channels with the very same date exist,
   * avoid HUNGUP ones.
   *
   * @param name the name of the requested channel.
   * @return the (most recent) channel if found, in any state, or null if none found.
   */
  AsteriskChannelImpl getChannelImplByName(String name) {
    Date dateOfCreation = null;
    AsteriskChannelImpl channel = null;

    if (name == null) {
      return null;
    }

    synchronized (channels) {
      for (AsteriskChannelImpl tmp : channels) {
        if (tmp.getName() != null && tmp.getName().equals(name)) {
          // return the most recent channel or when dates are similar, the active one
          if (dateOfCreation == null
              || tmp.getDateOfCreation().after(dateOfCreation)
              || (tmp.getDateOfCreation().equals(dateOfCreation)
                  && tmp.getState() != ChannelState.HUNGUP)) {
            channel = tmp;
            dateOfCreation = channel.getDateOfCreation();
          }
        }
      }
    }
    return channel;
  }