KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > quartz > QuartzConnector


1 /*
2  * $Id: QuartzConnector.java 3982 2006-11-22 14:28:01Z lajos $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.providers.quartz;
12
13 import org.mule.config.i18n.Message;
14 import org.mule.config.i18n.Messages;
15 import org.mule.providers.AbstractServiceEnabledConnector;
16 import org.mule.umo.UMOException;
17 import org.mule.umo.lifecycle.InitialisationException;
18 import org.mule.umo.provider.ConnectorException;
19 import org.mule.util.ClassUtils;
20 import org.quartz.Scheduler;
21 import org.quartz.SchedulerFactory;
22 import org.quartz.impl.StdSchedulerFactory;
23
24 import java.util.Properties JavaDoc;
25
26 /**
27  * Creates a connection to a Quartz sheduler. This allows events to be sheduled at
28  * specific times, with repeated occurences.
29  */

30 public class QuartzConnector extends AbstractServiceEnabledConnector
31 {
32
33     public static final String JavaDoc PROPERTY_CRON_EXPRESSION = "cronExpression";
34     public static final String JavaDoc PROPERTY_REPEAT_INTERVAL = "repeatInterval";
35     public static final String JavaDoc PROPERTY_REPEAT_COUNT = "repeatCount";
36     public static final String JavaDoc PROPERTY_START_DELAY = "startDelay";
37     public static final String JavaDoc PROPERTY_PAYLOAD = "payload";
38     public static final String JavaDoc PROPERTY_JOB_DISPATCH_ENDPOINT = "jobDispatchEndpoint";
39     public static final String JavaDoc PROPERTY_JOB_RECEIVE_ENDPOINT = "jobReceiveEndpoint";
40     public static final String JavaDoc PROPERTY_JOB_RECEIVE_TIMEOUT = "jobReceiveTimeout";
41
42     /** deprecated: use PROPERTY_PAYLOAD_REFERENCE */
43     public static final String JavaDoc PROPERTY_PAYLOAD_CLASS_NAME = "payloadClassName";
44
45     public static final String JavaDoc PROPERTY_PAYLOAD_REFERENCE = "payloadRef";
46     public static final String JavaDoc PROPERTY_GROUP_NAME = "groupName";
47     public static final String JavaDoc PROPERTY_JOB_GROUP_NAME = "jobGroupName";
48     public static final String JavaDoc PROPERTY_JOB_REF = "jobRef";
49     public static final String JavaDoc PROPERTY_JOB_CLASS = "jobClass";
50     public static final String JavaDoc PROPERTY_JOB_OBJECT = "jobObject";
51
52     public static final String JavaDoc DEFAULT_GROUP_NAME = "mule";
53
54     private String JavaDoc factoryClassName = StdSchedulerFactory.class.getName();
55
56     private SchedulerFactory factory;
57
58     private Properties JavaDoc factoryProperties;
59
60     private Scheduler scheduler;
61
62     public String JavaDoc getProtocol()
63     {
64         return "quartz";
65     }
66
67     public void doInitialise() throws InitialisationException
68     {
69         super.doInitialise();
70         try
71         {
72             if (scheduler == null)
73             {
74                 if (factory == null)
75                 {
76                     Object JavaDoc[] args = null;
77                     if (factoryProperties != null)
78                     {
79                         args = new Object JavaDoc[]{factoryProperties};
80                     }
81                     factory = (SchedulerFactory)ClassUtils.instanciateClass(factoryClassName, args);
82                 }
83                 scheduler = factory.getScheduler();
84             }
85         }
86         catch (Exception JavaDoc e)
87         {
88             throw new InitialisationException(new Message(Messages.INITIALISATION_FAILURE_X,
89                 "Quartz provider"), e);
90         }
91     }
92
93     protected void doStart() throws UMOException
94     {
95         try
96         {
97             scheduler.start();
98         }
99         catch (Exception JavaDoc e)
100         {
101             throw new ConnectorException(new Message(Messages.FAILED_TO_START_X, "Quartz provider"), this, e);
102         }
103     }
104
105     protected void doStop() throws UMOException
106     {
107         try
108         {
109             if (scheduler != null)
110             {
111                 scheduler.shutdown();
112             }
113         }
114         catch (Exception JavaDoc e)
115         {
116             throw new ConnectorException(new Message(Messages.FAILED_TO_STOP_X, "Quartz provider"), this, e);
117         }
118     }
119
120     public SchedulerFactory getFactory()
121     {
122         return factory;
123     }
124
125     public void setFactory(SchedulerFactory factory)
126     {
127         this.factory = factory;
128     }
129
130     public Scheduler getScheduler()
131     {
132         return scheduler;
133     }
134
135     public void setScheduler(Scheduler scheduler)
136     {
137         this.scheduler = scheduler;
138     }
139
140     public String JavaDoc getFactoryClassName()
141     {
142         return factoryClassName;
143     }
144
145     public void setFactoryClassName(String JavaDoc factoryClassName)
146     {
147         this.factoryClassName = factoryClassName;
148     }
149
150     public Properties JavaDoc getFactoryProperties()
151     {
152         return factoryProperties;
153     }
154
155     public void setFactoryProperties(Properties JavaDoc factoryProperties)
156     {
157         this.factoryProperties = factoryProperties;
158     }
159
160 }
161
Popular Tags