Modified: 
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=1812628&r1=1812627&r2=1812628&view=diff
==============================================================================
--- 
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/AbstractSchedulerService.java
 (original)
+++ 
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/AbstractSchedulerService.java
 Thu Oct 19 12:34:25 2017
@@ -1,371 +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:[email protected]";>Dave Bryson</a>
- * @author <a href="mailto:[email protected]";>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 if jobs could not be loaded
-     */
-    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.
-     * @throws 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.
-     * @throws 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 true to enable the scheduler
-     *
-     */
-    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.
-     * @throws 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();
-            }
-        }
-    }
-}
+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:[email protected]";>Dave Bryson</a>
+ * @author <a href="mailto:[email protected]";>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 if jobs could not be loaded
+     */
+    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.
+     * @throws 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.
+     * @throws 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 true to enable the scheduler
+     *
+     */
+    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.
+     * @throws 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/JobQueue.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobQueue.java?rev=1812628&r1=1812627&r2=1812628&view=diff
==============================================================================
--- 
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobQueue.java 
(original)
+++ 
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobQueue.java 
Thu Oct 19 12:34:25 2017
@@ -1,197 +1,197 @@
-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.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Vector;
-
-import org.apache.turbine.util.TurbineException;
-
-/**
- * Queue for the scheduler.
- *
- * @author <a href="mailto:[email protected]";>Dave Bryson</a>
- * @author <a href="mailto:[email protected]";>Quinton McCombs</a>
- * @version $Id: JobQueue.java 615328 2008-01-25 20:25:05Z tv $
- * @param <J> a specialized job entry type
- */
-public class JobQueue<J extends JobEntry>
-{
-    /**
-     * The queue of <code>JobEntry</code> objects.
-     */
-    private Vector<J> queue = null;
-
-    /**
-     * Creates a new instance.
-     */
-    public JobQueue()
-    {
-        queue = new Vector<J>(10);
-    }
-
-    /**
-     * Return the next job off the top of the queue, or <code>null</code> if
-     * there are no jobs in the queue.
-     *
-     * @return The next job in the queue.
-     */
-    public J getNext()
-    {
-        if (queue.size() > 0)
-        {
-            return queue.elementAt(0);
-        }
-        else
-        {
-            return null;
-        }
-    }
-
-    /**
-     * Return a specific job.
-     *
-     * @param je The JobEntry we are looking for.
-     * @return A JobEntry.
-     */
-    public J getJob(J je)
-    {
-        int index = -1;
-
-        if (je != null)
-        {
-            index = queue.indexOf(je);
-        }
-
-        if (index < 0)
-        {
-            return null;
-        }
-        else
-        {
-            return queue.elementAt(index);
-        }
-    }
-
-    /**
-     * List jobs in the queue.  This is used by the scheduler UI.
-     *
-     * @return A Vector of <code>JobEntry</code> objects.
-     */
-    @SuppressWarnings("unchecked")
-    public Vector<J> list()
-    {
-        if (queue != null && queue.size() > 0)
-        {
-            return (Vector<J>) queue.clone();
-        }
-        else
-        {
-            return null;
-        }
-    }
-
-    /**
-     * Add a job to the queue.
-     *
-     * @param je A JobEntry job.
-     */
-    public synchronized void add(J je)
-    {
-        queue.addElement(je);
-        sortQueue();
-    }
-
-    /**
-     * Batch load jobs.  Retains any already enqueued jobs.  Called on
-     * <code>SchedulerService</code> start-up.
-     *
-     * @param jobEntries A list of the <code>JobEntry</code> objects to load.
-     */
-    public synchronized void batchLoad(List<J> jobEntries)
-    {
-        if (jobEntries != null)
-        {
-            queue.addAll(jobEntries);
-            sortQueue();
-        }
-
-    }
-
-    /**
-     * Remove a job from the queue.
-     *
-     * @param je A JobEntry with the job to remove.
-     */
-    public synchronized void remove(J je)
-    {
-        queue.removeElement(je);
-        sortQueue();
-    }
-
-    /**
-     * Modify a job on the queue.
-     *
-     * @param je A JobEntry with the job to modify
-     * @throws TurbineException if the runtime calculation fails
-     */
-    public synchronized void modify(J je) throws TurbineException
-    {
-        remove(je);
-        je.calcRunTime();
-        this.add(je);
-        sortQueue();
-    }
-
-    /**
-     * Update the job for its next run time.
-     *
-     * @param je A JobEntry to be updated.
-     * @throws TurbineException a generic exception.
-     */
-    public synchronized void updateQueue(J je)
-            throws TurbineException
-    {
-        je.calcRunTime();
-        sortQueue();
-    }
-
-    /**
-     * Re-sort the existing queue.  Consumers of this method should be
-     * <code>synchronized</code>.
-     */
-    private void sortQueue()
-    {
-        Comparator<J> aComparator = new Comparator<J>()
-        {
-            @Override
-            public int compare(J o1, J o2)
-            {
-                Long time1 = Long.valueOf(o1.getNextRuntime());
-                Long time2 = Long.valueOf(o2.getNextRuntime());
-                return (time1.compareTo(time2));
-            }
-        };
-
-        Collections.sort(queue, aComparator);
-    }
-}
+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.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Vector;
+
+import org.apache.turbine.util.TurbineException;
+
+/**
+ * Queue for the scheduler.
+ *
+ * @author <a href="mailto:[email protected]";>Dave Bryson</a>
+ * @author <a href="mailto:[email protected]";>Quinton McCombs</a>
+ * @version $Id: JobQueue.java 615328 2008-01-25 20:25:05Z tv $
+ * @param <J> a specialized job entry type
+ */
+public class JobQueue<J extends JobEntry>
+{
+    /**
+     * The queue of <code>JobEntry</code> objects.
+     */
+    private Vector<J> queue = null;
+
+    /**
+     * Creates a new instance.
+     */
+    public JobQueue()
+    {
+        queue = new Vector<J>(10);
+    }
+
+    /**
+     * Return the next job off the top of the queue, or <code>null</code> if
+     * there are no jobs in the queue.
+     *
+     * @return The next job in the queue.
+     */
+    public J getNext()
+    {
+        if (queue.size() > 0)
+        {
+            return queue.elementAt(0);
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    /**
+     * Return a specific job.
+     *
+     * @param je The JobEntry we are looking for.
+     * @return A JobEntry.
+     */
+    public J getJob(J je)
+    {
+        int index = -1;
+
+        if (je != null)
+        {
+            index = queue.indexOf(je);
+        }
+
+        if (index < 0)
+        {
+            return null;
+        }
+        else
+        {
+            return queue.elementAt(index);
+        }
+    }
+
+    /**
+     * List jobs in the queue.  This is used by the scheduler UI.
+     *
+     * @return A Vector of <code>JobEntry</code> objects.
+     */
+    @SuppressWarnings("unchecked")
+    public Vector<J> list()
+    {
+        if (queue != null && queue.size() > 0)
+        {
+            return (Vector<J>) queue.clone();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    /**
+     * Add a job to the queue.
+     *
+     * @param je A JobEntry job.
+     */
+    public synchronized void add(J je)
+    {
+        queue.addElement(je);
+        sortQueue();
+    }
+
+    /**
+     * Batch load jobs.  Retains any already enqueued jobs.  Called on
+     * <code>SchedulerService</code> start-up.
+     *
+     * @param jobEntries A list of the <code>JobEntry</code> objects to load.
+     */
+    public synchronized void batchLoad(List<J> jobEntries)
+    {
+        if (jobEntries != null)
+        {
+            queue.addAll(jobEntries);
+            sortQueue();
+        }
+
+    }
+
+    /**
+     * Remove a job from the queue.
+     *
+     * @param je A JobEntry with the job to remove.
+     */
+    public synchronized void remove(J je)
+    {
+        queue.removeElement(je);
+        sortQueue();
+    }
+
+    /**
+     * Modify a job on the queue.
+     *
+     * @param je A JobEntry with the job to modify
+     * @throws TurbineException if the runtime calculation fails
+     */
+    public synchronized void modify(J je) throws TurbineException
+    {
+        remove(je);
+        je.calcRunTime();
+        this.add(je);
+        sortQueue();
+    }
+
+    /**
+     * Update the job for its next run time.
+     *
+     * @param je A JobEntry to be updated.
+     * @throws TurbineException a generic exception.
+     */
+    public synchronized void updateQueue(J je)
+            throws TurbineException
+    {
+        je.calcRunTime();
+        sortQueue();
+    }
+
+    /**
+     * Re-sort the existing queue.  Consumers of this method should be
+     * <code>synchronized</code>.
+     */
+    private void sortQueue()
+    {
+        Comparator<J> aComparator = new Comparator<J>()
+        {
+            @Override
+            public int compare(J o1, J o2)
+            {
+                Long time1 = Long.valueOf(o1.getNextRuntime());
+                Long time2 = Long.valueOf(o2.getNextRuntime());
+                return (time1.compareTo(time2));
+            }
+        };
+
+        Collections.sort(queue, aComparator);
+    }
+}

Modified: 
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/QuartzSchedulerService.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/schedule/QuartzSchedulerService.java?rev=1812628&r1=1812627&r2=1812628&view=diff
==============================================================================
--- 
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/QuartzSchedulerService.java
 (original)
+++ 
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/QuartzSchedulerService.java
 Thu Oct 19 12:34:25 2017
@@ -1,415 +1,415 @@
-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.text.ParseException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.fulcrum.quartz.QuartzScheduler;
-import org.apache.turbine.services.InitializationException;
-import org.apache.turbine.services.TurbineBaseService;
-import org.apache.turbine.services.TurbineServices;
-import org.apache.turbine.util.TurbineException;
-import org.quartz.CronScheduleBuilder;
-import org.quartz.JobBuilder;
-import org.quartz.JobDetail;
-import org.quartz.JobKey;
-import org.quartz.Scheduler;
-import org.quartz.SchedulerException;
-import org.quartz.Trigger;
-import org.quartz.TriggerBuilder;
-import org.quartz.impl.matchers.GroupMatcher;
-
-/**
- * Service for a quartz scheduler.
- *
- * @author <a href="mailto:[email protected]";>Thomas Vandahl</a>
- */
-public class QuartzSchedulerService
-        extends TurbineBaseService
-        implements ScheduleService
-{
-    /** Logging */
-    protected static Log log = LogFactory.getLog(ScheduleService.LOGGER_NAME);
-
-    /** Current status of the scheduler */
-    protected boolean enabled = false;
-
-    /** The Quartz scheduler instance */
-    private Scheduler scheduler;
-
-    /**
-     * Initializes the SchedulerService. Retrieves the Quartz {@link 
#scheduler} from the Fulcrum {@link QuartzScheduler} service. 
-     *
-     * @throws InitializationException Something went wrong in the init
-     *         stage
-     */
-    @Override
-    public void init()
-            throws InitializationException
-    {
-        setEnabled(getConfiguration().getBoolean("enabled", true));
-        QuartzScheduler qs = (QuartzScheduler) TurbineServices.getInstance()
-            .getService(QuartzScheduler.class.getName());
-        this.scheduler = qs.getScheduler();
-
-        restart();
-        setInit(true);
-    }
-
-    /**
-     * Shutdowns the service.
-     *
-     * This methods interrupts the housekeeping thread.
-     */
-    @Override
-    public void shutdown()
-    {
-        try
-        {
-            this.scheduler.shutdown();
-        }
-        catch (SchedulerException e)
-        {
-            log.error("Could not shut down the scheduler service", e);
-        }
-    }
-
-    /**
-     * @see org.apache.turbine.services.schedule.ScheduleService#newJob(int, 
int, int, int, int, java.lang.String)
-     */
-    @Override
-    public JobEntry newJob(int sec, int min, int hour, int wd, int day_mo, 
String task) throws TurbineException
-    {
-        try
-        {
-            JobDetail jd = JobBuilder.newJob(JobEntryQuartz.class)
-                    .withIdentity(task, JobEntryQuartz.DEFAULT_JOB_GROUP_NAME)
-                    .build();
-
-            CronScheduleBuilder csb = createCronExpression(sec, min, hour, wd, 
day_mo);
-
-            Trigger t = TriggerBuilder.newTrigger()
-                    .withIdentity(task, JobEntryQuartz.DEFAULT_JOB_GROUP_NAME)
-                    .withSchedule(csb)
-                    .forJob(jd)
-                    .build();
-
-            JobEntryQuartz jeq = new JobEntryQuartz(t, jd);
-
-            return jeq;
-        }
-        catch (ParseException e)
-        {
-            throw new TurbineException("Could not create scheduled job " + 
task, e);
-        }
-    }
-
-    /**
-     * Create a Cron expression from separate elements
-     *
-     * @param sec Value for entry "seconds".
-     * @param min Value for entry "minutes".
-     * @param hour Value for entry "hours".
-     * @param wd Value for entry "week days".
-     * @param day_mo Value for entry "month days".
-     * @return a CronScheduleBuilder
-     * @throws ParseException if the expression is invalid
-     */
-    private CronScheduleBuilder createCronExpression(int sec, int min, int 
hour, int wd, int day_mo) throws ParseException
-    {
-        StringBuilder sb = new StringBuilder();
-        sb.append(sec == -1 ? "*" : String.valueOf(sec)).append(' ');
-        sb.append(min == -1 ? "*" : String.valueOf(min)).append(' ');
-        sb.append(hour == -1 ? "*" : String.valueOf(hour)).append(' ');
-        if (day_mo == -1)
-        {
-            sb.append(wd == -1 ? "*" : "?").append(' ');
-        }
-        else
-        {
-            sb.append(day_mo).append(' ');
-        }
-        sb.append("* "); // Month not supported
-        if (day_mo == -1)
-        {
-            sb.append(wd == -1 ? "?" : String.valueOf(wd));
-        }
-        else
-        {
-            sb.append("*");
-        }
-
-        return CronScheduleBuilder.cronSchedule(sb.toString());
-    }
-
-    /**
-     * Get a specific Job from Storage.
-     *
-     * @param oid The int id for the job.
-     * @return A JobEntry.
-     * @throws TurbineException job could not be retrieved.
-     */
-    @Override
-    public JobEntry getJob(int oid)
-            throws TurbineException
-    {
-        for (JobEntry je : listJobs())
-        {
-            if (je.getJobId() == oid)
-            {
-                return je;
-            }
-        }
-
-        throw new TurbineException("Could not retrieve scheduled job with id " 
+ oid);
-    }
-
-    /**
-     * 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
-    {
-        try
-        {
-            // Update the scheduler.
-            JobEntryQuartz jq = downCast(je);
-            this.scheduler.scheduleJob(jq.getJobDetail(), jq.getJobTrigger());
-        }
-        catch (SchedulerException e)
-        {
-            throw new TurbineException("Problem adding Scheduled Job: " + 
je.getTask(), e);
-        }
-    }
-
-    /**
-     * Remove a job from the queue.
-     *
-     * @param je A JobEntry with the job to remove.
-     * @throws TurbineException job could not be removed
-     */
-    @Override
-    public void removeJob(JobEntry je)
-            throws TurbineException
-    {
-        try
-        {
-            JobEntryQuartz jq = downCast(je);
-            this.scheduler.deleteJob(jq.getJobTrigger().getJobKey());
-
-        }
-        catch (SchedulerException e)
-        {
-            throw new TurbineException("Problem removing Scheduled Job: " + 
je.getTask(), e);
-        }
-    }
-
-    /**
-     * Add or update a job.
-     *
-     * @param je A JobEntry with the job to modify
-     * @throws TurbineException job could not be updated
-     */
-    @Override
-    public void updateJob(JobEntry je)
-            throws TurbineException
-    {
-        try
-        {
-            // Update the scheduler.
-            JobEntryQuartz jq = downCast(je);
-            this.scheduler.rescheduleJob(jq.getJobTrigger().getKey(), 
jq.getJobTrigger());
-        }
-        catch (SchedulerException e)
-        {
-            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<? extends JobEntry> listJobs()
-    {
-        List<JobEntryQuartz> jobs = new ArrayList<JobEntryQuartz>();
-
-        try
-        {
-            @SuppressWarnings("unchecked") // See QTZ-184
-            GroupMatcher<JobKey> groupMatcher = 
GroupMatcher.groupEquals(JobEntryQuartz.DEFAULT_JOB_GROUP_NAME);
-            Set<JobKey> jobKeys = scheduler.getJobKeys(groupMatcher);
-            for (JobKey jk : jobKeys)
-            {
-                List<? extends Trigger> triggers = 
this.scheduler.getTriggersOfJob(jk);
-
-                if (triggers == null || triggers.isEmpty())
-                {
-                    continue; // skip
-                }
-                JobDetail jd = this.scheduler.getJobDetail(jk);
-                JobEntryQuartz job = new JobEntryQuartz(triggers.get(0), jd);
-                job.setJobId(jk.hashCode());
-                jobs.add(job);
-            }
-        }
-        catch (SchedulerException e)
-        {
-            log.error("Problem listing Scheduled Jobs", e);
-        }
-
-        return jobs;
-    }
-
-
-    /**
-     * 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");
-        try
-        {
-            this.scheduler.standby();
-            enabled = false;
-        }
-        catch (SchedulerException e)
-        {
-            log.error("Could not stop scheduler", e);
-        }
-    }
-
-    /**
-     * 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");
-            try
-            {
-                if (!this.scheduler.isStarted())
-                {
-                    this.scheduler.start();
-                }
-                else
-                {
-                    notify();
-                }
-            }
-            catch (SchedulerException e)
-            {
-                log.error("Could not start scheduler", e);
-            }
-        }
-    }
-
-    /**
-     * @param je a generic job entry
-     * @throws TurbineException
-     *
-     * @return A downcasted JobEntry type
-     */
-    private JobEntryQuartz downCast(JobEntry je) throws TurbineException
-    {
-        if (je instanceof JobEntryQuartz)
-        {
-            return (JobEntryQuartz)je;
-        }
-        else
-        {
-            throw new TurbineException("Invalid job type for this scheduler " 
+ je.getClass());
-        }
-    }
-
-    /**
-     * Exposing the Quartz scheduler to handle jobs/triggers in more detail.
-     * 
-     * @return the {@link Scheduler} of this service.
-     */
-       public Scheduler getScheduler()
-       {
-               return scheduler;
-       }
-       
-       /**
-        * Builds a {@link JobEntryQuartz} from Quartz trigger/job.
-        * 
-        * The developer should be aware to set identity/context properly, i.e. 
to 
-     * {@value JobEntryQuartz#DEFAULT_JOB_GROUP_NAME}, if adding triggers/jobs.
-        * 
-        * @param trigger a Quartz {@link Trigger}.
-        * @param jd a Quartz {@link JobDetail} (built from a {@link Job} with 
{@link JobBuilder}).
-        * @return A JobEntryQuartz.
-        */
-       public JobEntryQuartz buildJobEntry(Trigger trigger, JobDetail jd) {
-        JobEntryQuartz job = new JobEntryQuartz(trigger, jd);
-               return job;
-       }
-}
-
+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.text.ParseException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.fulcrum.quartz.QuartzScheduler;
+import org.apache.turbine.services.InitializationException;
+import org.apache.turbine.services.TurbineBaseService;
+import org.apache.turbine.services.TurbineServices;
+import org.apache.turbine.util.TurbineException;
+import org.quartz.CronScheduleBuilder;
+import org.quartz.JobBuilder;
+import org.quartz.JobDetail;
+import org.quartz.JobKey;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.Trigger;
+import org.quartz.TriggerBuilder;
+import org.quartz.impl.matchers.GroupMatcher;
+
+/**
+ * Service for a quartz scheduler.
+ *
+ * @author <a href="mailto:[email protected]";>Thomas Vandahl</a>
+ */
+public class QuartzSchedulerService
+        extends TurbineBaseService
+        implements ScheduleService
+{
+    /** Logging */
+    protected static Log log = LogFactory.getLog(ScheduleService.LOGGER_NAME);
+
+    /** Current status of the scheduler */
+    protected boolean enabled = false;
+
+    /** The Quartz scheduler instance */
+    private Scheduler scheduler;
+
+    /**
+     * Initializes the SchedulerService. Retrieves the Quartz {@link 
#scheduler} from the Fulcrum {@link QuartzScheduler} service.
+     *
+     * @throws InitializationException Something went wrong in the init
+     *         stage
+     */
+    @Override
+    public void init()
+            throws InitializationException
+    {
+        setEnabled(getConfiguration().getBoolean("enabled", true));
+        QuartzScheduler qs = (QuartzScheduler) TurbineServices.getInstance()
+            .getService(QuartzScheduler.class.getName());
+        this.scheduler = qs.getScheduler();
+
+        restart();
+        setInit(true);
+    }
+
+    /**
+     * Shutdowns the service.
+     *
+     * This methods interrupts the housekeeping thread.
+     */
+    @Override
+    public void shutdown()
+    {
+        try
+        {
+            this.scheduler.shutdown();
+        }
+        catch (SchedulerException e)
+        {
+            log.error("Could not shut down the scheduler service", e);
+        }
+    }
+
+    /**
+     * @see org.apache.turbine.services.schedule.ScheduleService#newJob(int, 
int, int, int, int, java.lang.String)
+     */
+    @Override
+    public JobEntry newJob(int sec, int min, int hour, int wd, int day_mo, 
String task) throws TurbineException
+    {
+        try
+        {
+            JobDetail jd = JobBuilder.newJob(JobEntryQuartz.class)
+                    .withIdentity(task, JobEntryQuartz.DEFAULT_JOB_GROUP_NAME)
+                    .build();
+
+            CronScheduleBuilder csb = createCronExpression(sec, min, hour, wd, 
day_mo);
+
+            Trigger t = TriggerBuilder.newTrigger()
+                    .withIdentity(task, JobEntryQuartz.DEFAULT_JOB_GROUP_NAME)
+                    .withSchedule(csb)
+                    .forJob(jd)
+                    .build();
+
+            JobEntryQuartz jeq = new JobEntryQuartz(t, jd);
+
+            return jeq;
+        }
+        catch (ParseException e)
+        {
+            throw new TurbineException("Could not create scheduled job " + 
task, e);
+        }
+    }
+
+    /**
+     * Create a Cron expression from separate elements
+     *
+     * @param sec Value for entry "seconds".
+     * @param min Value for entry "minutes".
+     * @param hour Value for entry "hours".
+     * @param wd Value for entry "week days".
+     * @param day_mo Value for entry "month days".
+     * @return a CronScheduleBuilder
+     * @throws ParseException if the expression is invalid
+     */
+    private CronScheduleBuilder createCronExpression(int sec, int min, int 
hour, int wd, int day_mo) throws ParseException
+    {
+        StringBuilder sb = new StringBuilder();
+        sb.append(sec == -1 ? "*" : String.valueOf(sec)).append(' ');
+        sb.append(min == -1 ? "*" : String.valueOf(min)).append(' ');
+        sb.append(hour == -1 ? "*" : String.valueOf(hour)).append(' ');
+        if (day_mo == -1)
+        {
+            sb.append(wd == -1 ? "*" : "?").append(' ');
+        }
+        else
+        {
+            sb.append(day_mo).append(' ');
+        }
+        sb.append("* "); // Month not supported
+        if (day_mo == -1)
+        {
+            sb.append(wd == -1 ? "?" : String.valueOf(wd));
+        }
+        else
+        {
+            sb.append("*");
+        }
+
+        return CronScheduleBuilder.cronSchedule(sb.toString());
+    }
+
+    /**
+     * Get a specific Job from Storage.
+     *
+     * @param oid The int id for the job.
+     * @return A JobEntry.
+     * @throws TurbineException job could not be retrieved.
+     */
+    @Override
+    public JobEntry getJob(int oid)
+            throws TurbineException
+    {
+        for (JobEntry je : listJobs())
+        {
+            if (je.getJobId() == oid)
+            {
+                return je;
+            }
+        }
+
+        throw new TurbineException("Could not retrieve scheduled job with id " 
+ oid);
+    }
+
+    /**
+     * 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
+    {
+        try
+        {
+            // Update the scheduler.
+            JobEntryQuartz jq = downCast(je);
+            this.scheduler.scheduleJob(jq.getJobDetail(), jq.getJobTrigger());
+        }
+        catch (SchedulerException e)
+        {
+            throw new TurbineException("Problem adding Scheduled Job: " + 
je.getTask(), e);
+        }
+    }
+
+    /**
+     * Remove a job from the queue.
+     *
+     * @param je A JobEntry with the job to remove.
+     * @throws TurbineException job could not be removed
+     */
+    @Override
+    public void removeJob(JobEntry je)
+            throws TurbineException
+    {
+        try
+        {
+            JobEntryQuartz jq = downCast(je);
+            this.scheduler.deleteJob(jq.getJobTrigger().getJobKey());
+
+        }
+        catch (SchedulerException e)
+        {
+            throw new TurbineException("Problem removing Scheduled Job: " + 
je.getTask(), e);
+        }
+    }
+
+    /**
+     * Add or update a job.
+     *
+     * @param je A JobEntry with the job to modify
+     * @throws TurbineException job could not be updated
+     */
+    @Override
+    public void updateJob(JobEntry je)
+            throws TurbineException
+    {
+        try
+        {
+            // Update the scheduler.
+            JobEntryQuartz jq = downCast(je);
+            this.scheduler.rescheduleJob(jq.getJobTrigger().getKey(), 
jq.getJobTrigger());
+        }
+        catch (SchedulerException e)
+        {
+            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<? extends JobEntry> listJobs()
+    {
+        List<JobEntryQuartz> jobs = new ArrayList<JobEntryQuartz>();
+
+        try
+        {
+            @SuppressWarnings("unchecked") // See QTZ-184
+            GroupMatcher<JobKey> groupMatcher = 
GroupMatcher.groupEquals(JobEntryQuartz.DEFAULT_JOB_GROUP_NAME);
+            Set<JobKey> jobKeys = scheduler.getJobKeys(groupMatcher);
+            for (JobKey jk : jobKeys)
+            {
+                List<? extends Trigger> triggers = 
this.scheduler.getTriggersOfJob(jk);
+
+                if (triggers == null || triggers.isEmpty())
+                {
+                    continue; // skip
+                }
+                JobDetail jd = this.scheduler.getJobDetail(jk);
+                JobEntryQuartz job = new JobEntryQuartz(triggers.get(0), jd);
+                job.setJobId(jk.hashCode());
+                jobs.add(job);
+            }
+        }
+        catch (SchedulerException e)
+        {
+            log.error("Problem listing Scheduled Jobs", e);
+        }
+
+        return jobs;
+    }
+
+
+    /**
+     * 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");
+        try
+        {
+            this.scheduler.standby();
+            enabled = false;
+        }
+        catch (SchedulerException e)
+        {
+            log.error("Could not stop scheduler", e);
+        }
+    }
+
+    /**
+     * 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");
+            try
+            {
+                if (!this.scheduler.isStarted())
+                {
+                    this.scheduler.start();
+                }
+                else
+                {
+                    notify();
+                }
+            }
+            catch (SchedulerException e)
+            {
+                log.error("Could not start scheduler", e);
+            }
+        }
+    }
+
+    /**
+     * @param je a generic job entry
+     * @throws TurbineException
+     *
+     * @return A downcasted JobEntry type
+     */
+    private JobEntryQuartz downCast(JobEntry je) throws TurbineException
+    {
+        if (je instanceof JobEntryQuartz)
+        {
+            return (JobEntryQuartz)je;
+        }
+        else
+        {
+            throw new TurbineException("Invalid job type for this scheduler " 
+ je.getClass());
+        }
+    }
+
+    /**
+     * Exposing the Quartz scheduler to handle jobs/triggers in more detail.
+     *
+     * @return the {@link Scheduler} of this service.
+     */
+       public Scheduler getScheduler()
+       {
+               return scheduler;
+       }
+
+       /**
+        * Builds a {@link JobEntryQuartz} from Quartz trigger/job.
+        *
+        * The developer should be aware to set identity/context properly, i.e. 
to
+     * {@value JobEntryQuartz#DEFAULT_JOB_GROUP_NAME}, if adding triggers/jobs.
+        *
+        * @param trigger a Quartz {@link Trigger}.
+        * @param jd a Quartz {@link JobDetail} (built from a {@link Job} with 
{@link JobBuilder}).
+        * @return A JobEntryQuartz.
+        */
+       public JobEntryQuartz buildJobEntry(Trigger trigger, JobDetail jd) {
+        JobEntryQuartz job = new JobEntryQuartz(trigger, jd);
+               return job;
+       }
+}
+

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=1812628&r1=1812627&r2=1812628&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 Oct 19 12:34:25 2017
@@ -1,177 +1,177 @@
-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.torque.TorqueException;
-import org.apache.torque.criteria.Criteria;
-import org.apache.turbine.util.TurbineException;
-
-/**
- * Service for a cron like scheduler.
- *
- * @author <a href="mailto:[email protected]";>Dave Bryson</a>
- * @author <a href="mailto:[email protected]";>Quinton McCombs</a>
- * @version $Id: TorqueSchedulerService.java 534527 2007-05-02 16:10:59Z tv $
- *
- * @deprecated Use {@link QuartzSchedulerService} instead
- */
-@Deprecated
-public class TorqueSchedulerService extends AbstractSchedulerService
-{
-    /**
-     * Load all jobs from configuration storage
-     *
-     * @return the list of pre-configured jobs
-     * @throws TurbineException
-     */
-    @Override
-    protected List<? extends JobEntry> loadJobs() throws TurbineException
-    {
-        // Load all from cold storage.
-        try
-        {
-            List<JobEntryTorque> jobsTorque = JobEntryTorquePeer.doSelect(new 
Criteria());
-
-            for (JobEntryTorque job : jobsTorque)
-            {
-                job.calcRunTime();
-            }
-
-            return jobsTorque;
-        }
-        catch (TorqueException e)
-        {
-            throw new TurbineException("Error retrieving initial job list from 
persistent storage.", e);
-        }
-    }
-
-    /**
-     * @see org.apache.turbine.services.schedule.ScheduleService#newJob(int, 
int, int, int, int, java.lang.String)
-     */
-    @Override
-    public JobEntry newJob(int sec, int min, int hour, int wd, int day_mo, 
String task) throws TurbineException
-    {
-        JobEntryTorque jet = new JobEntryTorque();
-        jet.setSecond(sec);
-        jet.setMinute(min);
-        jet.setHour(hour);
-        jet.setWeekDay(wd);
-        jet.setDayOfMonth(day_mo);
-        jet.setTask(task);
-
-        return jet;
-    }
-
-    /**
-     * Get a specific Job from Storage.
-     *
-     * @param oid
-     *            The int id for the job.
-     * @return A JobEntry.
-     * @throws TurbineException
-     *                job could not be retrieved.
-     */
-    @Override
-    public JobEntry getJob(int oid) throws TurbineException
-    {
-        try
-        {
-            JobEntryTorque je = JobEntryTorquePeer.retrieveByPK(oid);
-            return scheduleQueue.getJob(je);
-        }
-        catch (TorqueException e)
-        {
-            throw new TurbineException("Error retrieving job from persistent 
storage.", e);
-        }
-    }
-
-    /**
-     * Remove a job from the queue.
-     *
-     * @param je
-     *            A JobEntry with the job to remove.
-     * @throws TurbineException
-     *                job could not be removed
-     */
-    @Override
-    public void removeJob(JobEntry je) throws TurbineException
-    {
-        try
-        {
-            // First remove from DB.
-            Criteria c = new Criteria().where(JobEntryTorquePeer.JOB_ID, 
Integer.valueOf(je.getJobId()));
-            JobEntryTorquePeer.doDelete(c);
-
-            // Remove from the queue.
-            scheduleQueue.remove(je);
-
-            // restart the scheduler
-            restart();
-        }
-        catch (TorqueException e)
-        {
-            throw new TurbineException("Problem removing Scheduled Job: " + 
je.getTask(), e);
-        }
-    }
-
-    /**
-     * Add or update a job.
-     *
-     * @param je
-     *            A JobEntry with the job to modify
-     * @throws TurbineException
-     *             job could not be updated
-     */
-    @Override
-    public void updateJob(JobEntry je) throws TurbineException
-    {
-        try
-        {
-            je.calcRunTime();
-
-            // Update the queue.
-            if (je.isNew())
-            {
-                scheduleQueue.add(je);
-            }
-            else
-            {
-                scheduleQueue.modify(je);
-            }
-
-            if (je instanceof JobEntryTorque)
-            {
-                ((JobEntryTorque)je).save();
-            }
-
-            restart();
-        }
-        catch (TorqueException e)
-        {
-            throw new TurbineException("Problem persisting Scheduled Job: " + 
je.getTask(), e);
-        }
-        catch (TurbineException e)
-        {
-            throw new TurbineException("Problem updating Scheduled Job: " + 
je.getTask(), e);
-        }
-    }
-}
+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.torque.TorqueException;
+import org.apache.torque.criteria.Criteria;
+import org.apache.turbine.util.TurbineException;
+
+/**
+ * Service for a cron like scheduler.
+ *
+ * @author <a href="mailto:[email protected]";>Dave Bryson</a>
+ * @author <a href="mailto:[email protected]";>Quinton McCombs</a>
+ * @version $Id: TorqueSchedulerService.java 534527 2007-05-02 16:10:59Z tv $
+ *
+ * @deprecated Use {@link QuartzSchedulerService} instead
+ */
+@Deprecated
+public class TorqueSchedulerService extends AbstractSchedulerService
+{
+    /**
+     * Load all jobs from configuration storage
+     *
+     * @return the list of pre-configured jobs
+     * @throws TurbineException
+     */
+    @Override
+    protected List<? extends JobEntry> loadJobs() throws TurbineException
+    {
+        // Load all from cold storage.
+        try
+        {
+            List<JobEntryTorque> jobsTorque = JobEntryTorquePeer.doSelect(new 
Criteria());
+
+            for (JobEntryTorque job : jobsTorque)
+            {
+                job.calcRunTime();
+            }
+
+            return jobsTorque;
+        }
+        catch (TorqueException e)
+        {
+            throw new TurbineException("Error retrieving initial job list from 
persistent storage.", e);
+        }
+    }
+
+    /**
+     * @see org.apache.turbine.services.schedule.ScheduleService#newJob(int, 
int, int, int, int, java.lang.String)
+     */
+    @Override
+    public JobEntry newJob(int sec, int min, int hour, int wd, int day_mo, 
String task) throws TurbineException
+    {
+        JobEntryTorque jet = new JobEntryTorque();
+        jet.setSecond(sec);
+        jet.setMinute(min);
+        jet.setHour(hour);
+        jet.setWeekDay(wd);
+        jet.setDayOfMonth(day_mo);
+        jet.setTask(task);
+
+        return jet;
+    }
+
+    /**
+     * Get a specific Job from Storage.
+     *
+     * @param oid
+     *            The int id for the job.
+     * @return A JobEntry.
+     * @throws TurbineException
+     *                job could not be retrieved.
+     */
+    @Override
+    public JobEntry getJob(int oid) throws TurbineException
+    {
+        try
+        {
+            JobEntryTorque je = JobEntryTorquePeer.retrieveByPK(oid);
+            return scheduleQueue.getJob(je);
+        }
+        catch (TorqueException e)
+        {
+            throw new TurbineException("Error retrieving job from persistent 
storage.", e);
+        }
+    }
+
+    /**
+     * Remove a job from the queue.
+     *
+     * @param je
+     *            A JobEntry with the job to remove.
+     * @throws TurbineException
+     *                job could not be removed
+     */
+    @Override
+    public void removeJob(JobEntry je) throws TurbineException
+    {
+        try
+        {
+            // First remove from DB.
+            Criteria c = new Criteria().where(JobEntryTorquePeer.JOB_ID, 
Integer.valueOf(je.getJobId()));
+            JobEntryTorquePeer.doDelete(c);
+
+            // Remove from the queue.
+            scheduleQueue.remove(je);
+
+            // restart the scheduler
+            restart();
+        }
+        catch (TorqueException e)
+        {
+            throw new TurbineException("Problem removing Scheduled Job: " + 
je.getTask(), e);
+        }
+    }
+
+    /**
+     * Add or update a job.
+     *
+     * @param je
+     *            A JobEntry with the job to modify
+     * @throws TurbineException
+     *             job could not be updated
+     */
+    @Override
+    public void updateJob(JobEntry je) throws TurbineException
+    {
+        try
+        {
+            je.calcRunTime();
+
+            // Update the queue.
+            if (je.isNew())
+            {
+                scheduleQueue.add(je);
+            }
+            else
+            {
+                scheduleQueue.modify(je);
+            }
+
+            if (je instanceof JobEntryTorque)
+            {
+                ((JobEntryTorque)je).save();
+            }
+
+            restart();
+        }
+        catch (TorqueException e)
+        {
+            throw new TurbineException("Problem persisting Scheduled Job: " + 
je.getTask(), e);
+        }
+        catch (TurbineException e)
+        {
+            throw new TurbineException("Problem updating Scheduled Job: " + 
je.getTask(), e);
+        }
+    }
+}

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=1812628&r1=1812627&r2=1812628&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 Oct 19 12:34:25 2017
@@ -1,179 +1,179 @@
-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.ArrayList;
-import java.util.List;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.lang.StringUtils;
-import org.apache.turbine.util.TurbineException;
-
-/**
- * Service for a cron like scheduler that uses the
- * 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 initialize the jobs.
- * An example is given below.  The job names are the class names that
- * extend ScheduledJob.
- *
- * <PRE>
- *
- * services.SchedulerService.scheduler.jobs=scheduledJobName,scheduledJobName2
- *
- * services.SchedulerService.scheduler.job.scheduledJobName.ID=1
- * services.SchedulerService.scheduler.job.scheduledJobName.SECOND=-1
- * services.SchedulerService.scheduler.job.scheduledJobName.MINUTE=-1
- * services.SchedulerService.scheduler.job.scheduledJobName.HOUR=7
- * services.SchedulerService.scheduler.job.scheduledJobName.WEEKDAY=-1
- * services.SchedulerService.scheduler.job.scheduledJobName.DAY_OF_MONTH=-1
- *
- * services.SchedulerService.scheduler.job.scheduledJobName2.ID=1
- * services.SchedulerService.scheduler.job.scheduledJobName2.SECOND=-1
- * services.SchedulerService.scheduler.job.scheduledJobName2.MINUTE=-1
- * services.SchedulerService.scheduler.job.scheduledJobName2.HOUR=7
- * services.SchedulerService.scheduler.job.scheduledJobName2.WEEKDAY=-1
- * services.SchedulerService.scheduler.job.scheduledJobName2.DAY_OF_MONTH=-1
- *
- * </PRE>
- *
- * Based on TamboraSchedulerService written by John Thorhauer.
- *
- * @author <a href="mailto:[email protected]";>Jeff Brekke</a>
- * @author <a href="mailto:[email protected]";>John Thorhauer</a>
- * @author <a href="mailto:[email protected]";>Quinton McCombs</a>
- * @version $Id: TurbineNonPersistentSchedulerService.java 534527 2007-05-02 
16:10:59Z tv $
- *
- * @deprecated Use QuartzSchedulerService instead
- */
-@Deprecated
-public class TurbineNonPersistentSchedulerService extends 
AbstractSchedulerService
-{
-    /**
-     * @see 
org.apache.turbine.services.schedule.AbstractSchedulerService#loadJobs()
-     */
-    @Override
-    protected List<? extends JobEntry> loadJobs() throws TurbineException
-    {
-        Configuration conf = getConfiguration();
-        List<Object> jobProps = conf.getList("scheduler.jobs");
-        List<JobEntry> jobs = new ArrayList<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++)
-            {
-                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");
-                }
-
-                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);
-            }
-        }
-
-        return jobs;
-    }
-
-    /**
-     * @see org.apache.turbine.services.schedule.ScheduleService#newJob(int, 
int, int, int, int, java.lang.String)
-     */
-    @Override
-    public JobEntry newJob(int sec, int min, int hour, int wd, int day_mo, 
String task) throws TurbineException
-    {
-        return new JobEntryNonPersistent(sec, min, hour, wd, day_mo, task);
-    }
-
-    /**
-     * This method returns the job element from the internal queue.
-     *
-     * @param oid The int id for the job.
-     * @return A JobEntry.
-     * @throws TurbineException could not retrieve job
-     */
-    @Override
-    public JobEntry getJob(int oid)
-            throws TurbineException
-    {
-        JobEntry je = new JobEntryNonPersistent();
-        je.setJobId(oid);
-        return scheduleQueue.getJob(je);
-    }
-
-    /**
-     * Remove a job from the queue.
-     *
-     * @param je A JobEntry with the job to remove.
-     */
-    @Override
-    public void removeJob(JobEntry je)
-    {
-        // Remove from the queue.
-        scheduleQueue.remove(je);
-        restart();
-    }
-
-    /**
-     * Add/update a job
-     *
-     * @param je A JobEntry with the job to modify
-     * @throws TurbineException job could not be updated
-     */
-    @Override
-    public void updateJob(JobEntry je)
-            throws TurbineException
-    {
-        try
-        {
-            je.calcRunTime();
-
-            // Update the queue.
-            scheduleQueue.modify(je);
-            restart();
-        }
-        catch (Exception e)
-        {
-            throw new TurbineException("Problem updating Scheduled Job: " + 
je.getTask(), e);
-        }
-    }
-}
+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.ArrayList;
+import java.util.List;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
+import org.apache.turbine.util.TurbineException;
+
+/**
+ * Service for a cron like scheduler that uses the
+ * 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 initialize the jobs.
+ * An example is given below.  The job names are the class names that
+ * extend ScheduledJob.
+ *
+ * <PRE>
+ *
+ * services.SchedulerService.scheduler.jobs=scheduledJobName,scheduledJobName2
+ *
+ * services.SchedulerService.scheduler.job.scheduledJobName.ID=1
+ * services.SchedulerService.scheduler.job.scheduledJobName.SECOND=-1
+ * services.SchedulerService.scheduler.job.scheduledJobName.MINUTE=-1
+ * services.SchedulerService.scheduler.job.scheduledJobName.HOUR=7
+ * services.SchedulerService.scheduler.job.scheduledJobName.WEEKDAY=-1
+ * services.SchedulerService.scheduler.job.scheduledJobName.DAY_OF_MONTH=-1
+ *
+ * services.SchedulerService.scheduler.job.scheduledJobName2.ID=1
+ * services.SchedulerService.scheduler.job.scheduledJobName2.SECOND=-1
+ * services.SchedulerService.scheduler.job.scheduledJobName2.MINUTE=-1
+ * services.SchedulerService.scheduler.job.scheduledJobName2.HOUR=7
+ * services.SchedulerService.scheduler.job.scheduledJobName2.WEEKDAY=-1
+ * services.SchedulerService.scheduler.job.scheduledJobName2.DAY_OF_MONTH=-1
+ *
+ * </PRE>
+ *
+ * Based on TamboraSchedulerService written by John Thorhauer.
+ *
+ * @author <a href="mailto:[email protected]";>Jeff Brekke</a>
+ * @author <a href="mailto:[email protected]";>John Thorhauer</a>
+ * @author <a href="mailto:[email protected]";>Quinton McCombs</a>
+ * @version $Id: TurbineNonPersistentSchedulerService.java 534527 2007-05-02 
16:10:59Z tv $
+ *
+ * @deprecated Use QuartzSchedulerService instead
+ */
+@Deprecated
+public class TurbineNonPersistentSchedulerService extends 
AbstractSchedulerService
+{
+    /**
+     * @see 
org.apache.turbine.services.schedule.AbstractSchedulerService#loadJobs()
+     */
+    @Override
+    protected List<? extends JobEntry> loadJobs() throws TurbineException
+    {
+        Configuration conf = getConfiguration();
+        List<Object> jobProps = conf.getList("scheduler.jobs");
+        List<JobEntry> jobs = new ArrayList<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++)
+            {
+                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");
+                }
+
+                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);
+            }
+        }
+
+        return jobs;
+    }
+
+    /**
+     * @see org.apache.turbine.services.schedule.ScheduleService#newJob(int, 
int, int, int, int, java.lang.String)
+     */
+    @Override
+    public JobEntry newJob(int sec, int min, int hour, int wd, int day_mo, 
String task) throws TurbineException
+    {
+        return new JobEntryNonPersistent(sec, min, hour, wd, day_mo, task);
+    }
+
+    /**
+     * This method returns the job element from the internal queue.
+     *
+     * @param oid The int id for the job.
+     * @return A JobEntry.
+     * @throws TurbineException could not retrieve job
+     */
+    @Override
+    public JobEntry getJob(int oid)
+            throws TurbineException
+    {
+        JobEntry je = new JobEntryNonPersistent();
+        je.setJobId(oid);
+        return scheduleQueue.getJob(je);
+    }
+
+    /**
+     * Remove a job from the queue.
+     *
+     * @param je A JobEntry with the job to remove.
+     */
+    @Override
+    public void removeJob(JobEntry je)
+    {
+        // Remove from the queue.
+        scheduleQueue.remove(je);
+        restart();
+    }
+
+    /**
+     * Add/update a job
+     *
+     * @param je A JobEntry with the job to modify
+     * @throws TurbineException job could not be updated
+     */
+    @Override
+    public void updateJob(JobEntry je)
+            throws TurbineException
+    {
+        try
+        {
+            je.calcRunTime();
+
+            // Update the queue.
+            scheduleQueue.modify(je);
+            restart();
+        }
+        catch (Exception e)
+        {
+            throw new TurbineException("Problem updating Scheduled Job: " + 
je.getTask(), e);
+        }
+    }
+}


Reply via email to