Coverage report

  %line %branch
org.apache.turbine.modules.ScheduledJobLoader
0% 
0% 

 1  
 package org.apache.turbine.modules;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2004 The Apache Software Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License")
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import java.util.List;
 20  
 
 21  
 import org.apache.commons.logging.Log;
 22  
 import org.apache.commons.logging.LogFactory;
 23  
 
 24  
 import org.apache.turbine.Turbine;
 25  
 import org.apache.turbine.TurbineConstants;
 26  
 import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService;
 27  
 import org.apache.turbine.services.assemblerbroker.TurbineAssemblerBroker;
 28  
 import org.apache.turbine.services.schedule.JobEntry;
 29  
 import org.apache.turbine.util.ObjectUtils;
 30  
 import org.apache.turbine.util.RunData;
 31  
 
 32  
 /**
 33  
  * ScheduledJobs loader class.
 34  
  *
 35  
  * @author <a href="mailto:mbryson@mindspring.com">Dave Bryson</a>
 36  
  * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
 37  
  * @version $Id: ScheduledJobLoader.java,v 1.7.2.3 2004/08/16 22:57:50 henning Exp $
 38  
  */
 39  
 public class ScheduledJobLoader
 40  
     extends GenericLoader
 41  
 {
 42  
     /** Logging */
 43  0
     private static Log log = LogFactory.getLog(ScheduledJobLoader.class);
 44  
 
 45  
     /** The single instance of this class. */
 46  0
     private static ScheduledJobLoader instance =
 47  
         new ScheduledJobLoader(Turbine.getConfiguration()
 48  
             .getInt(TurbineConstants.SCHEDULED_JOB_CACHE_SIZE_KEY,
 49  
                 TurbineConstants.SCHEDULED_JOB_CACHE_SIZE_DEFAULT));
 50  
 
 51  
     /** The Assembler Broker Service */
 52  0
     private static AssemblerBrokerService ab = TurbineAssemblerBroker.getService();
 53  
 
 54  
     /**
 55  
      * These ctor's are private to force clients to use getInstance()
 56  
      * to access this class.
 57  
      */
 58  
     private ScheduledJobLoader()
 59  
     {
 60  0
         super();
 61  0
     }
 62  
 
 63  
     /**
 64  
      * These ctor's are private to force clients to use getInstance()
 65  
      * to access this class.
 66  
      */
 67  
     private ScheduledJobLoader(int i)
 68  
     {
 69  0
         super(i);
 70  0
     }
 71  
 
 72  
     /**
 73  
      * Adds an instance of an object into the hashtable.
 74  
      *
 75  
      * @param name Name of object.
 76  
      * @param job Job to be associated with name.
 77  
      */
 78  
     private void addInstance(String name, ScheduledJob job)
 79  
     {
 80  0
         if (cache())
 81  
         {
 82  0
             this.put(name, (ScheduledJob) job);
 83  
         }
 84  0
     }
 85  
 
 86  
     /**
 87  
      * Attempts to load and execute the external ScheduledJob.
 88  
      *
 89  
      * @param job The JobEntry.
 90  
      * @param name Name of object that will execute the job.
 91  
      * @exception Exception a generic exception.
 92  
      */
 93  
     public void exec(JobEntry job, String name)
 94  
             throws Exception
 95  
     {
 96  
         // Execute job
 97  0
         getInstance(name).run(job);
 98  0
     }
 99  
 
 100  
     /**
 101  
      * Attempts to load and execute the external ScheduledJob.
 102  
      *
 103  
      * HELP! - THIS IS UGLY!
 104  
      *
 105  
      * I want the cache stuff from GenericLoader, BUT, I don't think
 106  
      * the scheduler needs the Rundata object.  The scheduler runs
 107  
      * independently of an HTTP request.  This should not extend
 108  
      * GenericLoader!  Thoughts??
 109  
      *
 110  
      * @param data Turbine information.
 111  
      * @param name Name of object that will execute the job.
 112  
      * @exception Exception a generic exception.
 113  
      */
 114  
     public void exec(RunData data, String name)
 115  
             throws Exception
 116  
     {
 117  0
         throw new Exception("RunData objects not accepted for Scheduled jobs");
 118  
     }
 119  
 
 120  
     /**
 121  
      * Pulls out an instance of the object by name.  Name is just the
 122  
      * single name of the object.
 123  
      *
 124  
      * @param name Name of object instance.
 125  
      * @return An ScheduledJob with the specified name, or null.
 126  
      * @exception Exception a generic exception.
 127  
      */
 128  
     public ScheduledJob getInstance(String name)
 129  
             throws Exception
 130  
     {
 131  0
         ScheduledJob job = null;
 132  
 
 133  
         // Check if the screen is already in the cache
 134  0
         if (cache() && this.containsKey(name))
 135  
         {
 136  0
             job = (ScheduledJob) this.get(name);
 137  0
             log.debug("Found Job " + name + " in the cache!");
 138  
         }
 139  
         else
 140  
         {
 141  0
             log.debug("Loading Job " + name + " from the Assembler Broker");
 142  
 
 143  
             try
 144  
             {
 145  0
                 if (ab != null)
 146  
                 {
 147  
                     // Attempt to load the job
 148  0
                     job = (ScheduledJob) ab.getAssembler(
 149  
                         AssemblerBrokerService.SCHEDULEDJOB_TYPE, name);
 150  
                 }
 151  
             }
 152  0
             catch (ClassCastException cce)
 153  
             {
 154  
                 // This can alternatively let this exception be thrown
 155  
                 // So that the ClassCastException is shown in the
 156  
                 // browser window.  Like this it shows "Screen not Found"
 157  0
                 job = null;
 158  0
             }
 159  
 
 160  0
             if (job == null)
 161  
             {
 162  
                 // If we did not find a screen we should try and give
 163  
                 // the user a reason for that...
 164  
                 // FIX ME: The AssemblerFactories should each add it's
 165  
                 // own string here...
 166  0
                 List packages = Turbine.getConfiguration()
 167  
                     .getList(TurbineConstants.MODULE_PACKAGES);
 168  
 
 169  0
                 ObjectUtils.addOnce(packages, GenericLoader.getBasePackage());
 170  
 
 171  0
                 throw new ClassNotFoundException(
 172  
                         "\n\n\tRequested ScheduledJob not found: " + name +
 173  
                         "\n\tTurbine looked in the following " +
 174  
                         "modules.packages path: \n\t" + packages.toString() + "\n");
 175  
             }
 176  0
             else if (cache())
 177  
             {
 178  
                 // The new instance is added to the cache
 179  0
                 addInstance(name, job);
 180  
             }
 181  
         }
 182  0
         return job;
 183  
     }
 184  
 
 185  
     /**
 186  
      * The method through which this class is accessed.
 187  
      *
 188  
      * @return The single instance of this class.
 189  
      */
 190  
     public static ScheduledJobLoader getInstance()
 191  
     {
 192  0
         return instance;
 193  
     }
 194  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.