Package com.dianping.cat.message

Examples of com.dianping.cat.message.Transaction


      m_tag = tag;
    }

    @Override
    public void run() {
      Transaction t = Cat.newTransaction("TaggedThread", m_tag);

      try {
        TimeUnit.MILLISECONDS.sleep(m_timeout);

        t.setStatus(Message.SUCCESS);
        Cat.getManager().bind(m_tag, "Child Tagged Thread");
      } catch (Exception e) {
        Cat.logError(e);
        t.setStatus(e);
      } finally {
        t.complete();
      }
    }
View Full Code Here


  public void run() {
    boolean active = true;

    while (active) {
      long current = System.currentTimeMillis();
      Transaction t = Cat.newTransaction("Agent", "Paas");

      try {
        List<String> instances = m_dataBuilder.queryInstances();
        for (String instance : instances) {
          List<DataEntity> entities = m_dataBuilder.buildData(instance);

          m_dataSender.put(entities);
        }
        t.setStatus(Transaction.SUCCESS);
      } catch (Exception e) {
        t.setStatus(e);
        Cat.logError(e);
      } finally {
        t.complete();
      }

      long duration = System.currentTimeMillis() - current;

      try {
View Full Code Here

     processLongUrl(machine, tree);
     processLongService(machine, tree);

    if (message instanceof Transaction) {
      Transaction transaction = (Transaction) message;

      processTransaction(machine, transaction, tree);
    }
  }
View Full Code Here

    Message message = tree.getMessage();

    report.addIp(tree.getIpAddress());

    if (message instanceof Transaction) {
      Transaction root = (Transaction) message;

      processTransaction(report, tree, root);
    }
  }
View Full Code Here

public class ThreadTest {

  @Test
  public void test() throws InterruptedException {
    Transaction t = Cat.newTransaction("test3", "test3");
   
    String id= Cat.getProducer().createMessageId();
   
    Threads.forGroup("cat").start(new Task(id));
   
   
    Cat.logEvent("RemoteLink", "ChildThread3", Event.SUCCESS, id);
   
    t.complete();
   
    Thread.sleep(1000);
  }
View Full Code Here

    }
   
    @Override
      public void run() {

      Transaction t = Cat.newTransaction("test2", "test2");
     
      Cat.getManager().getThreadLocalMessageTree().setMessageId(m_messageId);

      t.complete();
      }
View Full Code Here

 
  @Test
  public void test() throws Exception {
    while (true) {
      for (int i = 0; i < 1000; i++) {
        Transaction t = Cat.newTransaction("URL", "/index");
        Cat.logEvent("RemoteLink", "sina", Event.SUCCESS, "http://sina.com.cn/");
        t.addData("channel=channel" + i % 5);
       
        Cat.logMetricForCount("Receipt Verify Success");

        MessageTree tree = (MessageTree) Cat.getManager().getThreadLocalMessageTree();
        tree.setDomain(TuanGou);
        t.complete();
      }

      for (int i = 0; i < 900; i++) {
        Transaction t = Cat.newTransaction("URL", "/detail");
        MessageTree tree = (MessageTree) Cat.getManager().getThreadLocalMessageTree();

        tree.setDomain(TuanGou);
        t.addData("channel=channel" + i % 5);
        t.complete();
      }

      for (int i = 0; i < 500; i++) {
        Transaction t = Cat.newTransaction("URL", "/order/submitOrder");
        MessageTree tree = (MessageTree) Cat.getManager().getThreadLocalMessageTree();

        tree.setDomain(PayOrder);
        Cat.logMetric("order", "quantity", 1, "channel", "channel" + i % 5);
        Cat.logMetric("payment.pending", "amount", i, "channel", "channel" + i % 5);
        Cat.logMetric("payment.success", "amount", i, "channel", "channel" + i % 5);
        t.addData("channel=channel" + i % 5);
        t.complete();
      }

      for (int i = 0; i < 1000; i++) {
        Transaction t = Cat.newTransaction("URL", "t");
        Cat.logEvent("RemoteLink", "sina", Event.SUCCESS, "http://sina.com.cn/");
        t.complete();
      }
      for (int i = 0; i < 900; i++) {
        Transaction t = Cat.newTransaction("URL", "e");
        t.complete();
      }
      for (int i = 0; i < 500; i++) {
        Transaction t = Cat.newTransaction("URL", "home");
        Cat.logMetric("order", "quantity", 1, "channel", "channel" + i % 5);
        Cat.logMetric("payment.pending", "amount", i, "channel", "channel" + i % 5);
        Cat.logMetric("payment.success", "amount", i, "channel", "channel" + i % 5);
        t.complete();
      }

      Thread.sleep(1000);
    }
  }
View Full Code Here

  @Test
  public void test2() throws Exception {
    while (true) {

      for (int i = 0; i < 1000; i++) {
        Transaction t = Cat.newTransaction("URL", "/index");
        Cat.logEvent("RemoteLink", "sina", Event.SUCCESS, "http://sina.com.cn/");
        t.addData("channel=channel" + i % 5);

        t.complete();
      }
      for (int i = 0; i < 900; i++) {
        Transaction t = Cat.newTransaction("URL", "/detail");
        t.addData("channel=channel" + i % 5);
        t.complete();
      }
      for (int i = 0; i < 500; i++) {
        Transaction t = Cat.newTransaction("URL", "/order/submitOrder");
        Cat.logMetric("order", "quantity", 1, "channel", "channel" + i % 5);
        Cat.logMetric("payment.pending", "amount", i, "channel", "channel" + i % 5);
        Cat.logMetric("payment.success", "amount", i, "channel", "channel" + i % 5);
        t.addData("channel=channel" + i % 5);
        t.complete();
      }

      Thread.sleep(1000);
      break;
    }
View Full Code Here

    }
  }

  public MetricReport invoke(final ModelRequest request) {
    final Semaphore semaphore = new Semaphore(0);
    final Transaction t = Cat.getProducer().newTransaction("ModelService", getClass().getSimpleName());
    final List<MetricReport> reports = Collections.synchronizedList(new ArrayList<MetricReport>());
    final List<String> ips = Collections.synchronizedList(new ArrayList<String>());
    int count = 0;
    t.setStatus(Message.SUCCESS);
    t.addData("request", request);
    t.addData("thread", Thread.currentThread());

    setParentTransaction(t);

    for (Pair<String, Integer> temp : m_servers) {
      final Pair<String, Integer> server = temp;

      s_threadPool.submit(new Runnable() {
        @Override
        public void run() {
          try {
            MetricReport report = invoke(request, server);

            if (report != null) {
              reports.add(report);
              ips.add(server.getKey());
            }
          } catch (Exception e) {
            logError(e);
            t.setStatus(e);
          } finally {
            semaphore.release();
          }
        }
      });
      count++;
    }

    try {
      semaphore.tryAcquire(count, 10000, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
      // ignore it
      t.setStatus(e);
    } finally {
      t.complete();
    }
    String require = request.getProperty("requireAll");

    if (reports.size() != count && require != null) {
      Cat.logEvent("FetchMetricReportError", request.getDomain(), Event.SUCCESS, null);
View Full Code Here

      return merger.getMetricReport();
    }
  }

  public MetricReport invoke(ModelRequest request, Pair<String, Integer> hostPorts) {
    Transaction t = newTransaction("ModelService", getClass().getSimpleName());

    try {
      URL url = buildUrl(request, hostPorts);

      t.addData(url.toString());

      InputStream in = Urls.forIO().connectTimeout(300).readTimeout(3000).openStream(url.toExternalForm());
      GZIPInputStream gzip = new GZIPInputStream(in);
      String xml = Files.forIO().readFrom(gzip, "utf-8");
      int len = xml == null ? 0 : xml.length();

      t.addData("length", len);

      if (len > 0) {
        MetricReport report = buildModel(xml);

        t.setStatus(Message.SUCCESS);
        return report;
      } else {
        t.setStatus("NoReport");
      }
    } catch (Exception e) {
      t.setStatus(e);
    } finally {
      t.complete();
    }
    return null;
  }
View Full Code Here

TOP

Related Classes of com.dianping.cat.message.Transaction

Copyright © 2018 www.massapicom. 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.