コード例 #1
0
  void handleBridgeEvent(BridgeEvent event) {
    final AsteriskChannelImpl channel1 = getChannelImplById(event.getUniqueId1());
    final AsteriskChannelImpl channel2 = getChannelImplById(event.getUniqueId2());

    if (channel1 == null) {
      logger.error("Ignored BridgeEvent for unknown channel " + event.getChannel1());
      return;
    }
    if (channel2 == null) {
      logger.error("Ignored BridgeEvent for unknown channel " + event.getChannel2());
      return;
    }

    if (event.isLink()) {
      logger.info("Linking channels " + channel1.getName() + " and " + channel2.getName());
      synchronized (channel1) {
        channel1.channelLinked(event.getDateReceived(), channel2);
      }

      synchronized (channel2) {
        channel2.channelLinked(event.getDateReceived(), channel1);
      }
    }

    if (event.isUnlink()) {
      logger.info("Unlinking channels " + channel1.getName() + " and " + channel2.getName());
      synchronized (channel1) {
        channel1.channelUnlinked(event.getDateReceived());
      }

      synchronized (channel2) {
        channel2.channelUnlinked(event.getDateReceived());
      }
    }
  }
コード例 #2
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);
    }
  }