Coverage Report - org.mule.transport.quartz.QuartzConnector
 
Classes in this File Line Coverage Branch Coverage Complexity
QuartzConnector
0%
0/37
0%
0/6
0
 
 1  
 /*
 2  
  * $Id: QuartzConnector.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.MuleContext;
 14  
 import org.mule.api.MuleException;
 15  
 import org.mule.api.config.MuleProperties;
 16  
 import org.mule.api.lifecycle.InitialisationException;
 17  
 import org.mule.api.transport.ConnectorException;
 18  
 import org.mule.config.i18n.CoreMessages;
 19  
 import org.mule.transport.AbstractConnector;
 20  
 
 21  
 import java.util.Properties;
 22  
 
 23  
 import org.quartz.Scheduler;
 24  
 import org.quartz.SchedulerFactory;
 25  
 import org.quartz.impl.StdSchedulerFactory;
 26  
 
 27  
 /**
 28  
  * Creates a connection to a Quartz scheduler. This allows events to be scheduled at
 29  
  * specific times, with repeated occurrences.
 30  
  */
 31  
 public class QuartzConnector extends AbstractConnector
 32  
 {
 33  
     public static final String QUARTZ = "quartz";
 34  
 
 35  
     public static final String PROPERTY_CRON_EXPRESSION = "cronExpression";
 36  
     public static final String PROPERTY_REPEAT_INTERVAL = "repeatInterval";
 37  
     public static final String PROPERTY_REPEAT_COUNT = "repeatCount";
 38  
     public static final String PROPERTY_START_DELAY = "startDelay";
 39  
     public static final String PROPERTY_PAYLOAD = "payload";
 40  
 
 41  
     public static final String PROPERTY_JOB_CONFIG = "jobConfig";
 42  
     public static final String PROPERTY_JOB_DATA = "jobData";
 43  
 
 44  
     public static final String PROPERTY_JOB_REF = "jobRef";
 45  
     public static final String PROPERTY_JOB_OBJECT = "jobObject";
 46  
 
 47  
     public static final String DEFAULT_GROUP_NAME = "mule";
 48  
 
 49  
     /**
 50  
      * Properties to be used for creating the scheduler.  If no properties are given, the
 51  
      * scheduler will be created by <code>StdSchedulerFactory.getDefaultScheduler()</code>
 52  
      */
 53  0
     private Properties factoryProperties = null;
 54  
 
 55  
     /**
 56  
      * The scheduler instance.  This can be configured by the user and injected as a bean
 57  
      * or if not, it will be created by Mule upon initialization.
 58  
      */
 59  0
     private Scheduler quartzScheduler = null;
 60  
 
 61  
     public QuartzConnector(MuleContext context)
 62  
     {
 63  0
         super(context);
 64  0
     }
 65  
     
 66  
     @Override
 67  
     protected void doInitialise() throws InitialisationException
 68  
     {
 69  0
         if (factoryProperties == null)
 70  
         {
 71  0
             factoryProperties = new Properties();
 72  
         }
 73  
 
 74  
         //Set the thread count, we can't seem to plug in our work manager unfortunately
 75  0
         factoryProperties.setProperty("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
 76  0
         factoryProperties.setProperty("org.quartz.threadPool.threadCount", String.valueOf(getReceiverThreadingProfile().getMaxThreadsActive()));
 77  
 
 78  
         try
 79  
         {
 80  0
             if (quartzScheduler == null)
 81  
             {
 82  0
                 SchedulerFactory factory = new StdSchedulerFactory(factoryProperties);
 83  0
                 quartzScheduler = factory.getScheduler();
 84  
             }
 85  0
             quartzScheduler.getContext().put(MuleProperties.MULE_CONTEXT_PROPERTY, muleContext);            
 86  
         
 87  
         }
 88  0
         catch (Exception e)
 89  
         {
 90  0
             throw new InitialisationException(CoreMessages.initialisationFailure("Quartz conntector"), e, this);
 91  0
         }
 92  0
     }
 93  
 
 94  
     @Override
 95  
     protected void doDispose()
 96  
     {
 97  
         // template method
 98  0
     }
 99  
 
 100  
     @Override
 101  
     protected void doConnect() throws Exception
 102  
     {
 103  
         // template method
 104  0
     }
 105  
 
 106  
     @Override
 107  
     protected void doDisconnect() throws Exception
 108  
     {
 109  
         // template method
 110  0
     }
 111  
 
 112  
     @Override
 113  
     protected void doStart() throws MuleException
 114  
     {
 115  
         try
 116  
         {
 117  0
             quartzScheduler.start();
 118  
         }
 119  0
         catch (Exception e)
 120  
         {
 121  0
             throw new ConnectorException(CoreMessages.failedToStart("Quartz provider"), this, e);
 122  0
         }
 123  0
     }
 124  
 
 125  
     @Override
 126  
     protected void doStop() throws MuleException
 127  
     {
 128  
         try
 129  
         {
 130  0
             if (quartzScheduler != null)
 131  
             {
 132  0
                 quartzScheduler.shutdown();
 133  
             }
 134  
         }
 135  0
         catch (Exception e)
 136  
         {
 137  0
             throw new ConnectorException(CoreMessages.failedToStop("Quartz provider"), this, e);
 138  0
         }
 139  0
     }
 140  
 
 141  
     public String getProtocol()
 142  
     {
 143  0
         return QUARTZ;
 144  
     }
 145  
 
 146  
     public Scheduler getQuartzScheduler()
 147  
     {
 148  0
         return quartzScheduler;
 149  
     }
 150  
 
 151  
     public void setQuartzScheduler(Scheduler scheduler)
 152  
     {
 153  0
         this.quartzScheduler = scheduler;
 154  0
     }
 155  
 
 156  
     public Properties getFactoryProperties()
 157  
     {
 158  0
         return factoryProperties;
 159  
     }
 160  
 
 161  
     public void setFactoryProperties(Properties factoryProperties)
 162  
     {
 163  0
         this.factoryProperties = factoryProperties;
 164  0
     }
 165  
 }