Package com.dianping.cat.report.task.alert.network

Source Code of com.dianping.cat.report.task.alert.network.NetworkAlert

package com.dianping.cat.report.task.alert.network;

import java.util.Map;

import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.unidal.helper.Threads.Task;

import com.dianping.cat.Cat;
import com.dianping.cat.consumer.company.model.entity.ProductLine;
import com.dianping.cat.helper.TimeHelper;
import com.dianping.cat.message.Transaction;
import com.dianping.cat.report.task.alert.AlertType;
import com.dianping.cat.report.task.alert.BaseAlert;

public class NetworkAlert extends BaseAlert implements Task, LogEnabled {

  @Override
  public void enableLogging(Logger logger) {
    m_logger = logger;
  }

  @Override
  public String getName() {
    return AlertType.Network.getName();
  }

  @Override
  public void run() {
    boolean active = true;
    try {
      Thread.sleep(5000);
    } catch (InterruptedException e) {
      active = false;
    }
    while (active) {
      Transaction t = Cat.newTransaction("AlertNetwork", TimeHelper.getMinuteStr());
      long current = System.currentTimeMillis();

      try {
        Map<String, ProductLine> productLines = m_productLineConfigManager.getCompany().getProductLines();

        for (ProductLine productLine : productLines.values()) {
          try {
            if (productLine.isNetworkDashboard()) {
              processProductLine(productLine);
            }
          } catch (Exception e) {
            Cat.logError(e);
          }
        }

        t.setStatus(Transaction.SUCCESS);
      } catch (Exception e) {
        t.setStatus(e);
      } finally {
        m_currentReports.clear();
        m_lastReports.clear();
        t.complete();
      }
      long duration = System.currentTimeMillis() - current;

      try {
        if (duration < DURATION) {
          Thread.sleep(DURATION - duration);
        }
      } catch (InterruptedException e) {
        active = false;
      }
    }
  }

  @Override
  public void shutdown() {
  }

}
TOP

Related Classes of com.dianping.cat.report.task.alert.network.NetworkAlert

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.