Ejemplo n.º 1
0
  void handleStatusEvent(StatusEvent event) {
    AsteriskChannelImpl channel;
    final Extension extension;
    boolean isNew = false;
    Map<String, String> variables = event.getVariables();

    channel = getChannelImplById(event.getUniqueId());
    if (channel == null) {
      Date dateOfCreation;

      if (event.getSeconds() != null) {
        dateOfCreation = new Date(DateUtil.getDate().getTime() - (event.getSeconds() * 1000L));
      } else {
        dateOfCreation = DateUtil.getDate();
      }
      channel =
          new AsteriskChannelImpl(server, event.getChannel(), event.getUniqueId(), dateOfCreation);
      isNew = true;
      if (variables != null) {
        for (String variable : variables.keySet()) {
          channel.updateVariable(variable, variables.get(variable));
        }
      }
    }

    if (event.getContext() == null && event.getExtension() == null && event.getPriority() == null) {
      extension = null;
    } else {
      extension = new Extension(event.getContext(), event.getExtension(), event.getPriority());
    }

    synchronized (channel) {
      channel.setCallerId(new CallerId(event.getCallerIdName(), event.getCallerIdNum()));
      channel.setAccount(event.getAccountCode());
      if (event.getChannelState() != null) {
        channel.stateChanged(
            event.getDateReceived(), ChannelState.valueOf(event.getChannelState()));
      }
      channel.extensionVisited(event.getDateReceived(), extension);

      if (event.getBridgedChannel() != null) {
        final AsteriskChannelImpl linkedChannel = getChannelImplByName(event.getBridgedChannel());
        if (linkedChannel != null) {
          // the date used here is not correct!
          channel.channelLinked(event.getDateReceived(), linkedChannel);
          synchronized (linkedChannel) {
            linkedChannel.channelLinked(event.getDateReceived(), channel);
          }
        }
      }
    }

    if (isNew) {
      logger.info("Adding new channel " + channel.getName());
      addChannel(channel);
      server.fireNewAsteriskChannel(channel);
    }
  }
Ejemplo n.º 2
0
  private AsteriskChannelImpl addNewChannel(
      String uniqueId,
      String name,
      Date dateOfCreation,
      String callerIdNumber,
      String callerIdName,
      ChannelState state,
      String account) {
    final AsteriskChannelImpl channel;
    final String traceId;

    channel = new AsteriskChannelImpl(server, name, uniqueId, dateOfCreation);
    channel.setCallerId(new CallerId(callerIdName, callerIdNumber));
    channel.setAccount(account);
    channel.stateChanged(dateOfCreation, state);
    logger.info("Adding channel " + channel.getName() + "(" + channel.getId() + ")");

    if (SLEEP_TIME_BEFORE_GET_VAR > 0) {
      try {
        Thread.sleep(SLEEP_TIME_BEFORE_GET_VAR);
      } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
      }
    }

    traceId = getTraceId(channel);
    channel.setTraceId(traceId);

    addChannel(channel);

    if (traceId != null
        && (!name.toLowerCase(Locale.ENGLISH).startsWith("local/")
            || (name.endsWith(",1") || name.endsWith(";1")))) {
      final OriginateCallbackData callbackData;
      callbackData = server.getOriginateCallbackDataByTraceId(traceId);
      if (callbackData != null && callbackData.getChannel() == null) {
        callbackData.setChannel(channel);
        try {
          callbackData.getCallback().onDialing(channel);
        } catch (Throwable t) {
          logger.warn("Exception dispatching originate progress.", t);
        }
      }
    }
    server.fireNewAsteriskChannel(channel);
    return channel;
  }