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$
034 */
035public class ScheduledJobLoader
036    extends GenericLoader<ScheduledJob>
037{
038    /** The single instance of this class. */
039    private static ScheduledJobLoader instance = new ScheduledJobLoader();
040
041    /**
042     * These ctor's are private to force clients to use getInstance()
043     * to access this class.
044     */
045    private ScheduledJobLoader()
046    {
047        super(ScheduledJob.class,
048                () -> Turbine.getConfiguration().getInt(ScheduledJob.CACHE_SIZE_KEY,
049                        ScheduledJob.CACHE_SIZE_DEFAULT));
050    }
051
052    /**
053     * Attempts to load and execute the external ScheduledJob.
054     *
055     * @param job The JobEntry.
056     * @param name Name of object that will execute the job.
057     * @throws Exception a generic exception.
058     */
059    public void exec(JobEntry job, String name)
060            throws Exception
061    {
062        // Execute job
063        getAssembler(name).run(job);
064    }
065
066    /**
067     * Attempts to load and execute the external ScheduledJob.
068     *
069     * HELP! - THIS IS UGLY!
070     *
071     * I want the cache stuff from GenericLoader, BUT, I don't think
072     * the scheduler needs the PipelineData object.  The scheduler runs
073     * independently of an HTTP request.  This should not extend
074     * GenericLoader!  Thoughts??
075     *
076     * @param pipelineData Turbine information.
077     * @param name Name of object that will execute the job.
078     * @throws Exception a generic exception.
079     * @deprecated
080     */
081    @Deprecated
082    @Override
083    public void exec(PipelineData pipelineData, String name)
084            throws Exception
085    {
086        throw new Exception("PipelineData objects not accepted for Scheduled jobs");
087    }
088
089    /**
090     * The method through which this class is accessed.
091     *
092     * @return The single instance of this class.
093     */
094    public static ScheduledJobLoader getInstance()
095    {
096        return instance;
097    }
098}