Package com.dianping.cat.message

Examples of com.dianping.cat.message.Transaction


  }

  @Test
  public void sendLongSQLTransaction() throws Exception {
    for (int i = 0; i < 10; i++) {
      Transaction t = Cat.getProducer().newTransaction("SQL", "Method6");
      t.addData("key and value");
      Thread.sleep(102);
      t.complete();
    }
  }
View Full Code Here


  }

  @Test
  public void testTransactionNormal() {
    long timestamp = 1325489621987L;
    Transaction root = newTransaction("URL", "Review", timestamp, "0", 100, "/review/2468");

    root.addChild(newEvent("URL", "Payload", timestamp, "0", "ip=127.0.0.1&ua=Mozilla 5.0...&refer=...&..."));
    root.addChild(newTransaction("Service", "Auth", timestamp, "0", 20, "userId=1357&token=..."));
    root.addChild(newTransaction("Cache", "findReviewByPK", timestamp + 22, "Missing", 1, "2468") //
          .addChild(newEvent("CacheHost", "host-1", timestamp + 22, "0", "ip=192.168.8.123")));
    root.addChild(newTransaction("DAL", "findReviewByPK", timestamp + 25, "0", 5, "select title,content from Review where id = ?"));
    root.addChild(newEvent("URL", "View", timestamp + 40, "0", "view=HTML"));

    check(root, "t2012-01-02 15:33:41.987\tURL\tReview\t\n" + //
          "E2012-01-02 15:33:41.987\tURL\tPayload\t0\tip=127.0.0.1&ua=Mozilla 5.0...&refer=...&...\t\n" + //
          "A2012-01-02 15:33:41.987\tService\tAuth\t0\t20000us\tuserId=1357&token=...\t\n" + //
          "t2012-01-02 15:33:42.009\tCache\tfindReviewByPK\t\n" + //
View Full Code Here

  }

  @Test
  public void testTransactionSimple() {
    long timestamp = 1325489621987L;
    Transaction transaction = newTransaction("type", "name", timestamp, "0", 10, "here is the data.");

    check(transaction, "A2012-01-02 15:33:41.987\ttype\tname\t0\t10000us\there is the data.\t\n");
  }
View Full Code Here

  private String parseHost() {
    MessageTree tree = (MessageTree) Cat.getManager().getThreadLocalMessageTree();
    Message message = tree.getMessage();

    if (message.getType().equals("URL") && message instanceof Transaction) {
      Transaction t = (Transaction) message;
      List<Message> messages = t.getChildren();

      for (Message temp : messages) {
        String name = temp.getName();
        if (name.equals("URL.Server") || name.equals("ClientInfo")) {
          m_data = temp.getData().toString();
View Full Code Here

    m_logger.info(String.format("Finishing %s tasks in period [%s, %s]", m_tasks.size(), df.format(startDate),
          df.format(endDate)));

    MessageProducer cat = Cat.getProducer();
    Transaction t = cat.newTransaction("Checkpoint", "RealtimeConsumer");

    try {
      for (PeriodTask task : m_tasks) {
        task.finish();
      }

      t.setStatus(Message.SUCCESS);
    } catch (Throwable e) {
      cat.logError(e);
      t.setStatus(e);
    } finally {
      t.complete();

      m_logger.info(String.format("Finished %s tasks in period [%s, %s]", m_tasks.size(), df.format(startDate),
            df.format(endDate)));
    }
  }
View Full Code Here

    });
  }

  @Override
  public void doCheckpoint(boolean atEnd) {
    Transaction t = Cat.newTransaction("Checkpoint", "dump");

    try {
      long startTime = getStartTime();

      checkpointAsyc(startTime);
      m_logger.info("Old version domains:" + m_oldVersionDomains);
      m_logger.info("Error timestamp:" + m_errorTimestampDomains);
      t.setStatus(Transaction.SUCCESS);
    } catch (Exception e) {
      t.setStatus(e);
    } finally {
      t.complete();
    }
  }
View Full Code Here

    }
  }

  public void doCheckpoint() throws IOException {
    MessageProducer cat = Cat.getProducer();
    Transaction t = cat.newTransaction("Checkpoint", getClass().getSimpleName());

    try {
      long currentStartTime = getCurrentStartTime();
      Period period = m_periodManager.findPeriod(currentStartTime);

      for (MessageAnalyzer analyzer : period.getAnalzyers()) {
        try {
          analyzer.doCheckpoint(false);
        } catch (Exception e) {
          Cat.logError(e);
        }
      }

      try {
        // wait dump analyzer store completed
        Thread.sleep(10 * 1000);
      } catch (InterruptedException e) {
        // ignore
      }
      t.setStatus(Message.SUCCESS);
    } catch (RuntimeException e) {
      cat.logError(e);
      t.setStatus(e);
    } finally {
      t.complete();
    }
  }
View Full Code Here

  private void processOneEntity(MonitorEntity entity) {
    String targetUrl = entity.getTargetUrl();
    String url = parseFormatUrl(targetUrl);

    if (url != null) {
      Transaction t = Cat.newTransaction("Monitor", url);
      String ip = entity.getIp();
      IpInfo ipInfo = m_ipService.findIpInfoByString(ip);

      try {
        if (ipInfo != null) {
          buildMessage(entity, url, ipInfo);
        } else {
          Cat.logEvent("ip", "notFound", Event.SUCCESS, ip);
        }
        t.setStatus(Transaction.SUCCESS);
      } catch (Exception e) {
        Cat.logError(e);
        t.setStatus(e);
      } finally {
        t.complete();
      }
    }
  }
View Full Code Here

    Cat.setup(null);
  }

  @Test
  public void testForkedTransaction() throws Exception {
    Transaction t = Cat.newTransaction("ForkedRoot", "Root");
    ForkedTransaction t1 = Cat.newForkedTransaction("ForkedChild", "Child1");
    ForkedTransaction t2 = Cat.newForkedTransaction("ForkedChild", "Child2");

    Threads.forGroup().start(new TimedThread(t1, 500)); // will run away
    Threads.forGroup().start(new TimedThread(t2, 100)); // will be back in time

    TimeUnit.MILLISECONDS.sleep(200);

    t.setStatus(Message.SUCCESS);
    t.complete();
  }
View Full Code Here

    t.complete();
  }

  @Test
  public void testTaggedTransaction() throws Exception {
    Transaction t = Cat.newTransaction("TaggedRoot", "Root");
    Cat.newTaggedTransaction("TaggedChild", "Child1", "Tag1");
    Cat.newTaggedTransaction("TaggedChild", "Child2", "Tag2");

    Threads.forGroup().start(new TaggedThread(500, "Tag1"));
    Threads.forGroup().start(new TaggedThread(100, "Tag2"));

    TimeUnit.MILLISECONDS.sleep(200);

    t.setStatus(Message.SUCCESS);
    t.complete();
  }
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.