You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by tv...@apache.org on 2015/08/13 02:33:04 UTC

svn commit: r1695632 - in /turbine/core/trunk/src/java/org/apache/turbine/services/schedule: AbstractSchedulerService.java TorqueSchedulerService.java TurbineNonPersistentSchedulerService.java

Author: tv
Date: Thu Aug 13 00:33:04 2015
New Revision: 1695632

URL: http://svn.apache.org/r1695632
Log:
Introduce AbstractSchedulerService to have a common code base for the derived implementations and to be able to deprecate them in favor of QuartzSchedulerService

Added:
    turbine/core/trunk/src/java/org/apache/turbine/services/schedule/AbstractSchedulerService.java   (with props)
Modified:
    turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TorqueSchedulerService.java
    turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TurbineNonPersistentSchedulerService.java

Added: turbine/core/trunk/src/java/org/apache/turbine/services/schedule/AbstractSchedulerService.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/schedule/AbstractSchedulerService.java?rev=1695632&view=auto
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/services/schedule/AbstractSchedulerService.java (added)
+++ turbine/core/trunk/src/java/org/apache/turbine/services/schedule/AbstractSchedulerService.java Thu Aug 13 00:33:04 2015
@@ -0,0 +1,371 @@
+package org.apache.turbine.services.schedule;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.turbine.services.InitializationException;
+import org.apache.turbine.services.TurbineBaseService;
+import org.apache.turbine.util.TurbineException;
+
+/**
+ * Service for a cron like scheduler.
+ *
+ * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
+ * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
+ * @version $Id: TorqueSchedulerService.java 534527 2007-05-02 16:10:59Z tv $
+ */
+public abstract class AbstractSchedulerService extends TurbineBaseService implements ScheduleService
+{
+    /** Logging */
+    protected static Log log = LogFactory.getLog(ScheduleService.LOGGER_NAME);
+
+    /** The queue */
+    protected JobQueue<JobEntry> scheduleQueue = null;
+
+    /** Current status of the scheduler */
+    protected boolean enabled = false;
+
+    /** The main loop for starting jobs. */
+    protected MainLoop mainLoop;
+
+    /** The thread used to process commands. */
+    protected Thread thread;
+
+    /**
+     * Creates a new instance.
+     */
+    public AbstractSchedulerService()
+    {
+        mainLoop = null;
+        thread = null;
+    }
+
+    /**
+     * Initializes the SchedulerService.
+     *
+     * @throws InitializationException
+     *             Something went wrong in the init stage
+     */
+    @Override
+    public void init() throws InitializationException
+    {
+        try
+        {
+            setEnabled(getConfiguration().getBoolean("enabled", true));
+            scheduleQueue = new JobQueue<JobEntry>();
+            mainLoop = new MainLoop();
+
+            @SuppressWarnings("unchecked") // Why is this cast necessary?
+            List<JobEntry> jobs = (List<JobEntry>)loadJobs();
+            scheduleQueue.batchLoad(jobs);
+            restart();
+
+            setInit(true);
+        }
+        catch (Exception e)
+        {
+            throw new InitializationException("Could not initialize the scheduler service", e);
+        }
+    }
+
+    /**
+     * Load all jobs from configuration storage
+     *
+     * @return the list of pre-configured jobs
+     * @throws TurbineException
+     */
+    protected abstract List<? extends JobEntry> loadJobs() throws TurbineException;
+
+    /**
+     * Shutdowns the service.
+     *
+     * This methods interrupts the housekeeping thread.
+     */
+    @Override
+    public void shutdown()
+    {
+        if (getThread() != null)
+        {
+            getThread().interrupt();
+        }
+    }
+
+    /**
+     * @see org.apache.turbine.services.schedule.ScheduleService#newJob(int, int, int, int, int, java.lang.String)
+     */
+    @Override
+    public abstract JobEntry newJob(int sec, int min, int hour, int wd, int day_mo, String task) throws TurbineException;
+
+    /**
+     * Get a specific Job from Storage.
+     *
+     * @param oid
+     *            The int id for the job.
+     * @return A JobEntry.
+     * @exception TurbineException
+     *                job could not be retrieved.
+     */
+    @Override
+    public abstract JobEntry getJob(int oid) throws TurbineException;
+
+    /**
+     * Add a new job to the queue.
+     *
+     * @param je
+     *            A JobEntry with the job to add.
+     * @throws TurbineException
+     *             job could not be added
+     */
+    @Override
+    public void addJob(JobEntry je) throws TurbineException
+    {
+        updateJob(je);
+    }
+
+    /**
+     * Remove a job from the queue.
+     *
+     * @param je
+     *            A JobEntry with the job to remove.
+     * @exception TurbineException
+     *                job could not be removed
+     */
+    @Override
+    public abstract void removeJob(JobEntry je) throws TurbineException;
+
+    /**
+     * Add or update a job.
+     *
+     * @param je
+     *            A JobEntry with the job to modify
+     * @throws TurbineException
+     *             job could not be updated
+     */
+    @Override
+    public abstract void updateJob(JobEntry je) throws TurbineException;
+
+    /**
+     * List jobs in the queue. This is used by the scheduler UI.
+     *
+     * @return A List of jobs.
+     */
+    @Override
+    public List<JobEntry> listJobs()
+    {
+        return scheduleQueue.list();
+    }
+
+    /**
+     * Sets the enabled status of the scheduler
+     *
+     * @param enabled
+     *
+     */
+    protected void setEnabled(boolean enabled)
+    {
+        this.enabled = enabled;
+    }
+
+    /**
+     * Determines if the scheduler service is currently enabled.
+     *
+     * @return Status of the scheduler service.
+     */
+    @Override
+    public boolean isEnabled()
+    {
+        return enabled;
+    }
+
+    /**
+     * Starts or restarts the scheduler if not already running.
+     */
+    @Override
+    public synchronized void startScheduler()
+    {
+        setEnabled(true);
+        restart();
+    }
+
+    /**
+     * Stops the scheduler if it is currently running.
+     */
+    @Override
+    public synchronized void stopScheduler()
+    {
+        log.info("Stopping job scheduler");
+        Thread thread = getThread();
+        if (thread != null)
+        {
+            thread.interrupt();
+        }
+        enabled = false;
+    }
+
+    /**
+     * Return the thread being used to process commands, or null if there is no
+     * such thread. You can use this to invoke any special methods on the
+     * thread, for example, to interrupt it.
+     *
+     * @return A Thread.
+     */
+    public synchronized Thread getThread()
+    {
+        return thread;
+    }
+
+    /**
+     * Set thread to null to indicate termination.
+     */
+    protected synchronized void clearThread()
+    {
+        thread = null;
+    }
+
+    /**
+     * Start (or restart) a thread to process commands, or wake up an existing
+     * thread if one is already running. This method can be invoked if the
+     * background thread crashed due to an unrecoverable exception in an
+     * executed command.
+     */
+    public synchronized void restart()
+    {
+        if (enabled)
+        {
+            log.info("Starting job scheduler");
+            if (thread == null)
+            {
+                // Create the the housekeeping thread of the scheduler. It will
+                // wait for the time when the next task needs to be started,
+                // and then launch a worker thread to execute the task.
+                thread = new Thread(mainLoop, ScheduleService.SERVICE_NAME);
+                // Indicate that this is a system thread. JVM will quit only
+                // when there are no more enabled user threads. Settings threads
+                // spawned internally by Turbine as daemons allows commandline
+                // applications using Turbine to terminate in an orderly manner.
+                thread.setDaemon(true);
+                thread.start();
+            }
+            else
+            {
+                notify();
+            }
+        }
+    }
+
+    /**
+     * Return the next Job to execute, or null if thread is interrupted.
+     *
+     * @return A JobEntry.
+     * @exception TurbineException
+     *                a generic exception.
+     */
+    protected synchronized JobEntry nextJob() throws TurbineException
+    {
+        try
+        {
+            while (!Thread.interrupted())
+            {
+                // Grab the next job off the queue.
+                JobEntry je = scheduleQueue.getNext();
+
+                if (je == null)
+                {
+                    // Queue must be empty. Wait on it.
+                    wait();
+                }
+                else
+                {
+                    long now = System.currentTimeMillis();
+                    long when = je.getNextRuntime();
+
+                    if (when > now)
+                    {
+                        // Wait till next runtime.
+                        wait(when - now);
+                    }
+                    else
+                    {
+                        // Update the next runtime for the job.
+                        scheduleQueue.updateQueue(je);
+                        // Return the job to run it.
+                        return je;
+                    }
+                }
+            }
+        }
+        catch (InterruptedException ex)
+        {
+            // ignore
+        }
+
+        // On interrupt.
+        return null;
+    }
+
+    /**
+     * Inner class. This is isolated in its own Runnable class just so that the
+     * main class need not implement Runnable, which would allow others to
+     * directly invoke run, which is not supported.
+     */
+    protected class MainLoop implements Runnable
+    {
+        /**
+         * Method to run the class.
+         */
+        @Override
+        public void run()
+        {
+            String taskName = null;
+            try
+            {
+                while (enabled)
+                {
+                    JobEntry je = nextJob();
+                    if (je != null)
+                    {
+                        taskName = je.getTask();
+
+                        // Start the thread to run the job.
+                        Runnable wt = new WorkerThread(je);
+                        Thread helper = new Thread(wt);
+                        helper.start();
+                    }
+                    else
+                    {
+                        break;
+                    }
+                }
+            }
+            catch (Exception e)
+            {
+                log.error("Error running a Scheduled Job: " + taskName, e);
+                enabled = false;
+            }
+            finally
+            {
+                clearThread();
+            }
+        }
+    }
+}

Propchange: turbine/core/trunk/src/java/org/apache/turbine/services/schedule/AbstractSchedulerService.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TorqueSchedulerService.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TorqueSchedulerService.java?rev=1695632&r1=1695631&r2=1695632&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TorqueSchedulerService.java (original)
+++ turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TorqueSchedulerService.java Thu Aug 13 00:33:04 2015
@@ -19,15 +19,10 @@ package org.apache.turbine.services.sche
  * under the License.
  */
 
-import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.torque.TorqueException;
 import org.apache.torque.criteria.Criteria;
-import org.apache.turbine.services.InitializationException;
-import org.apache.turbine.services.TurbineBaseService;
 import org.apache.turbine.util.TurbineException;
 
 /**
@@ -36,85 +31,36 @@ import org.apache.turbine.util.TurbineEx
  * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
  * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
  * @version $Id: TorqueSchedulerService.java 534527 2007-05-02 16:10:59Z tv $
+ *
+ * @deprecated Use QuartzSchedulerService instead
  */
-public class TorqueSchedulerService extends TurbineBaseService implements ScheduleService
+@Deprecated
+public class TorqueSchedulerService extends AbstractSchedulerService
 {
-    /** Logging */
-    protected static Log log = LogFactory.getLog(ScheduleService.LOGGER_NAME);
-
-    /** The queue */
-    protected JobQueue<JobEntry> scheduleQueue = null;
-
-    /** Current status of the scheduler */
-    protected boolean enabled = false;
-
-    /** The main loop for starting jobs. */
-    protected MainLoop mainLoop;
-
-    /** The thread used to process commands. */
-    protected Thread thread;
-
-    /**
-     * Creates a new instance.
-     */
-    public TorqueSchedulerService()
-    {
-        mainLoop = null;
-        thread = null;
-    }
-
     /**
-     * Initializes the SchedulerService.
+     * Load all jobs from configuration storage
      *
-     * @throws InitializationException
-     *             Something went wrong in the init stage
+     * @return the list of pre-configured jobs
+     * @throws TurbineException
      */
     @Override
-    public void init() throws InitializationException
+    protected List<? extends JobEntry> loadJobs() throws TurbineException
     {
+        // Load all from cold storage.
         try
         {
-            setEnabled(getConfiguration().getBoolean("enabled", true));
-            scheduleQueue = new JobQueue<JobEntry>();
-            mainLoop = new MainLoop();
-
-            // Load all from cold storage.
             List<JobEntryTorque> jobsTorque = JobEntryTorquePeer.doSelect(new Criteria());
 
-            if (jobsTorque != null)
+            for (JobEntryTorque job : jobsTorque)
             {
-                List<JobEntry> jobs = new ArrayList<JobEntry>(jobsTorque.size());
-
-                for (JobEntryTorque job : jobsTorque)
-                {
-                    job.calcRunTime();
-                    jobs.add(job);
-                }
-
-                scheduleQueue.batchLoad(jobs);
-
-                restart();
+                job.calcRunTime();
             }
 
-            setInit(true);
+            return jobsTorque;
         }
-        catch (Exception e)
-        {
-            throw new InitializationException("Could not initialize the scheduler service", e);
-        }
-    }
-
-    /**
-     * Shutdowns the service.
-     *
-     * This methods interrupts the housekeeping thread.
-     */
-    @Override
-    public void shutdown()
-    {
-        if (getThread() != null)
+        catch (TorqueException e)
         {
-            getThread().interrupt();
+            throw new TurbineException("Error retrieving initial job list from persistent storage.", e);
         }
     }
 
@@ -159,20 +105,6 @@ public class TorqueSchedulerService exte
     }
 
     /**
-     * Add a new job to the queue.
-     *
-     * @param je
-     *            A JobEntry with the job to add.
-     * @throws TurbineException
-     *             job could not be added
-     */
-    @Override
-    public void addJob(JobEntry je) throws TurbineException
-    {
-        updateJob(je);
-    }
-
-    /**
      * Remove a job from the queue.
      *
      * @param je
@@ -242,209 +174,4 @@ public class TorqueSchedulerService exte
             throw new TurbineException("Problem updating Scheduled Job: " + je.getTask(), e);
         }
     }
-
-    /**
-     * List jobs in the queue. This is used by the scheduler UI.
-     *
-     * @return A List of jobs.
-     */
-    @Override
-    public List<JobEntry> listJobs()
-    {
-        return scheduleQueue.list();
-    }
-
-    /**
-     * Sets the enabled status of the scheduler
-     *
-     * @param enabled
-     *
-     */
-    protected void setEnabled(boolean enabled)
-    {
-        this.enabled = enabled;
-    }
-
-    /**
-     * Determines if the scheduler service is currently enabled.
-     *
-     * @return Status of the scheduler service.
-     */
-    @Override
-    public boolean isEnabled()
-    {
-        return enabled;
-    }
-
-    /**
-     * Starts or restarts the scheduler if not already running.
-     */
-    @Override
-    public synchronized void startScheduler()
-    {
-        setEnabled(true);
-        restart();
-    }
-
-    /**
-     * Stops the scheduler if it is currently running.
-     */
-    @Override
-    public synchronized void stopScheduler()
-    {
-        log.info("Stopping job scheduler");
-        Thread thread = getThread();
-        if (thread != null)
-        {
-            thread.interrupt();
-        }
-        enabled = false;
-    }
-
-    /**
-     * Return the thread being used to process commands, or null if there is no
-     * such thread. You can use this to invoke any special methods on the
-     * thread, for example, to interrupt it.
-     *
-     * @return A Thread.
-     */
-    public synchronized Thread getThread()
-    {
-        return thread;
-    }
-
-    /**
-     * Set thread to null to indicate termination.
-     */
-    protected synchronized void clearThread()
-    {
-        thread = null;
-    }
-
-    /**
-     * Start (or restart) a thread to process commands, or wake up an existing
-     * thread if one is already running. This method can be invoked if the
-     * background thread crashed due to an unrecoverable exception in an
-     * executed command.
-     */
-    public synchronized void restart()
-    {
-        if (enabled)
-        {
-            log.info("Starting job scheduler");
-            if (thread == null)
-            {
-                // Create the the housekeeping thread of the scheduler. It will
-                // wait for the time when the next task needs to be started,
-                // and then launch a worker thread to execute the task.
-                thread = new Thread(mainLoop, ScheduleService.SERVICE_NAME);
-                // Indicate that this is a system thread. JVM will quit only
-                // when there are no more enabled user threads. Settings threads
-                // spawned internally by Turbine as daemons allows commandline
-                // applications using Turbine to terminate in an orderly manner.
-                thread.setDaemon(true);
-                thread.start();
-            }
-            else
-            {
-                notify();
-            }
-        }
-    }
-
-    /**
-     * Return the next Job to execute, or null if thread is interrupted.
-     *
-     * @return A JobEntry.
-     * @exception TurbineException
-     *                a generic exception.
-     */
-    protected synchronized JobEntry nextJob() throws TurbineException
-    {
-        try
-        {
-            while (!Thread.interrupted())
-            {
-                // Grab the next job off the queue.
-                JobEntry je = scheduleQueue.getNext();
-
-                if (je == null)
-                {
-                    // Queue must be empty. Wait on it.
-                    wait();
-                }
-                else
-                {
-                    long now = System.currentTimeMillis();
-                    long when = je.getNextRuntime();
-
-                    if (when > now)
-                    {
-                        // Wait till next runtime.
-                        wait(when - now);
-                    }
-                    else
-                    {
-                        // Update the next runtime for the job.
-                        scheduleQueue.updateQueue(je);
-                        // Return the job to run it.
-                        return je;
-                    }
-                }
-            }
-        }
-        catch (InterruptedException ex)
-        {
-            // ignore
-        }
-
-        // On interrupt.
-        return null;
-    }
-
-    /**
-     * Inner class. This is isolated in its own Runnable class just so that the
-     * main class need not implement Runnable, which would allow others to
-     * directly invoke run, which is not supported.
-     */
-    protected class MainLoop implements Runnable
-    {
-        /**
-         * Method to run the class.
-         */
-        @Override
-        public void run()
-        {
-            String taskName = null;
-            try
-            {
-                while (enabled)
-                {
-                    JobEntry je = nextJob();
-                    if (je != null)
-                    {
-                        taskName = je.getTask();
-
-                        // Start the thread to run the job.
-                        Runnable wt = new WorkerThread(je);
-                        Thread helper = new Thread(wt);
-                        helper.start();
-                    }
-                    else
-                    {
-                        break;
-                    }
-                }
-            }
-            catch (Exception e)
-            {
-                log.error("Error running a Scheduled Job: " + taskName, e);
-                enabled = false;
-            }
-            finally
-            {
-                clearThread();
-            }
-        }
-    }
 }

Modified: turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TurbineNonPersistentSchedulerService.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TurbineNonPersistentSchedulerService.java?rev=1695632&r1=1695631&r2=1695632&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TurbineNonPersistentSchedulerService.java (original)
+++ turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TurbineNonPersistentSchedulerService.java Thu Aug 13 00:33:04 2015
@@ -19,12 +19,11 @@ package org.apache.turbine.services.sche
  * under the License.
  */
 
+import java.util.ArrayList;
 import java.util.List;
-import java.util.Vector;
 
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.lang.StringUtils;
-import org.apache.turbine.services.InitializationException;
 import org.apache.turbine.util.TurbineException;
 
 /**
@@ -32,7 +31,7 @@ import org.apache.turbine.util.TurbineEx
  * TurbineResources.properties file instead of the database.
  * The methods that operate on jobs ( get,add,update,remove )
  * only operate on the queue in memory and changes are not reflected
- * to the properties file which was used to initilize the jobs.
+ * to the properties file which was used to initialize the jobs.
  * An example is given below.  The job names are the class names that
  * extend ScheduledJob.
  *
@@ -62,92 +61,58 @@ import org.apache.turbine.util.TurbineEx
  * @author <a href="mailto:john@zenplex.com">John Thorhauer</a>
  * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
  * @version $Id: TurbineNonPersistentSchedulerService.java 534527 2007-05-02 16:10:59Z tv $
+ *
+ * @deprecated Use QuartzSchedulerService instead
  */
-public class TurbineNonPersistentSchedulerService
-        extends TorqueSchedulerService
+@Deprecated
+public class TurbineNonPersistentSchedulerService extends AbstractSchedulerService
 {
     /**
-     * Constructor.
-     *
-     * @exception TurbineException a generic exception.
-     */
-    public TurbineNonPersistentSchedulerService()
-            throws TurbineException
-    {
-        super();
-    }
-
-    /**
-     * Called the first time the Service is used.<br>
-     *
-     * Load all the jobs from cold storage.  Add jobs to the queue
-     * (sorted in ascending order by runtime) and start the scheduler
-     * thread.
+     * @see org.apache.turbine.services.schedule.AbstractSchedulerService#loadJobs()
      */
-    @SuppressWarnings("unchecked")
     @Override
-    public void init()
-            throws InitializationException
+    protected List<? extends JobEntry> loadJobs() throws TurbineException
     {
         Configuration conf = getConfiguration();
+        List<Object> jobProps = conf.getList("scheduler.jobs");
+        List<JobEntry> jobs = new ArrayList<JobEntry>();
 
-        try
+        // If there are scheduler.jobs defined then set up a job vector
+        // for the scheduleQueue
+        if (!jobProps.isEmpty())
         {
-            scheduleQueue = new JobQueue();
-            mainLoop = new MainLoop();
-
-            List<Object> jobProps = conf.getList("scheduler.jobs");
-            List<JobEntry> jobs = new Vector<JobEntry>();
-            // If there are scheduler.jobs defined then set up a job vector
-            // for the scheduleQueue
-            if (!jobProps.isEmpty())
+            for (int i = 0; i < jobProps.size(); i++)
             {
-                for (int i = 0; i < jobProps.size(); i++)
-                {
-                    String jobName = (String)jobProps.get(i);
-                    String jobPrefix = "scheduler.job." + jobName;
-
-                    String jobId = conf.getString(jobPrefix + ".ID", null);
-                    if (StringUtils.isEmpty(jobId))
-                    {
-                        throw new Exception(
-                                "There is an error in the TurbineResources.properties file. \n"
-                                + jobPrefix + ".ID is not found.\n");
-                    }
-
-                    int sec = conf.getInt(jobPrefix + ".SECOND", -1);
-                    int min = conf.getInt(jobPrefix + ".MINUTE", -1);
-                    int hr = conf.getInt(jobPrefix + ".HOUR", -1);
-                    int wkday = conf.getInt(jobPrefix + ".WEEKDAY", -1);
-                    int dayOfMonth = conf.getInt(jobPrefix + ".DAY_OF_MONTH", -1);
-
-                    JobEntry je = new JobEntryNonPersistent(
-                            sec,
-                            min,
-                            hr,
-                            wkday,
-                            dayOfMonth,
-                            jobName);
-                    je.setJobId(Integer.parseInt(jobId));
-                    jobs.add(je);
+                String jobName = (String)jobProps.get(i);
+                String jobPrefix = "scheduler.job." + jobName;
 
+                String jobId = conf.getString(jobPrefix + ".ID", null);
+                if (StringUtils.isEmpty(jobId))
+                {
+                    throw new TurbineException(
+                            "There is an error in the TurbineResources.properties file. \n"
+                            + jobPrefix + ".ID is not found.\n");
                 }
-            }
 
-            if (jobs.size() > 0)
-            {
-                scheduleQueue.batchLoad(jobs);
+                int sec = conf.getInt(jobPrefix + ".SECOND", -1);
+                int min = conf.getInt(jobPrefix + ".MINUTE", -1);
+                int hr = conf.getInt(jobPrefix + ".HOUR", -1);
+                int wkday = conf.getInt(jobPrefix + ".WEEKDAY", -1);
+                int dayOfMonth = conf.getInt(jobPrefix + ".DAY_OF_MONTH", -1);
+
+                JobEntry je = newJob(
+                        sec,
+                        min,
+                        hr,
+                        wkday,
+                        dayOfMonth,
+                        jobName);
+                je.setJobId(Integer.parseInt(jobId));
+                jobs.add(je);
             }
-
-            setEnabled(getConfiguration().getBoolean("enabled", true));
-            restart();
-
-            setInit(true);
-        }
-        catch (Exception e)
-        {
-            throw new InitializationException("Could not initialize the scheduler service", e);
         }
+
+        return jobs;
     }
 
     /**
@@ -176,19 +141,6 @@ public class TurbineNonPersistentSchedul
     }
 
     /**
-     * Add a new job to the queue.
-     *
-     * @param je A JobEntry with the job to add.
-     * @throws TurbineException job could not be added
-     */
-    @Override
-    public void addJob(JobEntry je)
-            throws TurbineException
-    {
-        updateJob(je);
-    }
-
-    /**
      * Remove a job from the queue.
      *
      * @param je A JobEntry with the job to remove.