@Override
 public void setUp() {
   AsteriskServerImpl server = new AsteriskServerImpl();
   channel = new AsteriskChannelImpl(server, "SIP/1234", "0123456789.123", DateUtil.getDate());
   channel.stateChanged(DateUtil.getDate(), ChannelState.DOWN);
   numberOfChanges = 0;
 }
Esempio n. 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);
    }
  }
  public void testStateChange() {
    channel.addPropertyChangeListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent evt) {
            assertEquals("wrong propertyName", "state", evt.getPropertyName());
            assertEquals("wrong oldValue", ChannelState.DOWN, evt.getOldValue());
            assertEquals("wrong newValue", ChannelState.DIALING, evt.getNewValue());
            assertEquals("wrong source", channel, evt.getSource());
            numberOfChanges++;
          }
        });

    channel.stateChanged(DateUtil.getDate(), ChannelState.DIALING);
    assertEquals("wrong number of propagated changes", 1, numberOfChanges);
  }
Esempio n. 4
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();
          }
        }
      }
    }
  }
Esempio n. 5
0
 /**
  * Returns the end time as Date object.
  *
  * @param tz the timezone of the Asterisk server.
  * @return the end time as Date object.
  * @since 0.3
  */
 public Date getEndTimeAsDate(TimeZone tz) {
   return DateUtil.parseDateTime(endTime, tz);
 }
Esempio n. 6
0
 /**
  * Returns the end time as Date object.
  *
  * <p>This method asumes that the Asterisk server's timezone equals the default timezone of your
  * JVM.
  *
  * @return the end time as Date object.
  * @since 0.3
  */
 public Date getEndTimeAsDate() {
   return DateUtil.parseDateTime(endTime);
 }
Esempio n. 7
0
 /**
  * Returns the answer time as Date object.
  *
  * @param tz the timezone of the Asterisk server.
  * @return the answer time as Date object.
  * @since 0.3
  */
 public Date getAnswerTimeAsDate(TimeZone tz) {
   return DateUtil.parseDateTime(answerTime, tz);
 }
Esempio n. 8
0
 /**
  * Returns the answer time as Date object.
  *
  * <p>This method asumes that the Asterisk server's timezone equals the default timezone of your
  * JVM.
  *
  * @return the answer time as Date object.
  * @since 0.3
  */
 public Date getAnswerTimeAsDate() {
   return DateUtil.parseDateTime(answerTime);
 }
Esempio n. 9
0
 /**
  * Returns the start time as Date object.
  *
  * @param tz the timezone of the Asterisk server.
  * @return the start time as Date object.
  * @since 0.3
  */
 public Date getStartTimeAsDate(TimeZone tz) {
   return DateUtil.parseDateTime(startTime, tz);
 }
Esempio n. 10
0
 /**
  * Returns the start time as Date object.
  *
  * <p>This method asumes that the Asterisk server's timezone equals the default timezone of your
  * JVM.
  *
  * @return the start time as Date object.
  * @since 0.3
  */
 public Date getStartTimeAsDate() {
   return DateUtil.parseDateTime(startTime);
 }