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


Java Cat.newTransaction方法代码示例

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


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

示例1: initGroupDataSource

import com.dianping.cat.Cat; //导入方法依赖的package包/类
@Override
public void initGroupDataSource(GroupDataSource source, JdbcFilter chain) {
	Transaction transaction = Cat.newTransaction(CAT_TYPE, "DataSource.Init-" + source.getJdbcRef());
	try {
		chain.initGroupDataSource(source, chain);
		this.monitor = new GroupDataSourceMonitor(source);
		StatusExtensionRegister.getInstance().register(this.monitor);
		transaction.setStatus(Message.SUCCESS);
	} catch (RuntimeException e) {
		Cat.logError(e);
		transaction.setStatus(e);
		throw e;
	} finally {
		transaction.complete();
	}
}
 
开发者ID:dianping,项目名称:zebra,代码行数:17,代码来源:CatFilter.java

示例2: testMessageTree

import com.dianping.cat.Cat; //导入方法依赖的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: switchFailOverDataSource

import com.dianping.cat.Cat; //导入方法依赖的package包/类
@Override
public void switchFailOverDataSource(FailOverDataSource source, JdbcFilter chain) {
	Transaction t = Cat.newTransaction(CAT_TYPE, "FailOver");
	try {
		chain.switchFailOverDataSource(source, chain);
		Cat.logEvent("DAL.FailOver", "Success");
		t.setStatus(Message.SUCCESS);
	} catch (RuntimeException exp) {
		Cat.logEvent("DAL.FailOver", "Failed");
		Cat.logError(exp);
		t.setStatus("Fail to find any master database");
		throw exp;
	} finally {
		t.complete();
	}
}
 
开发者ID:dianping,项目名称:zebra,代码行数:17,代码来源:CatFilter.java

示例4: testCat

import com.dianping.cat.Cat; //导入方法依赖的package包/类
@Test
public void testCat() throws IOException {

	Transaction t1 = Cat.newTransaction("type1", "name1");
	Transaction t21 = Cat.newTransaction("type21", "name2");
	Transaction t31 = Cat.newTransaction("type31", "name3");
	t31.setStatus(Transaction.SUCCESS);
	t31.complete();
	t21.setStatus(Transaction.SUCCESS);
	t21.complete();

	Transaction t22 = Cat.newTransaction("type22", "name2");
	t22.setStatus(Transaction.SUCCESS);
	t22.complete();
	t1.setStatus(Transaction.SUCCESS);
	t1.complete();

	waitForAnyKeyToExit();
}
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:20,代码来源:SimpleTest.java

示例5: logTransactionSwallowException

import com.dianping.cat.Cat; //导入方法依赖的package包/类
@Override
public <V> V logTransactionSwallowException(String type, String name, Callable<V> task) {

	Transaction transaction = Cat.newTransaction(type, name);
	try{
		V result = task.call();
		transaction.setStatus(Transaction.SUCCESS);
		return result;
	}catch(Throwable th){
		transaction.setStatus(th);
		logger.error("[logTransaction]" + type + "," + name + "," + task, th);
	}finally{
		transaction.complete();
	}
	return null;
}
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:17,代码来源:CatTransactionMonitor.java

示例6: sendQueue

import com.dianping.cat.Cat; //导入方法依赖的package包/类
private void sendQueue(QueueName queueName, RabbitMessage rm) throws Exception {
    if (rm == null || queueName == null) {
        return;
    }
    initQueueChannel();
    String _queueName = queueName.getNameByEnvironment(environment);
    Transaction trans = Cat.newTransaction("RabbitMQ Message", "PUBLISH-QUEUE-" + _queueName);
    Cat.logEvent("mq send queue", _queueName, Event.SUCCESS,rm.toJsonStr());
    try {
        queueChannel.queueDeclare(_queueName, true, false, false, null);
        queueChannel.basicPublish("", _queueName, MessageProperties.PERSISTENT_TEXT_PLAIN, rm.toJsonStr().getBytes("UTF-8"));
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("SEND SUCCESS:[queue:{},message:{}]", _queueName, rm.toJsonStr());
        }
        Cat.logMetricForCount("PUBLISH-QUEUE-" + _queueName); // 统计请求次数, 可以查看对应队列中放入了多少信息
        trans.setStatus(Transaction.SUCCESS);
    } catch (Exception e) {
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error("SEND ERROR:[queue:{},message:{},exception:{}]", _queueName, rm.toJsonStr(), e);
        }
        String err = queueName + "  rabbitmq发送消息异常";
        Cat.logError(err, e);
        trans.setStatus(e);
        throw new AsuraRabbitMqException(err, e);
    } finally {
        trans.complete();
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:29,代码来源:RabbitMqSendClient.java

示例7: sendTopic

import com.dianping.cat.Cat; //导入方法依赖的package包/类
/**
 * 发送消息-topic方式
 *
 * @param exchangeName 格式为:系统标示_模块标示_功能标示
 * @param msg          具体消息
 * @author zhangshaobin
 * @created 2016年3月1日 下午4:40:59
 */
public void sendTopic(ExchangeName exchangeName, RoutingKey routingKey, PublishSubscribeType type, String msg) throws Exception {
    initTopicChannel();
    String _exchange = exchangeName.getNameByEnvironment(environment);
    Transaction trans = Cat.newTransaction("RabbitMQ Message", "PUBLISH-TOPIC-" + _exchange);
    RabbitMessage rm = new RabbitMessage();
    rm.setData(msg);
    rm.setType(_exchange);
    try {
        Cat.logEvent("mq send topic",exchangeName.getName(),Event.SUCCESS, rm.toJsonStr());
        rm.setType(_exchange);
        topicChannel.exchangeDeclare(_exchange, type.getName(), true);
        topicChannel.basicPublish(_exchange, routingKey.getKey(), null, rm.toJsonStr().getBytes("UTF-8"));
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("SEND SUCCESS:[queue:{},message:{}]", _exchange, rm.toJsonStr());
        }
        Cat.logMetricForCount("PUBLISH-TOPIC-" + _exchange); // 统计请求次数, 可以查看对应队列中放入了多少信息
        trans.setStatus(Transaction.SUCCESS);
    } catch (Exception e) {
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error("SEND ERROR:[queue:{},message:{},exception:{}]", _exchange, rm.toJsonStr(), e);
        }
        String err = exchangeName + "  rabbitmq发送消息异常";
        Cat.logError(err, e);
        trans.setStatus(e);
        throw new AsuraRabbitMqException(err, e);
    } finally {
        trans.complete();
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:38,代码来源:RabbitMqSendClient.java

示例8: doBasicProfiling

import com.dianping.cat.Cat; //导入方法依赖的package包/类
@Around("execution(* com..*.proxy..*.* (..))")
public Object doBasicProfiling(final ProceedingJoinPoint joinPoint) throws Throwable {
	long start_all = System.currentTimeMillis();
	long end_all = 0L;
	String declaringTypeName = joinPoint.getSignature().getDeclaringTypeName();
	String signatureName = joinPoint.getSignature().getName();
	Object [] args = joinPoint.getArgs();
	Transaction tran = Cat.newTransaction("Aspect-proxy", declaringTypeName + "." + signatureName);
	if (RpcContext.getContext().getRemoteAddressString() != null && RpcContext.getContext().getMethodName() != null
			&& RpcContext.getContext().getUrl() != null) {
		MDC.put(HOST, RpcContext.getContext().getRemoteAddressString());
		MDC.put(INTERFACE, RpcContext.getContext().getUrl().getServiceInterface());
		MDC.put(METHOD, RpcContext.getContext().getMethodName());
	} else {
		MDC.put(HOST, "127.0.0.1");
		MDC.put(INTERFACE, "none");
		MDC.put(METHOD, "none");
	}

	final DataLogEntity de = new DataLogEntity();
	de.setClassName(declaringTypeName);
	de.setMethodName(signatureName);
	de.setParams(args);
	String logJson = de.toJsonStr();
	// 参数日志
	if (logger.isDebugEnabled()) {
		logger.debug(de.toJsonStr());
	}
	try {
		long start = System.currentTimeMillis();
		final Object retVal = joinPoint.proceed();
		long end = System.currentTimeMillis();
		// 记录耗时
		logger.info("{}, 耗时:{} ms, 进入aop到执行完耗时:{} ms", logJson, (end - start), (end - start_all));
		Cat.logEvent(declaringTypeName, signatureName, "0", logJson+" 耗时:" + (end - start) + " ms" + " 时间戳:" + System.currentTimeMillis());
		/**
		 * 设置消息的状态,必须设置,0:标识成功,其他标识发生了异常
		 */
		tran.setStatus(Transaction.SUCCESS);
		end_all = System.currentTimeMillis();
		return retVal;
	} catch (final Exception e) {
		final ErrorLogEntity ele = new ErrorLogEntity(de);
		DataTransferObject dto = handleException(e, ele, tran);
		end_all = System.currentTimeMillis();
		// 方法返回值类型
		Class returnType = null;
		if (null != joinPoint.getSignature()) {
			returnType = ((MethodSignature) joinPoint.getSignature()).getReturnType();
		}
		if (null != returnType && returnType.equals(String.class)){
			return dto.toJsonString();
		}else if (null != returnType && returnType.equals(DataTransferObject.class)){
			return dto;
		}else{
			throw e;
		}
	} finally {
		MDC.remove(HOST);
		MDC.remove(INTERFACE);
		MDC.remove(METHOD);
		tran.complete();
		logger.info("{}, 接入cat后整体耗时: {} ms", logJson, (end_all - start_all));
	}
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:66,代码来源:SystemLogger.java

示例9: init

import com.dianping.cat.Cat; //导入方法依赖的package包/类
/**
 * 初始化zk连接
 *
 * @author zhangshaobin
 * @created 2013-6-26 上午10:21:34
 */
private void init() {
    applicationName = DynamicPropertyFactory.getInstance().getStringProperty(CommonConstant.CONFIG_APPLICATION_NAME_KEY, null).get();
    String zkConfigEnsemble = DynamicPropertyFactory.getInstance().getStringProperty(CommonConstant.ZK_ENSEMABLE_KEY, null).get();
    Integer zkConfigSessionTimeout = DynamicPropertyFactory.getInstance().getIntProperty(CommonConstant.ZK_SESSION_TIMEOUT_KEY, 15000).get();
    Integer zkConfigConnTimeout = DynamicPropertyFactory.getInstance().getIntProperty(CommonConstant.ZK_CONN_TIMEOUT_KEY, 5000).get();

    Transaction tran = Cat.newTransaction("Asura Configuration init", applicationName + "_" + zkConfigEnsemble);

    try {

        if (Check.NuNStr(zkConfigEnsemble)) {
            logger.warn("ZooKeeper configuration running in file mode, zk is not enabled since not configured");
            Cat.logError("zk is not enabled since not configured", new RuntimeException("ZooKeeper located at " + zkConfigEnsemble + " is not started."));
            return;
        }

        client = createAndStartZKClient(zkConfigEnsemble, zkConfigSessionTimeout, zkConfigConnTimeout);

        if (client.getState() != CuratorFrameworkState.STARTED) {
            throw new RuntimeException("ZooKeeper located at " + zkConfigEnsemble + " is not started.");
        }

        tran.setStatus(Transaction.SUCCESS);
    } catch (Exception e) {
        logger.error("连接配置中心服务器超时,时间5000毫秒。", e);
        Cat.logError("asura configuration init exception", e);
        tran.setStatus(e);
        System.exit(1);
    } finally {
        tran.complete();
    }
    logger.info(new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss] ").format(new Date()) + applicationName + " connected to cofnig server(" + zkConfigEnsemble + ").");
    logger.info(applicationName + " connected to cofnig server(" + zkConfigEnsemble + ").");
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:41,代码来源:ConfigSubscriber.java

示例10: getConfigValue

import com.dianping.cat.Cat; //导入方法依赖的package包/类
/**
 * 从zookeeper上获取配置信息
 *
 * @param suffixPath
 *         配置路径
 *
 * @return 配置信息值
 */
@Override
public String getConfigValue(final String suffixPath) {
    final String path = pasePath(suffixPath);
    String data = DynamicPropertyFactory.getInstance().getStringProperty(paseKey(path), null).get();
    if (Check.NuNStr(data)) {
        try {
            if (isExistsNode(path)) {
                data = (String) SerializableSerializer.deserialize(client.getData().forPath(path));
            } else {
                throw new RuntimeException("zk configuration can not find. key:" + path);
            }
            if (!Check.NuNStr(data)) {
                ((ConcurrentCompositeConfiguration) ConfigurationManager.getConfigInstance()).setOverrideProperty(paseKey(path), data);
            } else {
                throw new RuntimeException("zk configuration value is null. key:" + path);
            }
        } catch (Exception e) {
            logger.error("can't get asura configuration by " + path, e);
            Transaction tran = Cat.newTransaction("get Asura Configuration", path);
            Cat.logError("can't get asura configuration by " + path, e);
            tran.setStatus(e);
            tran.complete();
        }
    }
    return DynamicPropertyFactory.getInstance().getStringProperty(paseKey(path), null).get();
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:35,代码来源:ConfigSubscriber.java

示例11: testBasicBussiness

import com.dianping.cat.Cat; //导入方法依赖的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

示例12: findAll

import com.dianping.cat.Cat; //导入方法依赖的package包/类
@Override
public List<User> findAll() {
	String rootMessageId = RpcContext.getContext().getAttachment(CatConstants.PIGEON_ROOT_MESSAGE_ID);
	String currentMessageId = RpcContext.getContext().getAttachment(CatConstants.PIGEON_CURRENT_MESSAGE_ID);
	String serverMessageId = RpcContext.getContext().getAttachment(CatConstants.PIGEON_SERVER_MESSAGE_ID);
	Transaction t = Cat.newTransaction("RemoteCall", "findAll");
	
	MessageTree tree = Cat.getManager().getThreadLocalMessageTree();
	if (null == tree) {
		Cat.setup(null);
		tree = Cat.getManager().getThreadLocalMessageTree();
	}
	
	tree.setRootMessageId(rootMessageId);
	tree.setParentMessageId(serverMessageId);
	tree.setMessageId(currentMessageId);
	
	List<User> users = new ArrayList<User>();
	int i = 0;
	
	while (i ++ < 10) {
		User u = new User();
		u.setId(i);
		u.setName("Percy00" + i);
		users.add(u);
	}
	
	Cat.logEvent("Call", "Params", Event.SUCCESS, "parentId:" + serverMessageId + "|msgId:" + currentMessageId + "End...");
	t.setStatus(Transaction.SUCCESS);
	t.complete();
	return users;
}
 
开发者ID:Percy0601,项目名称:training-cat,代码行数:33,代码来源:UserServiceImpl.java

示例13: main

import com.dianping.cat.Cat; //导入方法依赖的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

示例14: hello

import com.dianping.cat.Cat; //导入方法依赖的package包/类
@RequestMapping("/hello")
public String hello(String name) {
	Transaction t = Cat.newTransaction("URL", "/hello");
	String serverMessageId = Cat.getProducer().createMessageId();
	MessageTree tree = Cat.getManager().getThreadLocalMessageTree();
	if (null == tree) {
		Cat.setup(null);
		tree = Cat.getManager().getThreadLocalMessageTree();
	}
	
	String rootMessageId = tree.getRootMessageId() == null ? tree.getMessageId() : tree.getRootMessageId();
	String currentMessageId = tree.getMessageId();
	
	// 传递上下文
	RpcContext.getContext().setAttachment(CatConstants.PIGEON_ROOT_MESSAGE_ID, rootMessageId);
	RpcContext.getContext().setAttachment(CatConstants.PIGEON_CURRENT_MESSAGE_ID, currentMessageId);
	RpcContext.getContext().setAttachment(CatConstants.PIGEON_SERVER_MESSAGE_ID, serverMessageId);
	Cat.logEvent(CatConstants.TYPE_REMOTE_CALL, CatConstants.NAME_REQUEST, Transaction.SUCCESS, serverMessageId);
	Transaction t1 = Cat.newTransaction("调用远程Dubbo服务", "findAll");
	System.out.println("==========" +  (userService == null));
	String result = "Hello: " + name + userService.findAll().size();
	t1.setStatus(Transaction.SUCCESS);
	t1.complete();
	Cat.logEvent("Call", "DubboServer", Event.SUCCESS, "parentId:" + serverMessageId+ "|msgId:" +  serverMessageId + " End...");
	t.setStatus(Transaction.SUCCESS);
	t.complete();
	return result;
}
 
开发者ID:Percy0601,项目名称:training-cat,代码行数:29,代码来源:TrainingController.java

示例15: getSingleConnection

import com.dianping.cat.Cat; //导入方法依赖的package包/类
@Override
public SingleConnection getSingleConnection(SingleDataSource source, JdbcFilter chain) throws SQLException {
	try {
		return chain.getSingleConnection(source, chain);
	} catch (SQLException exp) {
		Transaction t = Cat.newTransaction("SQL", DaoContextHolder.getSqlName());

		Cat.logEvent("SQL.Database", source.getConfig().getJdbcUrl(), "ERROR", source.getConfig().getId());
		Cat.logError(exp);

		t.setStatus(exp);
		t.complete();
		throw exp;
	}
}
 
开发者ID:dianping,项目名称:zebra,代码行数:16,代码来源:CatFilter.java


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