当前位置: 首页>>代码示例>>Java>>正文


Java Transaction.addData方法代码示例

本文整理汇总了Java中com.dianping.cat.message.Transaction.addData方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.addData方法的具体用法?Java Transaction.addData怎么用?Java Transaction.addData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.dianping.cat.message.Transaction的用法示例。


在下文中一共展示了Transaction.addData方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newtransation

import com.dianping.cat.message.Transaction; //导入方法依赖的package包/类
/**
 * Cat.newTransaction 与Cat.getProducer().newTransaction 区别在于 一个是重新生成一个transation  和获取当前线程绑定的transaction“
 *
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/cycletransation", method = RequestMethod.GET)
public String newtransation() throws Exception {
	Transaction t = Cat.getProducer().newTransaction("TransactionTest", "Cat.getProducer()");
	Cat.getProducer().logEvent("eventType1", "1", Message.SUCCESS, "");
	Cat.getProducer().logEvent("eventType1", "2", Message.SUCCESS, "");
	Transaction t2 = Cat.getProducer().newTransaction("TransactionTest-1", "child transaction 1");
	Cat.getProducer().logEvent("eventType2-1", "2-1", Message.SUCCESS, "");
	Cat.getProducer().logEvent("eventType2-2", "2-2", Message.SUCCESS, "");
	t2.addData("tChild transaction-1");
	t2.setStatus(Message.SUCCESS);
	t2.complete();
	Transaction t3 = Cat.getProducer().newTransaction("TransactionTest-2", "child transaction 2");
	Cat.getProducer().logEvent("eventType3-1", "3-1", Message.SUCCESS, "");
	Cat.getProducer().logEvent("eventType3-2", "3-2", Message.SUCCESS, "");
	t3.addData("Child transaction-2");
	t3.setStatus(Message.SUCCESS);
	// 休眠3s 验证时间
	Thread.sleep(4000);
	t3.complete();
	t.addData(" Parent transaction");
	t.setStatus(Message.SUCCESS);
	t.complete();
	return "";
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:31,代码来源:CatController.java

示例2: testMessageTree

import com.dianping.cat.message.Transaction; //导入方法依赖的package包/类
@Test
public void testMessageTree() {
	for (int i = 0; i < 500; i++) {
		Transaction t = Cat.newTransaction("URL", "/order/submitOrder");
		MessageTree tree = (MessageTree) Cat.getManager().getThreadLocalMessageTree();
		// 这里可以设置不同的域服务器,相当于app.properties那个配置文件
		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);
		
		try {
			Thread.sleep(300);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		t.complete();
	}
}
 
开发者ID:Percy0601,项目名称:training-cat,代码行数:22,代码来源:TrainingBussinessMessage.java

示例3: main

import com.dianping.cat.message.Transaction; //导入方法依赖的package包/类
public static void main(String[] args) {
	SpringApplication.run(ApplicationBootstrap.class, args);

	for (int i = 0; i < 1000; i++) {
		Transaction t = Cat.newTransaction(
				"统计消息类型:URL/SQL/Bussiness。。。一级纬度",
				"具体消息分类,属于一个二级纬度:/index;Select * from ...");
		// 增加事件记录
		Cat.logEvent("RemoteLink", "sina", Event.SUCCESS,
				"http://sina.com.cn/");
		// 增加记录变量
		t.addData("channel=channel" + i % 5);

		Cat.logMetricForCount("Receipt Verify Success");
		Cat.logMetricForCount("Receipt Verify Success 2", 2);
		Cat.logMetricForDuration("Receipt Verify Druation", 10);
		Cat.logMetricForSum("sum Value", 20);
		Cat.logMetricForSum("sum Value2", 20, 2);

		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		t.complete();

		// try {
		// System.in.read();
		// } catch (IOException e) {
		// e.printStackTrace();
		// }
		
	}

}
 
开发者ID:Percy0601,项目名称:training-cat,代码行数:37,代码来源:ApplicationBootstrap.java

示例4: aroundCache

import com.dianping.cat.message.Transaction; //导入方法依赖的package包/类
private Object aroundCache(CatMethodCache catMethodTransaction, ProceedingJoinPoint joinPoint) throws Throwable {
    //注解有值的优先以注解的值
    String type = catMethodTransaction.type();
    String name = catMethodTransaction.name();
    Object result = null;
    Transaction transaction = null;
    //不让cat异常导致业务异常
    try {
        transaction = Cat.getProducer().newTransaction(type, name);
    } catch (Exception e) {
        log.error("Cat.getProducer().newTransaction Error", e);
    }
    try {
        log.info("大众点评cat拦截 CatMethodCache :type="+type+";name="+name);
        result = joinPoint.proceed();
        if (transaction != null) {
            transaction.setStatus(Transaction.SUCCESS);
            if(joinPoint.getArgs().length>0)
            transaction.addData("key="+joinPoint.getArgs()[0]+";"+"value="+ JSONObject.toJSON(result==null?new Object():result).toString());
        }
    } catch (Throwable throwable) {
        if (transaction != null) transaction.setStatus(throwable);
        log.error("aroundTransaction exception", throwable);
        throw throwable;
    } finally {
        if (transaction != null)
            transaction.complete();
    }
    return result;
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:31,代码来源:CatAop.java

示例5: testBasicBussiness

import com.dianping.cat.message.Transaction; //导入方法依赖的package包/类
/**
 * 测试一个最简单的示例
 */
@Test
public void testBasicBussiness() {
	log.debug("测试最基本的事务");
	
	for (int i = 0; i < 1000; i++) {
		Transaction t = Cat.newTransaction("统计消息类型:URL/SQL/Bussiness。。。一级纬度", "具体消息分类,属于一个二级纬度:/index;Select * from ...");
		// 增加事件记录
		Cat.logEvent("RemoteLink", "sina", Event.SUCCESS, "http://sina.com.cn/");
		// 增加记录变量
		t.addData("channel=channel" + i % 5);
		
		Cat.logMetricForCount("Receipt Verify Success");
		Cat.logMetricForCount("Receipt Verify Success 2", 2);
		Cat.logMetricForDuration("Receipt Verify Druation", 10);
		Cat.logMetricForSum("sum Value", 20);
		Cat.logMetricForSum("sum Value2", 20, 2);
		
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		t.complete();
	}
}
 
开发者ID:Percy0601,项目名称:training-cat,代码行数:30,代码来源:TrainingBussinessMessage.java

示例6: Transaction

import com.dianping.cat.message.Transaction; //导入方法依赖的package包/类
/**
 * Transaction
 a).transaction适合记录跨越系统边界的程序访问行为,比如远程调用,数据库调用,也适合执行时间较长的业务逻辑监控
 b).某些运行期单元要花费一定时间完成工作, 内部需要其他处理逻辑协助, 我们定义为Transaction.
 c).Transaction可以嵌套(如http请求过程中嵌套了sql处理).
 d).大部分的Transaction可能会失败, 因此需要一个结果状态码.
 e).如果Transaction开始和结束之间没有其他消息产生, 那它就是Atomic Transaction(合并了起始标记).
 Event
 a). Event用来记录次数,表名单位时间内消息发生次数,比如记录系统异常,它和transaction相比缺少了时间的统计,开销比transaction要小
 
 type和name的组合要满足全局唯一性
    Transaction type有 "URL", "SQL", "Email", "Exec"等
    Event type有 "Info", "Warn", "Error"
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/transation", method = RequestMethod.GET)
public String transation() throws Exception {
	// Transaction的type
	Transaction t = Cat.newTransaction("TransactionTest", "findorder");
	// 3.Event Event用来记录次数,表名单位时间内消息发生次数,比如记录系统异常,它和transaction相比缺少了时间的统计,开销比transaction要小
	Cat.logEvent("info", "transation", Message.SUCCESS, "参数1");
	Cat.logEvent("error", "transation", Message.SUCCESS, "参数1");
	t.addData("Transaction测试");
	t.setStatus(Message.SUCCESS);
	t.complete();
	return "";
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:29,代码来源:CatController.java


注:本文中的com.dianping.cat.message.Transaction.addData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。