1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.quartz;
12
13 import org.mule.api.MuleException;
14 import org.mule.api.lifecycle.InitialisationException;
15 import org.mule.api.transport.ConnectorException;
16 import org.mule.config.i18n.CoreMessages;
17 import org.mule.transport.AbstractConnector;
18
19 import java.util.Properties;
20
21 import org.quartz.Scheduler;
22 import org.quartz.SchedulerFactory;
23 import org.quartz.impl.StdSchedulerFactory;
24
25
26
27
28
29 public class QuartzConnector extends AbstractConnector
30 {
31
32 public static final String QUARTZ = "quartz";
33
34 public static final String PROPERTY_CRON_EXPRESSION = "cronExpression";
35 public static final String PROPERTY_REPEAT_INTERVAL = "repeatInterval";
36 public static final String PROPERTY_REPEAT_COUNT = "repeatCount";
37 public static final String PROPERTY_START_DELAY = "startDelay";
38 public static final String PROPERTY_PAYLOAD = "payload";
39
40 public static final String PROPERTY_JOB_CONFIG = "jobConfig";
41
42 public static final String PROPERTY_JOB_REF = "jobRef";
43 public static final String PROPERTY_JOB_OBJECT = "jobObject";
44
45 public static final String DEFAULT_GROUP_NAME = "mule";
46
47
48
49
50
51 private Properties factoryProperties = null;
52
53
54
55
56
57 private Scheduler quartzScheduler = null;
58
59 protected void doInitialise() throws InitialisationException
60 {
61 try
62 {
63 if (quartzScheduler == null)
64 {
65 if (factoryProperties != null)
66 {
67 SchedulerFactory factory = new StdSchedulerFactory(factoryProperties);
68 quartzScheduler = factory.getScheduler();
69 }
70 else
71 {
72 quartzScheduler = StdSchedulerFactory.getDefaultScheduler();
73 }
74 }
75 }
76 catch (Exception e)
77 {
78 throw new InitialisationException(CoreMessages.initialisationFailure("Quartz provider"), e, this);
79 }
80 }
81
82 protected void doDispose()
83 {
84
85 }
86
87 protected void doConnect() throws Exception
88 {
89
90 }
91
92 protected void doDisconnect() throws Exception
93 {
94
95 }
96
97 protected void doStart() throws MuleException
98 {
99 try
100 {
101 quartzScheduler.start();
102 }
103 catch (Exception e)
104 {
105 throw new ConnectorException(CoreMessages.failedToStart("Quartz provider"), this, e);
106 }
107 }
108
109 protected void doStop() throws MuleException
110 {
111 try
112 {
113 if (quartzScheduler != null)
114 {
115 quartzScheduler.shutdown();
116 }
117 }
118 catch (Exception e)
119 {
120 throw new ConnectorException(CoreMessages.failedToStop("Quartz provider"), this, e);
121 }
122 }
123
124 public String getProtocol()
125 {
126 return QUARTZ;
127 }
128
129 public Scheduler getQuartzScheduler()
130 {
131 return quartzScheduler;
132 }
133
134 public void setQuartzScheduler(Scheduler scheduler)
135 {
136 this.quartzScheduler = scheduler;
137 }
138
139 public Properties getFactoryProperties()
140 {
141 return factoryProperties;
142 }
143
144 public void setFactoryProperties(Properties factoryProperties)
145 {
146 this.factoryProperties = factoryProperties;
147 }
148
149 }