<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:spring="http://www.springframework.org/schema/beans"
       xmlns:quartz="http://www.mulesource.org/schema/mule/quartz/2.0"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://www.mulesource.org/schema/mule/core/2.0 http://www.mulesource.org/schema/mule/core/2.0/mule.xsd
       http://www.mulesource.org/schema/mule/quartz/2.0 http://www.mulesource.org/schema/mule/quartz/2.0/mule-quartz.xsd">

    <!-- Default config -->
    <quartz:connector name="quartzConnectorDefaults"/>

    <!-- Inject the scheduler as a bean. -->
    <quartz:connector name="quartzConnector1" scheduler-ref="myScheduler"/>

    <spring:bean id="myScheduler" factory-bean="mySchedulerFactory" factory-method="getScheduler"/>

    <spring:bean id="mySchedulerFactory" class="org.quartz.impl.StdSchedulerFactory">
        <spring:constructor-arg>
            <spring:props>
                <spring:prop key="org.quartz.scheduler.instanceName">MuleScheduler1</spring:prop>
                <spring:prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</spring:prop>
                <spring:prop key="org.quartz.threadPool.threadCount">3</spring:prop>
                <spring:prop key="org.quartz.scheduler.rmi.export">false</spring:prop>
                <spring:prop key="org.quartz.scheduler.rmi.proxy">false</spring:prop>
                <spring:prop key="org.quartz.jobStore.class">org.quartz.simpl.RAMJobStore</spring:prop>
            </spring:props>
        </spring:constructor-arg>
    </spring:bean>

    <!-- Default config but provide some factory properties. -->
    <quartz:connector name="quartzConnector2">
        <quartz:factory-property key="org.quartz.scheduler.instanceName" value="MuleScheduler2"/>
        <quartz:factory-property key="org.quartz.threadPool.class" value="org.quartz.simpl.SimpleThreadPool"/>
        <quartz:factory-property key="org.quartz.threadPool.threadCount" value="3"/>
        <quartz:factory-property key="org.quartz.scheduler.rmi.export" value="false"/>
        <quartz:factory-properties>
            <!-- this allows more complex values to be constructed via spring -->
            <spring:entry key="org.quartz.scheduler.rmi.proxy" value="false"/>
            <spring:entry key="org.quartz.jobStore.class" value="org.quartz.simpl.RAMJobStore"/>
        </quartz:factory-properties>
    </quartz:connector>

    <endpoint name="scheduledDispatchEndpoint" address="vm://bar"/>
    

    <quartz:endpoint name="qEP1" cronExpression="3 * * * *" jobName="job" connector-ref="quartzConnector1">
        <quartz:event-generator-job >
            <quartz:payload>foo</quartz:payload>
        </quartz:event-generator-job>
    </quartz:endpoint>

    <quartz:endpoint name="qEP2" repeatCount="10" repeatInterval="1000" jobName="job" connector-ref="quartzConnector1">
        <quartz:event-generator-job groupName="fooGroup" jobGroupName="fooJobGroup">
            <quartz:payload file="payload-data.txt"/>
        </quartz:event-generator-job>
    </quartz:endpoint>

    <quartz:endpoint name="qEP3" repeatCount="10" repeatInterval="1000" jobName="job" connector-ref="quartzConnector1">
        <quartz:custom-job-from-message evaluator="header" expression="jobConfig"/>
    </quartz:endpoint>

    <quartz:endpoint name="qEP4" repeatCount="10" repeatInterval="1000" jobName="job" connector-ref="quartzConnector1">
        <quartz:custom-job job-ref="custJob"/>
    </quartz:endpoint>

    <quartz:endpoint name="qEP5" repeatCount="10" repeatInterval="1000" jobName="job" connector-ref="quartzConnector1">
        <quartz:endpoint-polling-job>
            <quartz:job-endpoint address="vm://foo" timeout="4000"/>
        </quartz:endpoint-polling-job>
    </quartz:endpoint>

    <quartz:endpoint name="qEP6" repeatCount="10" repeatInterval="1000" jobName="job" connector-ref="quartzConnector1">
        <quartz:scheduled-dispatch-job>
            <quartz:job-endpoint ref="scheduledDispatchEndpoint"/>
        </quartz:scheduled-dispatch-job>
    </quartz:endpoint>

    <spring:bean name="custJob" class="org.mule.transport.quartz.jobs.EventGeneratorJob"/>
</mule>
