public synchronized void completedExchange(Exchange exchange, long time) {
    increment();
    exchangesCompleted.increment();
    exchangesInflight.decrement();

    if (ExchangeHelper.isFailureHandled(exchange)) {
      failuresHandled.increment();
    }
    Boolean externalRedelivered = exchange.isExternalRedelivered();
    if (externalRedelivered != null && externalRedelivered) {
      externalRedeliveries.increment();
    }

    minProcessingTime.updateValue(time);
    maxProcessingTime.updateValue(time);
    totalProcessingTime.updateValue(time);
    lastProcessingTime.updateValue(time);
    deltaProcessingTime.updateValue(time);

    long now = new Date().getTime();
    if (firstExchangeCompletedTimestamp.getUpdateCount() == 0) {
      firstExchangeCompletedTimestamp.updateValue(now);
    }

    lastExchangeCompletedTimestamp.updateValue(now);
    if (firstExchangeCompletedExchangeId == null) {
      firstExchangeCompletedExchangeId = exchange.getExchangeId();
    }
    lastExchangeCompletedExchangeId = exchange.getExchangeId();

    // update mean
    long count = exchangesCompleted.getValue();
    long mean = count > 0 ? totalProcessingTime.getValue() / count : 0;
    meanProcessingTime.updateValue(mean);
  }
  public String dumpStatsAsXml(boolean fullStats) {
    StringBuilder sb = new StringBuilder();
    sb.append("<stats ");
    sb.append(String.format("exchangesCompleted=\"%s\"", exchangesCompleted.getValue()));
    sb.append(String.format(" exchangesFailed=\"%s\"", exchangesFailed.getValue()));
    sb.append(String.format(" failuresHandled=\"%s\"", failuresHandled.getValue()));
    sb.append(String.format(" redeliveries=\"%s\"", redeliveries.getValue()));
    sb.append(String.format(" externalRedeliveries=\"%s\"", externalRedeliveries.getValue()));
    sb.append(String.format(" minProcessingTime=\"%s\"", minProcessingTime.getValue()));
    sb.append(String.format(" maxProcessingTime=\"%s\"", maxProcessingTime.getValue()));
    sb.append(String.format(" totalProcessingTime=\"%s\"", totalProcessingTime.getValue()));
    sb.append(String.format(" lastProcessingTime=\"%s\"", lastProcessingTime.getValue()));
    sb.append(String.format(" deltaProcessingTime=\"%s\"", deltaProcessingTime.getValue()));
    sb.append(String.format(" meanProcessingTime=\"%s\"", meanProcessingTime.getValue()));

    if (fullStats) {
      sb.append(String.format(" startTimestamp=\"%s\"", dateAsString(startTimestamp.getValue())));
      sb.append(String.format(" resetTimestamp=\"%s\"", dateAsString(resetTimestamp.getValue())));
      sb.append(
          String.format(
              " firstExchangeCompletedTimestamp=\"%s\"",
              dateAsString(firstExchangeCompletedTimestamp.getValue())));
      sb.append(
          String.format(
              " firstExchangeCompletedExchangeId=\"%s\"",
              nullSafe(firstExchangeCompletedExchangeId)));
      sb.append(
          String.format(
              " firstExchangeFailureTimestamp=\"%s\"",
              dateAsString(firstExchangeFailureTimestamp.getValue())));
      sb.append(
          String.format(
              " firstExchangeFailureExchangeId=\"%s\"", nullSafe(firstExchangeFailureExchangeId)));
      sb.append(
          String.format(
              " lastExchangeCompletedTimestamp=\"%s\"",
              dateAsString(lastExchangeCompletedTimestamp.getValue())));
      sb.append(
          String.format(
              " lastExchangeCompletedExchangeId=\"%s\"",
              nullSafe(lastExchangeCompletedExchangeId)));
      sb.append(
          String.format(
              " lastExchangeFailureTimestamp=\"%s\"",
              dateAsString(lastExchangeFailureTimestamp.getValue())));
      sb.append(
          String.format(
              " lastExchangeFailureExchangeId=\"%s\"", nullSafe(lastExchangeFailureExchangeId)));
    }
    sb.append("/>");
    return sb.toString();
  }
 public Date getFirstExchangeFailureTimestamp() {
   long value = firstExchangeFailureTimestamp.getValue();
   return value > 0 ? new Date(value) : null;
 }
 public long getDeltaProcessingTime() throws Exception {
   return deltaProcessingTime.getValue();
 }
 public Date getLastExchangeCompletedTimestamp() {
   long value = lastExchangeCompletedTimestamp.getValue();
   return value > 0 ? new Date(value) : null;
 }
 public long getTotalProcessingTime() throws Exception {
   return totalProcessingTime.getValue();
 }
 public long getLastProcessingTime() throws Exception {
   return lastProcessingTime.getValue();
 }
 public long getExternalRedeliveries() throws Exception {
   return externalRedeliveries.getValue();
 }
 public long getMaxProcessingTime() throws Exception {
   return maxProcessingTime.getValue();
 }
 public long getRedeliveries() throws Exception {
   return redeliveries.getValue();
 }
 public long getFailuresHandled() throws Exception {
   return failuresHandled.getValue();
 }
 public long getExchangesInflight() {
   return exchangesInflight.getValue();
 }
 public long getExchangesFailed() throws Exception {
   return exchangesFailed.getValue();
 }
 public long getExchangesCompleted() throws Exception {
   return exchangesCompleted.getValue();
 }