Search in sources :

Example 1 with RedisCenter

use of com.sohu.cache.redis.RedisCenter in project cachecloud by sohutv.

the class RedisSlowLogJob method action.

@Override
public void action(JobExecutionContext context) {
    try {
        SchedulerContext schedulerContext = context.getScheduler().getContext();
        ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY);
        RedisCenter redisCenter = (RedisCenter) applicationContext.getBean("redisCenter");
        JobDataMap dataMap = context.getMergedJobDataMap();
        String host = dataMap.getString(ConstUtils.HOST_KEY);
        int port = dataMap.getInt(ConstUtils.PORT_KEY);
        long appId = dataMap.getLong(ConstUtils.APP_KEY);
        Trigger trigger = context.getTrigger();
        long collectTime = ScheduleUtil.getCollectTime(trigger.getPreviousFireTime());
        redisCenter.collectRedisSlowLog(appId, collectTime, host, port);
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) JobDataMap(org.quartz.JobDataMap) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException) RedisCenter(com.sohu.cache.redis.RedisCenter) SchedulerContext(org.quartz.SchedulerContext) SchedulerException(org.quartz.SchedulerException)

Example 2 with RedisCenter

use of com.sohu.cache.redis.RedisCenter in project cachecloud by sohutv.

the class RedisJob method action.

/**
     * 实现收集任务,通过RedisCenter
     *
     * @param context
     */
@Override
public void action(JobExecutionContext context) {
    JobDataMap dataMap = new JobDataMap();
    try {
        SchedulerContext schedulerContext = context.getScheduler().getContext();
        ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY);
        RedisCenter redisCenter = (RedisCenter) applicationContext.getBean("redisCenter");
        dataMap = context.getMergedJobDataMap();
        String host = dataMap.getString(ConstUtils.HOST_KEY);
        int port = dataMap.getInt(ConstUtils.PORT_KEY);
        long appId = dataMap.getLong(ConstUtils.APP_KEY);
        Trigger trigger = context.getTrigger();
        long collectTime = ScheduleUtil.getCollectTime(trigger.getPreviousFireTime());
        redisCenter.collectRedisInfo(appId, collectTime, host, port);
    } catch (SchedulerException e) {
        logger.error("host: {}, appId: {}", dataMap.get(ConstUtils.HOST_KEY), dataMap.get(ConstUtils.APP_KEY));
        logger.error("port: {}", dataMap.get(ConstUtils.PORT_KEY));
        logger.error(e.getMessage(), e);
    } catch (Exception e) {
        logger.error("host: {}, appId: {}", dataMap.get(ConstUtils.HOST_KEY), dataMap.get(ConstUtils.APP_KEY));
        logger.error("port: {}", dataMap.get(ConstUtils.PORT_KEY));
        logger.error(e.getMessage(), e);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) ApplicationContext(org.springframework.context.ApplicationContext) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException) RedisCenter(com.sohu.cache.redis.RedisCenter) SchedulerContext(org.quartz.SchedulerContext) SchedulerException(org.quartz.SchedulerException)

Aggregations

RedisCenter (com.sohu.cache.redis.RedisCenter)2 JobDataMap (org.quartz.JobDataMap)2 SchedulerContext (org.quartz.SchedulerContext)2 SchedulerException (org.quartz.SchedulerException)2 Trigger (org.quartz.Trigger)2 ApplicationContext (org.springframework.context.ApplicationContext)2