Coverage Report - org.mule.transport.quartz.QuartzConnector
 
Classes in this File Line Coverage Branch Coverage Complexity
QuartzConnector
79%
27/34
83%
5/6
1.818
 
 1  
 /*
 2  
  * $Id: QuartzConnector.java 11613 2008-04-20 20:30:10Z rossmason $
 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.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  
  * Creates a connection to a Quartz scheduler. This allows events to be scheduled at
 27  
  * specific times, with repeated occurrences.
 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  
      * Properties to be used for creating the scheduler.  If no properties are given, the
 49  
      * scheduler will be created by StdSchedulerFactory.getDefaultScheduler()
 50  
      */
 51  82
     private Properties factoryProperties = null;
 52  
 
 53  
     /**
 54  
      * The scheduler instance.  This can be configured by the user and injected as a bean
 55  
      * or if not, it will be created by Mule upon initialization.
 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  
         // template method
 85  98
     }
 86  
 
 87  
     protected void doConnect() throws Exception
 88  
     {
 89  
         // template method
 90  82
     }
 91  
 
 92  
     protected void doDisconnect() throws Exception
 93  
     {
 94  
         // template method
 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  
 }