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 | 82 | 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 | 82 | private Properties factoryProperties = null; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | 82 | private Scheduler quartzScheduler = null; |
58 | |
|
59 | |
protected void doInitialise() throws InitialisationException |
60 | |
{ |
61 | |
try |
62 | |
{ |
63 | 82 | if (quartzScheduler == null) |
64 | |
{ |
65 | 64 | if (factoryProperties != null) |
66 | |
{ |
67 | 18 | SchedulerFactory factory = new StdSchedulerFactory(factoryProperties); |
68 | 18 | quartzScheduler = factory.getScheduler(); |
69 | 18 | } |
70 | |
else |
71 | |
{ |
72 | 46 | quartzScheduler = StdSchedulerFactory.getDefaultScheduler(); |
73 | |
} |
74 | |
} |
75 | |
} |
76 | 0 | catch (Exception e) |
77 | |
{ |
78 | 0 | throw new InitialisationException(CoreMessages.initialisationFailure("Quartz provider"), e, this); |
79 | 82 | } |
80 | 82 | } |
81 | |
|
82 | |
protected void doDispose() |
83 | |
{ |
84 | |
|
85 | 98 | } |
86 | |
|
87 | |
protected void doConnect() throws Exception |
88 | |
{ |
89 | |
|
90 | 82 | } |
91 | |
|
92 | |
protected void doDisconnect() throws Exception |
93 | |
{ |
94 | |
|
95 | 82 | } |
96 | |
|
97 | |
protected void doStart() throws MuleException |
98 | |
{ |
99 | |
try |
100 | |
{ |
101 | 82 | quartzScheduler.start(); |
102 | |
} |
103 | 0 | catch (Exception e) |
104 | |
{ |
105 | 0 | throw new ConnectorException(CoreMessages.failedToStart("Quartz provider"), this, e); |
106 | 82 | } |
107 | 82 | } |
108 | |
|
109 | |
protected void doStop() throws MuleException |
110 | |
{ |
111 | |
try |
112 | |
{ |
113 | 82 | if (quartzScheduler != null) |
114 | |
{ |
115 | 82 | quartzScheduler.shutdown(); |
116 | |
} |
117 | |
} |
118 | 0 | catch (Exception e) |
119 | |
{ |
120 | 0 | throw new ConnectorException(CoreMessages.failedToStop("Quartz provider"), this, e); |
121 | 82 | } |
122 | 82 | } |
123 | |
|
124 | |
public String getProtocol() |
125 | |
{ |
126 | 190 | return QUARTZ; |
127 | |
} |
128 | |
|
129 | |
public Scheduler getQuartzScheduler() |
130 | |
{ |
131 | 84 | return quartzScheduler; |
132 | |
} |
133 | |
|
134 | |
public void setQuartzScheduler(Scheduler scheduler) |
135 | |
{ |
136 | 18 | this.quartzScheduler = scheduler; |
137 | 18 | } |
138 | |
|
139 | |
public Properties getFactoryProperties() |
140 | |
{ |
141 | 0 | return factoryProperties; |
142 | |
} |
143 | |
|
144 | |
public void setFactoryProperties(Properties factoryProperties) |
145 | |
{ |
146 | 18 | this.factoryProperties = factoryProperties; |
147 | 18 | } |
148 | |
|
149 | |
} |