<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
       default-autowire="byName">
       
    <!-- 非分布式模式 -->
    <bean id="jvmQuartzScheduler" name="jvmQuartzScheduler" lazy-init="false" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="quartzProperties">
            <props>
                <prop key="org.quartz.scheduler.instanceName">cachecloudJvmScheduler</prop>
                <prop key="org.quartz.jobStore.class">org.quartz.simpl.RAMJobStore</prop>
                <prop key="org.quartz.scheduler.instanceId">AUTO</prop>
                <prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
                <prop key="org.quartz.threadPool.threadCount">10</prop>
                <prop key="org.quartz.threadPool.threadPriority">5</prop>
                <prop key="org.quartz.scheduler.jmx.export">true</prop>
                <prop key="org.quartz.plugin.shutdownHook.class">org.quartz.plugins.management.ShutdownHookPlugin</prop>
                <prop key="org.quartz.plugin.shutdownHook.cleanShutdown">true</prop>
                <prop key="org.quartz.plugin.triggHistory.class">org.quartz.plugins.history.LoggingJobHistoryPlugin
                </prop>
            </props>
        </property>
        <property name="startupDelay" value="10"/>
        <property name="applicationContextSchedulerContextKey" value="applicationContext"/>
        <property name="overwriteExistingJobs" value="true"/>
        <property name="autoStartup" value="true"/>

        <property name="triggers">
            <array>
                <ref bean="errorStatisticsTrigger"/>
                <ref bean="systemConfigRefreshTrigger"/>
            </array>
        </property>

        <property name="jobDetails">
            <array>
                <ref bean="errorStatisticsJobDetail"/>
                <ref bean="systemConfigRefreshJobDetail"/>
            </array>
        </property>
    </bean>
    

    <!-- quartz线程池 -->
    <bean id="quartzThreadPool" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
        <!-- 核心线程数  -->
        <property name="corePoolSize" value="100"/>
        <!-- 最大线程数 -->
        <property name="maxPoolSize" value="200"/>
        <!-- 队列最大长度 >=mainExecutor.maxSize -->
        <property name="queueCapacity" value="10"/>
        <!-- 线程池维护线程所允许的空闲时间 -->
        <property name="keepAliveSeconds" value="300"/>
        <!-- 拒绝任务策略:被拒绝后直接在调用者线程中运行当前被放弃任务 -->
        <property name="rejectedExecutionHandler">
            <bean class="java.util.concurrent.ThreadPoolExecutor$AbortPolicy"/>
        </property>
    </bean>
 
    <!-- 分布式QuartzScheduler -->
    <bean id="clusterScheduler" name="clusterScheduler" lazy-init="false" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="dataSource" ref="cacheCloudDB"></property>
        <property name="taskExecutor" ref="quartzThreadPool"/>
        <!--
        <property name="transactionManager" ref="transactionManager"/>
        -->
        <property name="quartzProperties">
            <props>
                <prop key="org.quartz.scheduler.instanceName">CacheCloudScheduler</prop>
                <prop key="org.quartz.scheduler.instanceId">AUTO</prop>
                <prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
                <prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop>
                <!-- 表名前缀 -->
                <prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
                <prop key="org.quartz.jobStore.isClustered">${isClustered}</prop>
                <prop key="org.quartz.jobStore.clusterCheckinInterval">15000</prop>
                <prop key="org.quartz.jobStore.maxMisfiresToHandleAtATime">120</prop>
                <prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
                <!-- 打开JMX 配置 -->
                <prop key="org.quartz.scheduler.jmx.export">true</prop>
                <prop key="org.quartz.plugin.shutdownHook.class">org.quartz.plugins.management.ShutdownHookPlugin</prop>
                <prop key="org.quartz.plugin.shutdownHook.cleanShutdown">true</prop>
                <prop key="org.terracotta.quartz.skipUpdateCheck">true</prop>
                <!--<prop key="org.quartz.plugin.triggHistory.class">org.quartz.plugins.history.LoggingJobHistoryPlugin</prop>-->

            </props>
        </property>
        <property name="schedulerName" value="CacheCloudScheduler"/>
        <property name="applicationContextSchedulerContextKey" value="applicationContext"/>
        <property name="overwriteExistingJobs" value="true"/>
        <property name="waitForJobsToCompleteOnShutdown" value="false"/>
        <property name="startupDelay" value="10"/>
        <property name="autoStartup" value="true"/>
        <property name="triggers">
            <array>
                <ref bean="cleanUpStatisticsTrigger"/>
                <ref bean="hostInspectorTrigger"/>
                <ref bean="appInspectorTrigger"/>
                <ref bean="appDailyTrigger"/>
            </array>
        </property>
        <property name="jobDetails">
            <array>
                <ref bean="redisJobDetail"/>
                <ref bean="machineJobDetail"/>
                <ref bean="serverJobDetail"/>
                <ref bean="machineMonitorJobDetail"/>
                <ref bean="redisSlowLogJobDetail"/>
                <ref bean="cleanUpStatisticsJobDetail"/>
                <ref bean="inspectorJobDetail"/>
                <ref bean="appDailyJobDetail"/>
            </array>
        </property>

    </bean>

    <bean id="redisJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
        <property name="name" value="redisJob"></property>
        <property name="group" value="redis"></property>
        <property name="jobClass" value="com.sohu.cache.schedule.jobs.RedisJob"></property>
        <property name="requestsRecovery" value="true"/>
        <property name="durability" value="true"/>
    </bean>

    <bean id="machineJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
        <property name="name" value="machineJob"/>
        <property name="group" value="machine"/>
        <property name="jobClass" value="com.sohu.cache.schedule.jobs.MachineJob"/>
        <property name="requestsRecovery" value="true"/>
        <property name="durability" value="true"/>
    </bean>
    <bean id="serverJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
        <property name="name" value="serverJob"/>
        <property name="group" value="server"/>
        <property name="jobClass" value="com.sohu.cache.schedule.jobs.ServerJob"/>
        <property name="requestsRecovery" value="true"/>
        <property name="durability" value="true"/>
    </bean>

    <bean id="machineMonitorJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
        <property name="name" value="machineMonitorJob"/>
        <property name="group" value="machineMonitor"/>
        <property name="jobClass" value="com.sohu.cache.schedule.jobs.MachineMonitorJob"/>
        <property name="requestsRecovery" value="true"/>
        <property name="durability" value="true"/>
    </bean>
    
    <bean id="redisSlowLogJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
        <property name="name" value="redisSlowLogJob"/>
        <property name="group" value="redisSlowLog"/>
        <property name="jobClass" value="com.sohu.cache.schedule.jobs.RedisSlowLogJob"/>
        <property name="requestsRecovery" value="true"/>
        <property name="durability" value="true"/>
    </bean>
    
    <bean id="cleanUpStatisticsJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
        <property name="name" value="cleanUpStatisticsJobDetail"></property>
        <property name="group" value="cleanUpStatisticsGroup"></property>
        <property name="jobClass" value="com.sohu.cache.schedule.jobs.CleanUpStatisticsJob"></property>
        <property name="durability" value="true" />
    </bean>

    <bean id="errorStatisticsJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
        <property name="name" value="errorStatisticsJobDetail"></property>
        <property name="group" value="errorStatisticsGroup"></property>
        <property name="jobClass" value="com.sohu.cache.schedule.jobs.ErrorStatisticsJob"></property>
        <property name="durability" value="true" />
    </bean>

    <bean id="cleanUpStatisticsTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="name" value="cleanUpStatisticsTrigger"/>
        <property name="group" value="cleanUp"/>
        <property name="jobDetail" ref="cleanUpStatisticsJobDetail"/>
        <!-- 每天执行一次 -->
        <property name="cronExpression" value="0 0 12 * * ?"/>
    </bean>

    <bean id="inspectorJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
        <property name="name" value="inspectorJob"></property>
        <property name="group" value="inspector"></property>
        <property name="jobClass" value="com.sohu.cache.inspect.InspectorJob"></property>
        <property name="requestsRecovery" value="true"/>
        <property name="durability" value="true"/>
    </bean>

    <bean id="hostInspectorTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="name" value="hostInspectorTrigger"/>
        <property name="group" value="inspector"/>
        <property name="jobDetail" ref="inspectorJobDetail"/>
        <!-- 5分钟执行一次 -->
        <property name="cronExpression" value="0 0/5 * ? * *"/>
        <property name="jobDataAsMap">
            <map>
                <entry key="inspectorType" value="host"/>
            </map>
        </property>
    </bean>

    <bean id="appInspectorTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="name" value="appInspectorTrigger"/>
        <property name="group" value="inspector"/>
        <property name="jobDetail" ref="inspectorJobDetail"/>
        <!-- 20分钟执行一次 -->
        <property name="cronExpression" value="0 0/20 * ? * *"/>
        <property name="jobDataAsMap">
            <map>
                <entry key="inspectorType" value="app"/>
            </map>
        </property>
    </bean>
    
    <bean id="errorStatisticsTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="name" value="errorStatisticsTrigger"/>
        <property name="group" value="errorStatisticsGroup"/>
        <property name="jobDetail" ref="errorStatisticsJobDetail"/>
        <property name="cronExpression" value="0 0 10 * * ?"/>
    </bean>
    
    <bean id="systemConfigRefreshJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
        <property name="name" value="systemConfigRefreshJobDetail"></property>
        <property name="group" value="systemConfigRefreshGroup"></property>
        <property name="jobClass" value="com.sohu.cache.schedule.jobs.SystemConfigRefreshJob"></property>
        <property name="durability" value="true" />
    </bean>
    
    <bean id="systemConfigRefreshTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="name" value="systemConfigRefreshTrigger"/>
        <property name="group" value="systemConfigRefreshGroup"/>
        <property name="jobDetail" ref="systemConfigRefreshJobDetail"/>
        <property name="cronExpression" value="0/30 * * ? * *"/>
    </bean>
    
    
    <bean id="appDailyJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
        <property name="name" value="appDailyJob"></property>
        <property name="group" value="appDaily"></property>
        <property name="jobClass" value="com.sohu.cache.schedule.jobs.AppDailyJob"></property>
        <property name="requestsRecovery" value="true"/>
        <property name="durability" value="true"/>
    </bean>

    <bean id="appDailyTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="name" value="appDailyTrigger"/>
        <property name="group" value="appDaily"/>
        <property name="jobDetail" ref="appDailyJobDetail"/>
        <property name="cronExpression" value="0 0 10 * * ?"/>
    </bean>
    
    

</beans>
