コード例 #1
0
  /**
   * Returns a collection of all active AsteriskChannels.
   *
   * @return a collection of all active AsteriskChannels.
   */
  Collection<AsteriskChannel> getChannels() {
    Collection<AsteriskChannel> copy;

    synchronized (channels) {
      copy = new ArrayList<AsteriskChannel>(channels.size() + 2);
      for (AsteriskChannel channel : channels) {
        if (channel.getState() != ChannelState.HUNGUP) {
          copy.add(channel);
        }
      }
    }
    return copy;
  }
コード例 #2
0
  /**
   * Returns the other side of a local channel.
   *
   * <p>Local channels consist of two sides, like "Local/1234@from-local-60b5,1" and
   * "Local/1234@from-local-60b5,2" (for Asterisk 1.4) or "Local/1234@from-local-60b5;1" and
   * "Local/1234@from-local-60b5;2" (for Asterisk 1.6) this method returns the other side.
   *
   * @param localChannel one side
   * @return the other side, or <code>null</code> if not available or if the given channel is not a
   *     local channel.
   */
  AsteriskChannelImpl getOtherSideOfLocalChannel(AsteriskChannel localChannel) {
    final String name;
    final char num;

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

    name = localChannel.getName();
    if (name == null
        || !name.startsWith("Local/")
        || (name.charAt(name.length() - 2) != ',' && name.charAt(name.length() - 2) != ';')) {
      return null;
    }

    num = name.charAt(name.length() - 1);

    if (num == '1') {
      return getChannelImplByName(name.substring(0, name.length() - 1) + "2");
    } else if (num == '2') {
      return getChannelImplByName(name.substring(0, name.length() - 1) + "1");
    } else {
      return null;
    }
  }
コード例 #3
0
  /** Removes channels that have been hung more than {@link #REMOVAL_THRESHOLD} milliseconds. */
  private void removeOldChannels() {
    Iterator<AsteriskChannelImpl> i;

    synchronized (channels) {
      i = channels.iterator();
      while (i.hasNext()) {
        final AsteriskChannel channel = i.next();
        final Date dateOfRemoval = channel.getDateOfRemoval();
        if (channel.getState() == ChannelState.HUNGUP && dateOfRemoval != null) {
          final long diff = DateUtil.getDate().getTime() - dateOfRemoval.getTime();
          if (diff >= REMOVAL_THRESHOLD) {
            i.remove();
          }
        }
      }
    }
  }
コード例 #4
0
  private String getTraceId(AsteriskChannel channel) {
    String traceId;

    try {
      traceId = channel.getVariable(Constants.VARIABLE_TRACE_ID);
    } catch (Exception e) {
      traceId = null;
    }
    // logger.info("TraceId for channel " + channel.getName() + " is " + traceId);
    return traceId;
  }
コード例 #5
0
  @Override
  public void onBusy(AsteriskChannel asteriskChannel) {
    MotechEvent event = callRequest.getOnBusyEvent();

    if (event != null) {
      org.asteriskjava.live.CallDetailRecord aCDR = asteriskChannel.getCallDetailRecord();
      CallDetailRecord cdr =
          new CallDetailRecord(
              aCDR.getStartDate(),
              aCDR.getEndDate(),
              aCDR.getAnswerDate(),
              translateDisposition(aCDR.getDisposition()),
              aCDR.getDuration());

      Map<String, Object> parameters = event.getParameters();
      parameters.put(IVREventDelegate.CALL_DETAIL_RECORD_KEY, cdr);

      eventRelay.sendEventMessage(event);
    }
  }