Coverage Report - org.mule.providers.quartz.QuartzConnector
 
Classes in this File Line Coverage Branch Coverage Complexity
QuartzConnector
0%
0/40
0%
0/5
1.667
 
 1  
 /*
 2  
  * $Id: QuartzConnector.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 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 CPAL v1.0
 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.CoreMessages;
 14  
 import org.mule.providers.AbstractConnector;
 15  
 import org.mule.umo.UMOException;
 16  
 import org.mule.umo.lifecycle.InitialisationException;
 17  
 import org.mule.umo.provider.ConnectorException;
 18  
 import org.mule.util.ClassUtils;
 19  
 
 20  
 import java.util.Properties;
 21  
 
 22  
 import org.quartz.Scheduler;
 23  
 import org.quartz.SchedulerFactory;
 24  
 import org.quartz.impl.StdSchedulerFactory;
 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  0
 public class QuartzConnector extends AbstractConnector
 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  
     /** deprecated: use PROPERTY_PAYLOAD_REFERENCE */
 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  0
     private String factoryClassName = StdSchedulerFactory.class.getName();
 55  
 
 56  
     private SchedulerFactory factory;
 57  
 
 58  
     private Properties factoryProperties;
 59  
 
 60  
     private Scheduler quartzScheduler;
 61  
 
 62  
     protected void doInitialise() throws InitialisationException
 63  
     {
 64  
         try
 65  
         {
 66  0
             if (quartzScheduler == null)
 67  
             {
 68  0
                 if (factory == null)
 69  
                 {
 70  0
                     Object[] args = null;
 71  0
                     if (factoryProperties != null)
 72  
                     {
 73  0
                         args = new Object[]{factoryProperties};
 74  
                     }
 75  0
                     factory = (SchedulerFactory)ClassUtils.instanciateClass(factoryClassName, args);
 76  
                 }
 77  0
                 quartzScheduler = factory.getScheduler();
 78  
             }
 79  
         }
 80  0
         catch (Exception e)
 81  
         {
 82  0
             throw new InitialisationException(CoreMessages.initialisationFailure("Quartz provider"), e);
 83  0
         }
 84  0
     }
 85  
 
 86  
     protected void doDispose()
 87  
     {
 88  
         // template method
 89  0
     }
 90  
 
 91  
     protected void doConnect() throws Exception
 92  
     {
 93  
         // template method
 94  0
     }
 95  
 
 96  
     protected void doDisconnect() throws Exception
 97  
     {
 98  
         // template method
 99  0
     }
 100  
 
 101  
     protected void doStart() throws UMOException
 102  
     {
 103  
         try
 104  
         {
 105  0
             quartzScheduler.start();
 106  
         }
 107  0
         catch (Exception e)
 108  
         {
 109  0
             throw new ConnectorException(CoreMessages.failedToStart("Quartz provider"), this, e);
 110  0
         }
 111  0
     }
 112  
 
 113  
     protected void doStop() throws UMOException
 114  
     {
 115  
         try
 116  
         {
 117  0
             if (quartzScheduler != null)
 118  
             {
 119  0
                 quartzScheduler.shutdown();
 120  
             }
 121  
         }
 122  0
         catch (Exception e)
 123  
         {
 124  0
             throw new ConnectorException(CoreMessages.failedToStop("Quartz provider"), this, e);
 125  0
         }
 126  0
     }
 127  
 
 128  
     public String getProtocol()
 129  
     {
 130  0
         return "quartz";
 131  
     }
 132  
 
 133  
     public SchedulerFactory getFactory()
 134  
     {
 135  0
         return factory;
 136  
     }
 137  
 
 138  
     public void setFactory(SchedulerFactory factory)
 139  
     {
 140  0
         this.factory = factory;
 141  0
     }
 142  
 
 143  
     public Scheduler getQuartzScheduler()
 144  
     {
 145  0
         return quartzScheduler;
 146  
     }
 147  
 
 148  
     public void setQuartzScheduler(Scheduler scheduler)
 149  
     {
 150  0
         this.quartzScheduler = scheduler;
 151  0
     }
 152  
 
 153  
     public String getFactoryClassName()
 154  
     {
 155  0
         return factoryClassName;
 156  
     }
 157  
 
 158  
     public void setFactoryClassName(String factoryClassName)
 159  
     {
 160  0
         this.factoryClassName = factoryClassName;
 161  0
     }
 162  
 
 163  
     public Properties getFactoryProperties()
 164  
     {
 165  0
         return factoryProperties;
 166  
     }
 167  
 
 168  
     public void setFactoryProperties(Properties factoryProperties)
 169  
     {
 170  0
         this.factoryProperties = factoryProperties;
 171  0
     }
 172  
 
 173  
 }