PerformanceTask

public class PerformanceTask
{
    /**
     * 调测日志记录器。
     */
    private static Logger logger = Logger.getLogger(PerformanceTask.class);


    /**
     * 发送失败重试
     */
    private static final int RETRYTIME = 3;
    
    /**
     * PortalStartProcessID
     */
    private static final int PORTALSTARTPROCESSID = 300;
    
    /**
     * PortalEndProcessID
     */
    private static final int PORTALENDPROCESSID = 600;
    
    
    /**
     * 性能统计类-业务性能
     */
    private Performance performance = null;


    /**
     * 性能统计类-系统性能
     */
    private SystemPerformance systemPerformance = null;


    /**
     * 数据汇集客户端
     */
    private DataCollectClient dataCollectClient = null;


    /**
     * 数据汇集的JavaBean-业务性能汇聚
     */
    private DataCollect dataCollectPerformance = null;


    /**
     * 数据汇集的JavaBean-系统性能汇聚
     */
    private DataCollect dataCollectSystemPerformance = null;


    /**
     * 系统话筒发送对象
     */
    private SystemPerformance sendSystemPerformance = new SystemPerformance();


    /**
     * 话筒客户端发送数据函数。 如果三次都失败,则继续统计,
     * 不初始化统计数据。下个发送周期在发送
     * 
     */
    public void sendMessageOnTime()
    {
        logger.recordEnterMethodLog();


        if (null == dataCollectClient)
        {
            dataCollectClient = new DataCollectClientImpl();
        }
        //发送业务性能数据方法
        sendPerformanceData();


        if ((CommonProcess.getProcessID() < PORTALENDPROCESSID) 
                && (CommonProcess.getProcessID() > PORTALSTARTPROCESSID))
        {
            sendSystemPerformanceData();
        }


        logger.recordExitMethodLog();
    }


    /**
     * 发送业务性能信息
     * 
     */
    private void sendPerformanceData()
    {
        logger.recordEnterMethodLog();
        if (null == performance)
        {
            // 根据performance从spring中获取性能对象
            performance = (Performance) ContextRegistry.getContextHolder().getBean("performance");
            if (null != performance)
            {
                // 获取框槽号需要等系统参数刷新之后,所以需要在此处赋值。
                performance.setPortalServerId(CommonProcess.getSubRackNumber()
                        + "-" + CommonProcess.getSlotNumber() + "-"
                        + CommonProcess.getProcessID());
            }
        }


        if (null == dataCollectPerformance)
        {
            dataCollectPerformance = new DataCollect(PortalCommonConst.PERFORMANCE_MSG_ID, performance);
        }


        if (null != performance)
        {
            int result = ErrorCodeDecode.SUCCESS;
            long lonTIme = 0;
            Timestamp ts = null;
            
            // 向服务端发送统计到的话筒数据,发送失败重试,重试三次,
            // 如果三次重试都失败,继续统计,不初始化统计数据,下个发送周期再发送。
            for (int i = 0; i < RETRYTIME; i++)
            {
                // 设置业务性能记录时间为系统当前时间
                lonTIme = CommonProcess.getCurTimeByZone();
                ts = new Timestamp(lonTIme);
                
                performance.setPerformanceDateTime(ts);
                dataCollectPerformance.setObject(performance);
                // 客户端发送信息
                result = dataCollectClient.sendMessage(dataCollectPerformance);
                if (ErrorCodeDecode.SUCCESS == result)
                {
                    performance.init();
                    break;
                }
            }
        }
        else
        {
            logger.recordErrorsLog("Performance is empty");
        }


        logger.recordExitMethodLog();
    }


    /**
     * 发送系统性能信息
     * 
     */
    private void sendSystemPerformanceData()
    {
        logger.recordEnterMethodLog();


        if (null == systemPerformance)
        {
            // 根据sysPerformance从spring中获取系统性能对象
            systemPerformance = (SystemPerformance) ContextRegistry.getContextHolder().getBean("systemPerformance");
        }
        
        //为发送的系统性能对象赋值
        systemPerformance.getAvgSystemPerform(sendSystemPerformance);


        if (null == dataCollectSystemPerformance)
        {
            dataCollectSystemPerformance = new DataCollect(PortalCommonConst.SYSTEM_PERFORMANCE_MSG_ID, 
                    sendSystemPerformance);
        }


        if (sendSystemPerformance.checkData())
        {
            int resultPerformance = ErrorCodeDecode.SUCCESS;
            long lonTIme = 0;
            Timestamp ts = null;
            
            // 向服务端发送统计到的话筒数据,发送失败重试,重试三次,
            // 如果三次重试都失败,继续统计,不初始化统计数据,下个发送周期再发送。
            for (int i = 0; i < RETRYTIME; i++)
            {
                lonTIme = CommonProcess.getCurTimeByZone();
                ts = new Timestamp(lonTIme);
                logger.recordDebugLog("Long current time is " + lonTIme);
                logger.recordDebugLog("Current time is " + ts);


                sendSystemPerformance.setSystemPerformanceDateTime(ts);
                dataCollectSystemPerformance.setObject(sendSystemPerformance);
                // 客户端发送信息
                resultPerformance = dataCollectClient.sendMessage(dataCollectSystemPerformance);
                if (ErrorCodeDecode.SUCCESS == resultPerformance)
                {
                    systemPerformance.init();
                    break;
                }
            }
        }
        else
        {
            logger.recordErrorsLog("systemPerformance is empty");
        }


        logger.recordExitMethodLog();
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值