1 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 ; 25 26 30 public class QuartzConnector extends AbstractServiceEnabledConnector 31 { 32 33 public static final String PROPERTY_CRON_EXPRESSION = "cronExpression"; 34 public static final String PROPERTY_REPEAT_INTERVAL = "repeatInterval"; 35 public static final String PROPERTY_REPEAT_COUNT = "repeatCount"; 36 public static final String PROPERTY_START_DELAY = "startDelay"; 37 public static final String PROPERTY_PAYLOAD = "payload"; 38 public static final String PROPERTY_JOB_DISPATCH_ENDPOINT = "jobDispatchEndpoint"; 39 public static final String PROPERTY_JOB_RECEIVE_ENDPOINT = "jobReceiveEndpoint"; 40 public static final String PROPERTY_JOB_RECEIVE_TIMEOUT = "jobReceiveTimeout"; 41 42 43 public static final String PROPERTY_PAYLOAD_CLASS_NAME = "payloadClassName"; 44 45 public static final String PROPERTY_PAYLOAD_REFERENCE = "payloadRef"; 46 public static final String PROPERTY_GROUP_NAME = "groupName"; 47 public static final String PROPERTY_JOB_GROUP_NAME = "jobGroupName"; 48 public static final String PROPERTY_JOB_REF = "jobRef"; 49 public static final String PROPERTY_JOB_CLASS = "jobClass"; 50 public static final String PROPERTY_JOB_OBJECT = "jobObject"; 51 52 public static final String DEFAULT_GROUP_NAME = "mule"; 53 54 private String factoryClassName = StdSchedulerFactory.class.getName(); 55 56 private SchedulerFactory factory; 57 58 private Properties factoryProperties; 59 60 private Scheduler scheduler; 61 62 public String 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 [] args = null; 77 if (factoryProperties != null) 78 { 79 args = new Object []{factoryProperties}; 80 } 81 factory = (SchedulerFactory)ClassUtils.instanciateClass(factoryClassName, args); 82 } 83 scheduler = factory.getScheduler(); 84 } 85 } 86 catch (Exception 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 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 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 getFactoryClassName() 141 { 142 return factoryClassName; 143 } 144 145 public void setFactoryClassName(String factoryClassName) 146 { 147 this.factoryClassName = factoryClassName; 148 } 149 150 public Properties getFactoryProperties() 151 { 152 return factoryProperties; 153 } 154 155 public void setFactoryProperties(Properties factoryProperties) 156 { 157 this.factoryProperties = factoryProperties; 158 } 159 160 } 161 | Popular Tags |