Search in sources :

Example 6 with SchedulerContext

use of org.quartz.SchedulerContext in project cachecloud by sohutv.

the class MachineMonitorJob method action.

@Override
public void action(JobExecutionContext context) {
    try {
        JobDataMap dataMap = context.getMergedJobDataMap();
        String ip = dataMap.getString(ConstUtils.HOST_KEY);
        long hostId = dataMap.getLong(ConstUtils.HOST_ID_KEY);
        SchedulerContext schedulerContext = context.getScheduler().getContext();
        ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY);
        MachineCenter machineCenter = applicationContext.getBean("machineCenter", MachineCenter.class);
        machineCenter.asyncMonitorMachineStats(hostId, ip);
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) ApplicationContext(org.springframework.context.ApplicationContext) MachineCenter(com.sohu.cache.machine.MachineCenter) SchedulerException(org.quartz.SchedulerException) SchedulerContext(org.quartz.SchedulerContext)

Example 7 with SchedulerContext

use of org.quartz.SchedulerContext 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 8 with SchedulerContext

use of org.quartz.SchedulerContext in project cachecloud by sohutv.

the class SystemConfigRefreshJob method action.

@Override
public void action(JobExecutionContext context) {
    try {
        SchedulerContext schedulerContext = context.getScheduler().getContext();
        ApplicationContext applicationContext = (ApplicationContext) schedulerContext.get(APPLICATION_CONTEXT_KEY);
        ConfigService configService = applicationContext.getBean("configService", ConfigService.class);
        configService.reloadSystemConfig();
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ConfigService(com.sohu.cache.web.service.ConfigService) SchedulerException(org.quartz.SchedulerException) SchedulerContext(org.quartz.SchedulerContext)

Example 9 with SchedulerContext

use of org.quartz.SchedulerContext in project camel by apache.

the class ScheduledJob method execute.

public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    SchedulerContext schedulerContext;
    try {
        schedulerContext = jobExecutionContext.getScheduler().getContext();
    } catch (SchedulerException e) {
        throw new JobExecutionException("Failed to obtain scheduler context for job " + jobExecutionContext.getJobDetail().getName());
    }
    ScheduledJobState state = (ScheduledJobState) schedulerContext.get(jobExecutionContext.getJobDetail().getName());
    Action storedAction = state.getAction();
    Route storedRoute = state.getRoute();
    List<RoutePolicy> policyList = storedRoute.getRouteContext().getRoutePolicyList();
    for (RoutePolicy policy : policyList) {
        try {
            if (policy instanceof ScheduledRoutePolicy) {
                ((ScheduledRoutePolicy) policy).onJobExecute(storedAction, storedRoute);
            }
        } catch (Exception e) {
            throw new JobExecutionException("Failed to execute Scheduled Job for route " + storedRoute.getId() + " with trigger name: " + jobExecutionContext.getTrigger().getFullName(), e);
        }
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) JobExecutionException(org.quartz.JobExecutionException) SchedulerContext(org.quartz.SchedulerContext) RoutePolicy(org.apache.camel.spi.RoutePolicy) Route(org.apache.camel.Route) JobExecutionException(org.quartz.JobExecutionException) SchedulerException(org.quartz.SchedulerException)

Example 10 with SchedulerContext

use of org.quartz.SchedulerContext in project camel by apache.

the class ScheduledJob method execute.

public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    LOG.debug("Running ScheduledJob: jobExecutionContext={}", jobExecutionContext);
    SchedulerContext schedulerContext = getSchedulerContext(jobExecutionContext);
    ScheduledJobState state = (ScheduledJobState) schedulerContext.get(jobExecutionContext.getJobDetail().getKey().toString());
    Action storedAction = state.getAction();
    Route storedRoute = state.getRoute();
    List<RoutePolicy> policyList = storedRoute.getRouteContext().getRoutePolicyList();
    for (RoutePolicy policy : policyList) {
        try {
            if (policy instanceof ScheduledRoutePolicy) {
                ((ScheduledRoutePolicy) policy).onJobExecute(storedAction, storedRoute);
            }
        } catch (Exception e) {
            throw new JobExecutionException("Failed to execute Scheduled Job for route " + storedRoute.getId() + " with trigger name: " + jobExecutionContext.getTrigger().getKey(), e);
        }
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) SchedulerContext(org.quartz.SchedulerContext) RoutePolicy(org.apache.camel.spi.RoutePolicy) Route(org.apache.camel.Route) JobExecutionException(org.quartz.JobExecutionException) SchedulerException(org.quartz.SchedulerException)

Aggregations

SchedulerContext (org.quartz.SchedulerContext)18 SchedulerException (org.quartz.SchedulerException)12 ApplicationContext (org.springframework.context.ApplicationContext)10 JobDataMap (org.quartz.JobDataMap)5 JobExecutionException (org.quartz.JobExecutionException)4 Date (java.util.Date)3 Trigger (org.quartz.Trigger)3 MachineCenter (com.sohu.cache.machine.MachineCenter)2 RedisCenter (com.sohu.cache.redis.RedisCenter)2 SimpleDateFormat (java.text.SimpleDateFormat)2 CamelContext (org.apache.camel.CamelContext)2 Route (org.apache.camel.Route)2 RoutePolicy (org.apache.camel.spi.RoutePolicy)2 ClientReportCostDistriService (com.sohu.cache.client.service.ClientReportCostDistriService)1 ClientReportValueDistriService (com.sohu.cache.client.service.ClientReportValueDistriService)1 ErrorLoggerWatcherMBean (com.sohu.cache.jmx.ErrorLoggerWatcherMBean)1 AppDailyDataCenter (com.sohu.cache.stats.app.AppDailyDataCenter)1 InstanceAlertValueService (com.sohu.cache.stats.instance.InstanceAlertValueService)1 InstanceStatsCenter (com.sohu.cache.stats.instance.InstanceStatsCenter)1 EmailComponent (com.sohu.cache.web.component.EmailComponent)1