    001package org.apache.turbine.modules;
    002
    003
    004/*
    005 * Licensed to the Apache Software Foundation (ASF) under one
    006 * or more contributor license agreements.  See the NOTICE file
    007 * distributed with this work for additional information
    008 * regarding copyright ownership.  The ASF licenses this file
    009 * to you under the Apache License, Version 2.0 (the
    010 * "License"); you may not use this file except in compliance
    011 * with the License.  You may obtain a copy of the License at
    012 *
    013 *   http://www.apache.org/licenses/LICENSE-2.0
    014 *
    015 * Unless required by applicable law or agreed to in writing,
    016 * software distributed under the License is distributed on an
    017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    018 * KIND, either express or implied.  See the License for the
    019 * specific language governing permissions and limitations
    020 * under the License.
    021 */
    022
    023
    024import org.apache.turbine.Turbine;
    025import org.apache.turbine.pipeline.PipelineData;
    026import org.apache.turbine.services.schedule.JobEntry;
    027
    028/**
    029 * ScheduledJobs loader class.
    030 *
    031 * @author <a href="mailto:mbryson@mindspring.com">Dave Bryson</a>
    032 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
    033 * @version $Id: ScheduledJobLoader.java 1773378 2016-12-09 13:19:59Z tv $
    034 */
    035public class ScheduledJobLoader
    036    extends GenericLoader<ScheduledJob>
    037    implements Loader<ScheduledJob>
    038{
    039    /** The single instance of this class. */
    040    private static ScheduledJobLoader instance = new ScheduledJobLoader();
    041
    042    /**
    043     * These ctor's are private to force clients to use getInstance()
    044     * to access this class.
    045     */
    046    private ScheduledJobLoader()
    047    {
    048        super();
    049    }
    050
    051    /**
    052     * Attempts to load and execute the external ScheduledJob.
    053     *
    054     * @param job The JobEntry.
    055     * @param name Name of object that will execute the job.
    056     * @throws Exception a generic exception.
    057     */
    058    public void exec(JobEntry job, String name)
    059            throws Exception
    060    {
    061        // Execute job
    062        getAssembler(name).run(job);
    063    }
    064
    065    /**
    066     * Attempts to load and execute the external ScheduledJob.
    067     *
    068     * HELP! - THIS IS UGLY!
    069     *
    070     * I want the cache stuff from GenericLoader, BUT, I don't think
    071     * the scheduler needs the PipelineData object.  The scheduler runs
    072     * independently of an HTTP request.  This should not extend
    073     * GenericLoader!  Thoughts??
    074     *
    075     * @param pipelineData Turbine information.
    076     * @param name Name of object that will execute the job.
    077     * @throws Exception a generic exception.
    078     * @deprecated
    079     */
    080    @Deprecated
    081    @Override
    082    public void exec(PipelineData pipelineData, String name)
    083            throws Exception
    084    {
    085        throw new Exception("PipelineData objects not accepted for Scheduled jobs");
    086    }
    087
    088    /**
    089     * Pulls out an instance of the object by name.  Name is just the
    090     * single name of the object.
    091     *
    092     * @param name Name of object instance.
    093     * @return A ScheduledJob with the specified name, or null.
    094     * @throws Exception a generic exception.
    095     */
    096    @Override
    097    public ScheduledJob getAssembler(String name)
    098        throws Exception
    099    {
    100        return getAssembler(ScheduledJob.class, name);
    101    }
    102
    103    /**
    104     * @see org.apache.turbine.modules.Loader#getCacheSize()
    105     */
    106    @Override
    107    public int getCacheSize()
    108    {
    109        return ScheduledJobLoader.getConfiguredCacheSize();
    110    }
    111
    112    /**
    113     * The method through which this class is accessed.
    114     *
    115     * @return The single instance of this class.
    116     */
    117    public static ScheduledJobLoader getInstance()
    118    {
    119        return instance;
    120    }
    121
    122    /**
    123     * Helper method to get the configured cache size for this module
    124     *
    125     * @return the configure cache size
    126     */
    127    private static int getConfiguredCacheSize()
    128    {
    129        return Turbine.getConfiguration().getInt(ScheduledJob.CACHE_SIZE_KEY,
    130                ScheduledJob.CACHE_SIZE_DEFAULT);
    131    }
    132}