Coverage Report - org.kuali.rice.kcb.config.KCBInitializer
 
Classes in this File Line Coverage Branch Coverage Complexity
KCBInitializer
0%
0/26
0%
0/6
1.375
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kcb.config;
 17  
 
 18  
 import org.kuali.rice.kcb.service.GlobalKCBServiceLocator;
 19  
 import org.kuali.rice.ksb.service.KSBServiceLocator;
 20  
 import org.quartz.JobDetail;
 21  
 import org.quartz.ObjectAlreadyExistsException;
 22  
 import org.quartz.Scheduler;
 23  
 import org.quartz.SchedulerException;
 24  
 import org.quartz.Trigger;
 25  
 import org.springframework.beans.BeansException;
 26  
 import org.springframework.beans.factory.BeanFactory;
 27  
 import org.springframework.beans.factory.BeanFactoryAware;
 28  
 import org.springframework.beans.factory.DisposableBean;
 29  
 import org.springframework.beans.factory.InitializingBean;
 30  
 import org.springframework.beans.factory.annotation.Required;
 31  
 
 32  
 /**
 33  
  * Initializing bean that initializes KCB (specifically the GlobalKCBServiceLocator)
 34  
  * on Spring context initialization.  This bean should be eagerly initialized (not marked lazy) 
 35  
  * 
 36  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 37  
  */
 38  0
 public class KCBInitializer implements BeanFactoryAware, InitializingBean, DisposableBean {
 39  
     private BeanFactory beanFactory;
 40  
     private Trigger messageProcessingTrigger;
 41  
     private JobDetail messageProcessingJobDetail;
 42  
     protected Scheduler scheduler;
 43  
     
 44  
         /**
 45  
      * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
 46  
      */
 47  
     public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
 48  0
         this.beanFactory = beanFactory;
 49  0
     }
 50  
 
 51  
     /**
 52  
      * Sets the Trigger for the message processing job
 53  
      * @param messageProcessingTrigger the Trigger for the message processing job
 54  
      */
 55  
     @Required
 56  
     public void setMessageProcessingTrigger(Trigger messageProcessingTrigger) {
 57  0
         this.messageProcessingTrigger = messageProcessingTrigger;
 58  0
     }
 59  
     
 60  
     /**
 61  
      * Sets the JobDetail for the message processing job
 62  
      * @param messageProcessingJobDetail the JobDetail for the message processing job
 63  
      */
 64  
     @Required
 65  
     public void setMessageProcessingJobDetail(JobDetail messageProcessingJobDetail) {
 66  0
         this.messageProcessingJobDetail = messageProcessingJobDetail;
 67  0
     }
 68  
 
 69  
     /**
 70  
      * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
 71  
      */
 72  
     public void afterPropertiesSet() throws Exception {
 73  0
         GlobalKCBServiceLocator.init(beanFactory);
 74  
         // kill the reference, our job is done
 75  0
         beanFactory = null;
 76  
 
 77  0
         Scheduler scheduler = getScheduler()==null?KSBServiceLocator.getScheduler():getScheduler();
 78  0
         scheduler.addJob(messageProcessingJobDetail, true);
 79  
 
 80  0
         addTriggerToScheduler(messageProcessingTrigger);
 81  0
     }
 82  
     
 83  
     private void addTriggerToScheduler(Trigger trigger) throws SchedulerException {
 84  0
                 boolean triggerExists = (getScheduler().getTrigger(trigger.getName(), trigger.getGroup()) != null);
 85  0
                 if (!triggerExists) {
 86  
                         try {
 87  0
                                 getScheduler().scheduleJob(trigger);
 88  0
                         } catch (ObjectAlreadyExistsException ex) {
 89  0
                                 getScheduler().rescheduleJob(trigger.getName(), trigger.getGroup(), trigger);
 90  0
                         }
 91  
                 } else {
 92  0
                     getScheduler().rescheduleJob(trigger.getName(), trigger.getGroup(), trigger);
 93  
                 }
 94  0
         }
 95  
 
 96  
     public void destroy() throws Exception {
 97  
         // prevent anything from accessing our services after the module has been destroyed/shutdown
 98  
         // our module's lifecycle is tied to the Spring context lifecycle for now
 99  0
         GlobalKCBServiceLocator.destroy();
 100  0
     }
 101  
 
 102  
         /**
 103  
          * @return the scheduler
 104  
          */
 105  
         public Scheduler getScheduler() {
 106  0
                 return this.scheduler;
 107  
         }
 108  
 
 109  
         /**
 110  
          * @param scheduler the scheduler to set
 111  
          */
 112  
         public void setScheduler(Scheduler scheduler) {
 113  0
                 this.scheduler = scheduler;
 114  0
         }
 115  
     
 116  
 }