Author: tv
Date: Sat Jul 25 19:22:57 2015
New Revision: 1692637
URL: http://svn.apache.org/r1692637
Log:
Add QuartzSchedulerService,
Rename TurbineSchedulerService to TorqueSchedulerService
Added:
turbine/core/trunk/conf/test/quartz.xml (with props)
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/AbstractJobEntry.java
- copied, changed from r1616985,
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntry.java
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntryNonPersistent.java
(with props)
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntryQuartz.java
(with props)
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/QuartzSchedulerService.java
(with props)
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TorqueSchedulerService.java
- copied, changed from r1620557,
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TurbineSchedulerService.java
Removed:
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntryInterface.java
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntryPeer.java
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntryRecordMapper.java
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TurbineSchedulerService.java
Modified:
turbine/core/trunk/conf/TurbineResources.properties
turbine/core/trunk/conf/test/ConfigurationBuilder.xml
turbine/core/trunk/conf/test/TestFulcrumComponents.properties
turbine/core/trunk/conf/test/fulcrumComponentConfiguration.xml
turbine/core/trunk/conf/test/fulcrumRoleConfiguration.xml
turbine/core/trunk/conf/test/intake.xml
turbine/core/trunk/src/changes/changes.xml
turbine/core/trunk/src/java/org/apache/turbine/services/intake/IntakeTool.java
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntry.java
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobQueue.java
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/ScheduleService.java
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/SchedulerTool.java
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TurbineNonPersistentSchedulerService.java
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TurbineScheduler.java
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/WorkerThread.java
turbine/core/trunk/src/test-cactus/testapp/WEB-INF/conf/TurbineComplete.properties
turbine/core/trunk/src/torque/schema/scheduler-schema.xml
Modified: turbine/core/trunk/conf/TurbineResources.properties
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/conf/TurbineResources.properties?rev=1692637&r1=1692636&r2=1692637&view=diff
==============================================================================
--- turbine/core/trunk/conf/TurbineResources.properties (original)
+++ turbine/core/trunk/conf/TurbineResources.properties Sat Jul 25 19:22:57 2015
@@ -333,7 +333,7 @@ services.AvalonComponentService.classnam
services.RunDataService.classname=org.apache.turbine.services.rundata.TurbineRunDataService
services.ServletService.classname=org.apache.turbine.services.servlet.TurbineServletService
services.AssemblerBrokerService.classname=org.apache.turbine.services.assemblerbroker.TurbineAssemblerBrokerService
-services.SchedulerService.classname=org.apache.turbine.services.schedule.TurbineSchedulerService
+services.SchedulerService.classname=org.apache.turbine.services.schedule.TorqueSchedulerService
services.UniqueIdService.classname=org.apache.turbine.services.uniqueid.TurbineUniqueIdService
services.SecurityService.classname=org.apache.turbine.services.security.DefaultSecurityService
services.PullService.classname=org.apache.turbine.services.pull.TurbinePullService
Modified: turbine/core/trunk/conf/test/ConfigurationBuilder.xml
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/conf/test/ConfigurationBuilder.xml?rev=1692637&r1=1692636&r2=1692637&view=diff
==============================================================================
--- turbine/core/trunk/conf/test/ConfigurationBuilder.xml (original)
+++ turbine/core/trunk/conf/test/ConfigurationBuilder.xml Sat Jul 25 19:22:57
2015
@@ -4,7 +4,7 @@
<header>
<!-- Meta data about the resulting combined configuration -->
</header>
- <override><!-- only allowed configurations are user and turbine, realtive
paths -->
+ <override><!-- only allowed configurations are user and turbine, relative
paths -->
<properties config-name="user"
fileName="conf/test/usersettings.properties" config-optional="true"
config-forceCreate="true"/>
<xml fileName="conf/test/TurbineResources.xml"/>
<properties config-name="turbine"
fileName="conf/test/TemplateService.properties" throwExceptionOnMissing="true"/>
Modified: turbine/core/trunk/conf/test/TestFulcrumComponents.properties
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/conf/test/TestFulcrumComponents.properties?rev=1692637&r1=1692636&r2=1692637&view=diff
==============================================================================
--- turbine/core/trunk/conf/test/TestFulcrumComponents.properties (original)
+++ turbine/core/trunk/conf/test/TestFulcrumComponents.properties Sat Jul 25
19:22:57 2015
@@ -68,6 +68,7 @@ services.ServletService.classname=org.ap
services.AssemblerBrokerService.classname=org.apache.turbine.services.assemblerbroker.TurbineAssemblerBrokerService
services.PullService.classname=org.apache.turbine.services.pull.TurbinePullService
services.TemplateService.classname=org.apache.turbine.services.template.TurbineTemplateService
+services.SchedulerService.classname=org.apache.turbine.services.schedule.QuartzSchedulerService
# -------------------------------------------------------------------
@@ -129,3 +130,23 @@ tool.request.l10n=org.apache.turbine.ser
services.AvalonComponentService.componentConfiguration =
conf/test/fulcrumComponentConfiguration.xml
services.AvalonComponentService.componentRoles =
conf/test/fulcrumRoleConfiguration.xml
services.AvalonComponentService.lookup =
org.apache.fulcrum.cache.GlobalCacheService
+
+# -------------------------------------------------------------------
+#
+# S C H E D U L E R S E R V I C E
+#
+# -------------------------------------------------------------------
+
+#
+# Set enabled to true to start the scheduler. The scheduler can be
+# stopped and started after Turbine has been intialized. See the
+# javadocs for org.apache.turbine.services.schedule.TurbineScheduler
+# for the methods calls.
+#
+# Default = false
+#
+services.SchedulerService.enabled=false
+
+# Determines if the scheduler service should be initialized early. This
+# Should always be set to true!!!!
+services.SchedulerService.earlyInit=true
Modified: turbine/core/trunk/conf/test/fulcrumComponentConfiguration.xml
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/conf/test/fulcrumComponentConfiguration.xml?rev=1692637&r1=1692636&r2=1692637&view=diff
==============================================================================
--- turbine/core/trunk/conf/test/fulcrumComponentConfiguration.xml (original)
+++ turbine/core/trunk/conf/test/fulcrumComponentConfiguration.xml Sat Jul 25
19:22:57 2015
@@ -74,4 +74,35 @@
<className>org.apache.fulcrum.security.model.turbine.entity.impl.TurbinePermissionImpl</className>
</permissionManager>
+ <!--
+ Quartz Scheduler Service
+
+ configuration := contains either a property file or properties
(optional)
+ configuration/propertyFile := a property file to configure Quartz
+ configuration/properties := a set of properties to configure Quartz
+ configuration/properties/parameter := a single configuration
+ configuration/properties/parameter@name := the name of the property
+ configuration/properties/parameter@value := the value of the property
+ -->
+
+ <quartz>
+ <configuration>
+ <properties>
+ <parameter name="org.quartz.scheduler.instanceName"
value="TestScheduler"/>
+ <parameter name="org.quartz.scheduler.instanceId "
value="AUTO"/>
+ <parameter name="org.quartz.scheduler.skipUpdateCheck"
value="true"/>
+ <parameter name="org.quartz.threadPool.class"
value="org.quartz.simpl.SimpleThreadPool"/>
+ <parameter name="org.quartz.threadPool.threadCount" value="3"/>
+ <parameter name="org.quartz.threadPool.threadPriority"
value="5"/>
+ <parameter name="org.quartz.jobStore.misfireThreshold"
value="60000"/>
+ <parameter name="org.quartz.jobStore.class"
value="org.quartz.simpl.RAMJobStore"/>
+ <parameter name="org.quartz.plugin.jobInitializer.class"
value="org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin"/>
+ <parameter name="org.quartz.plugin.jobInitializer.fileNames"
value="./conf/test/quartz.xml"/>
+ <parameter
name="org.quartz.plugin.jobInitializer.failOnFileNotFound" value="true"/>
+ <parameter
name="org.quartz.plugin.jobInitializer.scanInterval" value="120"/>
+ <parameter
name="org.quartz.plugin.jobInitializer.wrapInUserTransaction" value="false"/>
+ </properties>
+ </configuration>
+ </quartz>
+
</componentConfig>
Modified: turbine/core/trunk/conf/test/fulcrumRoleConfiguration.xml
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/conf/test/fulcrumRoleConfiguration.xml?rev=1692637&r1=1692636&r2=1692637&view=diff
==============================================================================
--- turbine/core/trunk/conf/test/fulcrumRoleConfiguration.xml (original)
+++ turbine/core/trunk/conf/test/fulcrumRoleConfiguration.xml Sat Jul 25
19:22:57 2015
@@ -119,5 +119,12 @@
name="org.apache.fulcrum.security.model.ACLFactory"
shorthand="aclFactory"
default-class="org.apache.fulcrum.security.model.turbine.TurbineACLFactory"/>
+
+ <!-- Service required for the QuartzSchedulerService -->
+ <role
+ name="org.apache.fulcrum.quartz.QuartzScheduler"
+ shorthand="quartz"
+ default-class="org.apache.fulcrum.quartz.impl.QuartzSchedulerImpl" />
+
</role-list>
Modified: turbine/core/trunk/conf/test/intake.xml
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/conf/test/intake.xml?rev=1692637&r1=1692636&r2=1692637&view=diff
==============================================================================
--- turbine/core/trunk/conf/test/intake.xml (original)
+++ turbine/core/trunk/conf/test/intake.xml Sat Jul 25 19:22:57 2015
@@ -17,16 +17,12 @@
specific language governing permissions and limitations
under the License.
-->
-<!DOCTYPE input-data SYSTEM
- "http://turbine.apache.org/dtd/intake_2_4.dtd">
-<input-data basePackage="org.apache.turbine.services.intake.">
-<group name="LoginGroup" key="loginGroupKey" mapToObject="LoginForm">
-<field name="Username" key="loginUsernameKey" type="String"
+<input-data xmlns="http://turbine.apache.org/schema/intake/4.0"
+ basePackage="org.apache.turbine.services.intake.">
+ <group name="LoginGroup" key="loginGroupKey" mapToObject="LoginForm">
+ <field name="Username" key="loginUsernameKey" type="String"
mapToProperty="Username">
-
-</field>
-</group>
-
-
+ </field>
+ </group>
</input-data>
Added: turbine/core/trunk/conf/test/quartz.xml
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/conf/test/quartz.xml?rev=1692637&view=auto
==============================================================================
--- turbine/core/trunk/conf/test/quartz.xml (added)
+++ turbine/core/trunk/conf/test/quartz.xml Sat Jul 25 19:22:57 2015
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+-->
+<job-scheduling-data
xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData
http://www.quartz-scheduler.org/xml/job_scheduling_data_2_0.xsd"
+ version="2.0">
+ <pre-processing-commands>
+ <delete-jobs-in-group>*</delete-jobs-in-group>
+ <!-- clear all jobs in scheduler -->
+ <delete-triggers-in-group>*</delete-triggers-in-group>
+ <!-- clear all triggers in scheduler -->
+ </pre-processing-commands>
+ <processing-directives>
+ <!-- if there are any jobs/trigger in scheduler of same name (as in
this file), overwrite them -->
+ <overwrite-existing-data>true</overwrite-existing-data>
+ <!-- if there are any jobs/trigger in scheduler of same name (as in
this file), and over-write is false, ignore them rather then generating an
error -->
+ <ignore-duplicates>false</ignore-duplicates>
+ </processing-directives>
+ <schedule>
+ <job>
+ <name>SimpleJob</name>
+ <group>TURBINE</group>
+ <description>A simple job</description>
+
<job-class>org.apache.turbine.services.schedule.JobEntryQuartz</job-class>
+ </job>
+ <trigger>
+ <simple>
+ <!-- define a simple trigger firing every ten seconds -->
+ <name>simpleTrigger</name>
+ <group>TURBINE</group>
+ <job-name>SimpleJob</job-name>
+ <job-group>TURBINE</job-group>
+ <start-time>2015-01-01T00:00:00</start-time>
+
<misfire-instruction>MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT</misfire-instruction>
+ <repeat-count>-1</repeat-count>
+ <repeat-interval>1000</repeat-interval>
+ </simple>
+ </trigger>
+ </schedule>
+</job-scheduling-data>
Propchange: turbine/core/trunk/conf/test/quartz.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: turbine/core/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/src/changes/changes.xml?rev=1692637&r1=1692636&r2=1692637&view=diff
==============================================================================
--- turbine/core/trunk/src/changes/changes.xml (original)
+++ turbine/core/trunk/src/changes/changes.xml Sat Jul 25 19:22:57 2015
@@ -25,7 +25,15 @@
<body>
<release version="4.0-M2" date="in Subversion">
- <action type="update" dev="gk">
+ <action type="add" dev="tv">
+ Add QuartzSchedulerService
+ </action>
+ <action type="update" dev="tv">
+ Update dependencies
+ - fulcrum-security to 1.1.0
+ - fulcrum-intake to 1.2.0
+ </action>
+ <action type="update" dev="gk">
Update to Torque 4.0.0
</action>
<action type="add" dev="tv">
Modified:
turbine/core/trunk/src/java/org/apache/turbine/services/intake/IntakeTool.java
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/intake/IntakeTool.java?rev=1692637&r1=1692636&r2=1692637&view=diff
==============================================================================
---
turbine/core/trunk/src/java/org/apache/turbine/services/intake/IntakeTool.java
(original)
+++
turbine/core/trunk/src/java/org/apache/turbine/services/intake/IntakeTool.java
Sat Jul 25 19:22:57 2015
@@ -66,8 +66,8 @@ public class IntakeTool
protected ValueParser pp;
private final HashMap<String, Group> declaredGroups = new HashMap<String,
Group>();
- private final StringBuffer allGroupsSB = new StringBuffer(256);
- private final StringBuffer groupSB = new StringBuffer(128);
+ private final StringBuilder allGroupsSB = new StringBuilder(256);
+ private final StringBuilder groupSB = new StringBuilder(128);
/** The cache of PullHelpers. **/
private final Map<String, IntakeTool.PullHelper> pullMap;
@@ -95,6 +95,7 @@ public class IntakeTool
/**
* Prepares intake for a single request
*/
+ @Override
public void init(Object runData)
{
this.pp = ((RunData) runData).getParameters();
@@ -185,7 +186,7 @@ public class IntakeTool
* xhtml valid hidden input field(s) that notifies intake of the
* group's presence.
*/
- public void declareGroup(Group group, StringBuffer sb)
+ public void declareGroup(Group group, StringBuilder sb)
{
if (!declaredGroups.containsKey(group.getIntakeGroupName()))
{
@@ -212,6 +213,7 @@ public class IntakeTool
* Implementation of ApplicationTool interface is not needed for this
* tool as it is request scoped
*/
+ @Override
public void refresh()
{
// empty
@@ -333,7 +335,7 @@ public class IntakeTool
/**
* Get a specific group
*
- * @param throwExceptions if false, exceptions will be supressed.
+ * @param throwExceptions if false, exceptions will be suppressed.
* @throws IntakeException could not retrieve group
*/
public PullHelper get(String groupName, boolean throwExceptions)
@@ -473,6 +475,7 @@ public class IntakeTool
* methods whenever applicable.
* The recycle methods must call their super.
*/
+ @Override
public void recycle()
{
disposed = false;
@@ -483,6 +486,7 @@ public class IntakeTool
* when the object is returned to its pool.
* The dispose method must call its super.
*/
+ @Override
public void dispose()
{
for (Group group : groups.values())
@@ -510,6 +514,7 @@ public class IntakeTool
*
* @return true, if the recyclable is disposed.
*/
+ @Override
public boolean isDisposed()
{
return disposed;
Copied:
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/AbstractJobEntry.java
(from r1616985,
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntry.java)
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/schedule/AbstractJobEntry.java?p2=turbine/core/trunk/src/java/org/apache/turbine/services/schedule/AbstractJobEntry.java&p1=turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntry.java&r1=1616985&r2=1692637&rev=1692637&view=diff
==============================================================================
---
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntry.java
(original)
+++
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/AbstractJobEntry.java
Sat Jul 25 19:22:57 2015
@@ -1,35 +1,36 @@
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.sql.Date;
import java.util.Calendar;
+import java.util.Date;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.torque.om.Persistent;
import org.apache.turbine.util.TurbineException;
-/**
- * The skeleton for this class was autogenerated by Torque on:
- *
- * [Mon Jan 24 20:11:00 CET 2011]
- *
- * You should add additional methods to this class to meet the
- * application requirements. This class will only be generated as
- * long as it does not already exist in the output directory.
- */
-public class JobEntry
- extends org.apache.turbine.services.schedule.BaseJobEntry
- implements Persistent
+public abstract class AbstractJobEntry implements JobEntry
{
- /**
- *
- */
- private static final long serialVersionUID = -5501116588294474363L;
-
/** Logging */
- private static Log log = LogFactory.getLog(ScheduleService.LOGGER_NAME);
+ protected static Log log = LogFactory.getLog(ScheduleService.LOGGER_NAME);
/** indicates if job is currently running */
private boolean jobIsActive = false;
@@ -38,22 +39,24 @@ public class JobEntry
private long runtime = 0;
/** schedule types **/
- private static final int SECOND = 0;
- private static final int MINUTE = 1;
- private static final int WEEK_DAY = 2;
- private static final int DAY_OF_MONTH = 3;
- private static final int DAILY = 4;
+ public enum ScheduleType {
+ SECOND,
+ MINUTE,
+ WEEK_DAY,
+ DAY_OF_MONTH,
+ DAILY
+ }
/**
- * default constructor
+ * Default constructor
*/
- public JobEntry()
+ public AbstractJobEntry()
{
- // empty
+ super();
}
/**
- * Constuctor.
+ * Constructor.
*
* Schedule a job to run on a certain point of time.<br>
*
@@ -83,7 +86,7 @@ public class JobEntry
* @param task Task to execute.
* @exception TurbineException a generic exception.
*/
- public JobEntry(int sec,
+ public AbstractJobEntry(int sec,
int min,
int hour,
int wd,
@@ -91,6 +94,8 @@ public class JobEntry
String task)
throws TurbineException
{
+ this();
+
if (StringUtils.isEmpty(task))
{
throw new TurbineException("Error in JobEntry. " +
@@ -115,14 +120,10 @@ public class JobEntry
* @param je The first <code>JobEntry</code> object.
* @return An <code>int</code> indicating the result of the comparison.
*/
- public int compareTo(Object je)
+ @Override
+ public int compareTo(JobEntry je)
{
- int result = -1;
- if (je instanceof JobEntry)
- {
- result = getJobId() - ((JobEntry) je).getJobId();
- }
- return result;
+ return getJobId() - je.getJobId();
}
/**
@@ -130,6 +131,7 @@ public class JobEntry
*
* @param isActive Whether the job is running.
*/
+ @Override
public void setActive(boolean isActive)
{
jobIsActive = isActive;
@@ -141,6 +143,7 @@ public class JobEntry
* @return true if job is currently geing run by the
* workerthread, otherwise false
*/
+ @Override
public boolean isActive()
{
return jobIsActive;
@@ -151,6 +154,7 @@ public class JobEntry
*
* @return The next run time as a long.
*/
+ @Override
public long getNextRuntime()
{
return runtime;
@@ -161,6 +165,7 @@ public class JobEntry
*
* @return Next run date
*/
+ @Override
public Date getNextRunDate()
{
return new Date(runtime);
@@ -171,6 +176,7 @@ public class JobEntry
*
* @return The next run time as a String.
*/
+ @Override
public String getNextRunAsString()
{
return getNextRunDate().toString();
@@ -289,7 +295,7 @@ public class JobEntry
* calcRunTime().
* @exception TurbineException a generic exception.
*/
- private int evaluateJobType()
+ private ScheduleType evaluateJobType()
throws TurbineException
{
@@ -307,18 +313,22 @@ public class JobEntry
{
// Not a by the minute job so must be by the second
if (getSecond() < 0)
+ {
throw new TurbineException("Error in JobEntry. Bad
Job parameter.");
+ }
- return SECOND;
+ return ScheduleType.SECOND;
}
else
{
// Must be a job run by the minute so we need minutes
and
// seconds.
if (getMinute() < 0 || getSecond() < 0)
+ {
throw new TurbineException("Error in JobEntry. Bad
Job parameter.");
+ }
- return MINUTE;
+ return ScheduleType.MINUTE;
}
}
else
@@ -326,9 +336,11 @@ public class JobEntry
// Must be a daily job by hours minutes, and seconds. In
// this case, we need the minute, second, and hour params.
if (getMinute() < 0 || getHour() < 0 || getSecond() < 0)
+ {
throw new TurbineException("Error in JobEntry. Bad Job
parameter.");
+ }
- return DAILY;
+ return ScheduleType.DAILY;
}
}
else
@@ -336,9 +348,11 @@ public class JobEntry
// Must be a weekday job. In this case, we need
// minute, second, and hour params
if (getMinute() < 0 || getHour() < 0 || getSecond() < 0)
+ {
throw new TurbineException("Error in JobEntry. Bad Job
parameter.");
+ }
- return WEEK_DAY;
+ return ScheduleType.WEEK_DAY;
}
}
else
@@ -346,10 +360,113 @@ public class JobEntry
// Must be a day of the month job. In this case, we need
// minute, second, and hour params
if (getMinute() < 0 || getHour() < 0)
+ {
throw new TurbineException("Error in JobEntry. Bad Job
parameter.");
+ }
- return DAY_OF_MONTH;
+ return ScheduleType.DAY_OF_MONTH;
}
}
+ /**
+ * Get the value of jobId.
+ *
+ * @return int
+ */
+ @Override
+ public abstract int getJobId();
+
+ /**
+ * Set the value of jobId.
+ *
+ * @param v new value
+ */
+ @Override
+ public abstract void setJobId(int v);
+
+ /**
+ * Get the value of second.
+ *
+ * @return int
+ */
+ public abstract int getSecond();
+
+ /**
+ * Set the value of second.
+ *
+ * @param v new value
+ */
+ public abstract void setSecond(int v);
+
+ /**
+ * Get the value of minute.
+ *
+ * @return int
+ */
+ public abstract int getMinute();
+
+ /**
+ * Set the value of minute.
+ *
+ * @param v new value
+ */
+ public abstract void setMinute(int v);
+
+ /**
+ * Get the value of hour.
+ *
+ * @return int
+ */
+ public abstract int getHour();
+
+ /**
+ * Set the value of hour.
+ *
+ * @param v new value
+ */
+ public abstract void setHour(int v);
+
+ /**
+ * Get the value of weekDay.
+ *
+ * @return int
+ */
+ public abstract int getWeekDay();
+
+ /**
+ * Set the value of weekDay.
+ *
+ * @param v new value
+ */
+ public abstract void setWeekDay(int v);
+
+ /**
+ * Get the value of dayOfMonth.
+ *
+ * @return int
+ */
+ public abstract int getDayOfMonth();
+
+ /**
+ * Set the value of dayOfMonth.
+ *
+ * @param v new value
+ */
+ public abstract void setDayOfMonth(int v);
+
+ /**
+ * Get the value of task.
+ *
+ * @return String
+ */
+ @Override
+ public abstract String getTask();
+
+ /**
+ * Set the value of task.
+ *
+ * @param v new value
+ */
+ @Override
+ public abstract void setTask(String v);
}
Modified:
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntry.java
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntry.java?rev=1692637&r1=1692636&r2=1692637&view=diff
==============================================================================
---
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntry.java
(original)
+++
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntry.java
Sat Jul 25 19:22:57 2015
@@ -1,355 +1,126 @@
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.sql.Date;
-import java.util.Calendar;
+import java.util.Date;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.torque.om.Persistent;
import org.apache.turbine.util.TurbineException;
/**
- * The skeleton for this class was autogenerated by Torque on:
- *
- * [Mon Jan 24 20:11:00 CET 2011]
+ * This is a interface for a scheduled job. It does not specify how to
configure
+ * when to run, that is left to subclasses. See the JobEntryTorque for an
+ * example of a JobEntry backed by Torque objects.
*
- * You should add additional methods to this class to meet the
- * application requirements. This class will only be generated as
- * long as it does not already exist in the output directory.
+ * @author <a href="mailto:[email protected]">Eric Pugh</a>
+ * @author <a href="mailto:[email protected]">Dave Bryson</a>
+ * @author <a href="mailto:[email protected]">Quinton McCombs</a>
+ * @version $Id$
*/
-public class JobEntry
- extends org.apache.turbine.services.schedule.BaseJobEntry
- implements Persistent
+public interface JobEntry extends Comparable<JobEntry>
{
/**
+ * Sets whether the job is running.
*
+ * @param isActive
+ * Whether the job is running.
*/
- private static final long serialVersionUID = -5501116588294474363L;
-
- /** Logging */
- private static Log log = LogFactory.getLog(ScheduleService.LOGGER_NAME);
-
- /** indicates if job is currently running */
- private boolean jobIsActive = false;
-
- /** Next runtime. **/
- private long runtime = 0;
-
- /** schedule types **/
- private static final int SECOND = 0;
- private static final int MINUTE = 1;
- private static final int WEEK_DAY = 2;
- private static final int DAY_OF_MONTH = 3;
- private static final int DAILY = 4;
+ void setActive(boolean isActive);
/**
- * default constructor
+ * Check to see if job is currently active/running
+ *
+ * @return true if job is currently being run by the worker thread,
otherwise
+ * false
*/
- public JobEntry()
- {
- // empty
- }
+ boolean isActive();
/**
- * Constuctor.
- *
- * Schedule a job to run on a certain point of time.<br>
- *
- * Example 1: Run the DefaultScheduledJob at 8:00am every 15th of
- * the month - <br>
- *
- * JobEntry je = new JobEntry(0,0,8,15,"DefaultScheduledJob");<br>
- *
- * Example 2: Run the DefaultScheduledJob at 8:00am every day -
- * <br>
- *
- * JobEntry je = new JobEntry(0,0,8,-1,"DefaultScheduledJob");<br>
+ * Check to see if job is new
*
- * Example 3: Run the DefaultScheduledJob every 2 hours. - <br>
- *
- * JobEntry je = new JobEntry(0,120,-1,-1,"DefaultScheduledJob");<br>
- *
- * Example 4: Run the DefaultScheduledJob every 30 seconds. - <br>
- *
- * JobEntry je = new JobEntry(30,-1,-1,-1,"DefaultScheduledJob");<br>
- *
- * @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".
- * @param task Task to execute.
- * @exception TurbineException a generic exception.
+ * @return true if job is not yet saved, otherwise
+ * false
*/
- public JobEntry(int sec,
- int min,
- int hour,
- int wd,
- int day_mo,
- String task)
- throws TurbineException
- {
- if (StringUtils.isEmpty(task))
- {
- throw new TurbineException("Error in JobEntry. " +
- "Bad Job parameter. Task not set.");
- }
+ boolean isNew();
- setSecond(sec);
- setMinute(min);
- setHour(hour);
- setWeekDay(wd);
- setDayOfMonth(day_mo);
- setTask(task);
-
- calcRunTime();
- }
+ /**
+ * Get the value of jobId.
+ *
+ * @return int
+ */
+ int getJobId();
/**
- * Used for ordering Jobentries
- * Note: this comparator imposes orderings that are inconsistent with
- * equals.
+ * Set the value of jobId.
*
- * @param je The first <code>JobEntry</code> object.
- * @return An <code>int</code> indicating the result of the comparison.
+ * @param v new value
*/
- public int compareTo(Object je)
- {
- int result = -1;
- if (je instanceof JobEntry)
- {
- result = getJobId() - ((JobEntry) je).getJobId();
- }
- return result;
- }
+ void setJobId(int v);
/**
- * Sets whether the job is running.
+ * Get the Task
*
- * @param isActive Whether the job is running.
+ * @return String
*/
- public void setActive(boolean isActive)
- {
- jobIsActive = isActive;
- }
+ String getTask();
/**
- * Check to see if job is currently active/running
+ * Set the value of Task
*
- * @return true if job is currently geing run by the
- * workerthread, otherwise false
+ * @param v new value
*/
- public boolean isActive()
- {
- return jobIsActive;
- }
+ void setTask(String v);
/**
* Get the next runtime for this job as a long.
*
* @return The next run time as a long.
*/
- public long getNextRuntime()
- {
- return runtime;
- }
+ long getNextRuntime();
/**
* Gets the next runtime as a date
*
* @return Next run date
*/
- public Date getNextRunDate()
- {
- return new Date(runtime);
- }
+ Date getNextRunDate();
/**
* Get the next runtime for this job as a String.
*
* @return The next run time as a String.
*/
- public String getNextRunAsString()
- {
- return getNextRunDate().toString();
- }
-
- /**
- * Calculate how long before the next runtime.<br>
- *
- * The runtime determines it's position in the job queue.
- * Here's the logic:<br>
- *
- * 1. Create a date the represents when this job is to run.<br>
- *
- * 2. If this date has expired, them "roll" appropriate date
- * fields forward to the next date.<br>
- *
- * 3. Calculate the diff in time between the current time and the
- * next run time.<br>
- *
- * @exception TurbineException a generic exception.
- */
- public void calcRunTime()
- throws TurbineException
- {
- Calendar schedrun = Calendar.getInstance();
- Calendar now = Calendar.getInstance();
-
- switch (evaluateJobType())
- {
- case SECOND:
- // SECOND (every so many seconds...)
- schedrun.add(Calendar.SECOND, getSecond());
- runtime = schedrun.getTime().getTime();
- break;
-
- case MINUTE:
- // MINUTE (every so many minutes...)
- schedrun.add(Calendar.SECOND, getSecond());
- schedrun.add(Calendar.MINUTE, getMinute());
- runtime = schedrun.getTime().getTime();
- break;
-
- case WEEK_DAY:
- // WEEKDAY (day of the week)
- schedrun.set(Calendar.SECOND, getSecond());
- schedrun.set(Calendar.MINUTE, getMinute());
- schedrun.set(Calendar.HOUR_OF_DAY, getHour());
- schedrun.set(Calendar.DAY_OF_WEEK, getWeekDay());
-
- if (now.before(schedrun))
- {
- // Scheduled time has NOT expired.
- runtime = schedrun.getTime().getTime();
- }
- else
- {
- // Scheduled time has expired; roll to the next week.
- schedrun.add(Calendar.DAY_OF_WEEK, 7);
- runtime = schedrun.getTime().getTime();
- }
- break;
-
- case DAY_OF_MONTH:
- // DAY_OF_MONTH (date of the month)
- schedrun.set(Calendar.SECOND, getSecond());
- schedrun.set(Calendar.MINUTE, getMinute());
- schedrun.set(Calendar.HOUR_OF_DAY, getHour());
- schedrun.set(Calendar.DAY_OF_MONTH, getDayOfMonth());
-
- if (now.before(schedrun))
- {
- // Scheduled time has NOT expired.
- runtime = schedrun.getTime().getTime();
- }
- else
- {
- // Scheduled time has expired; roll to the next month.
- schedrun.add(Calendar.MONTH, 1);
- runtime = schedrun.getTime().getTime();
- }
- break;
-
- case DAILY:
- // DAILY (certain hour:minutes of the day)
- schedrun.set(Calendar.SECOND, getSecond());
- schedrun.set(Calendar.MINUTE, getMinute());
- schedrun.set(Calendar.HOUR_OF_DAY, getHour());
-
- // Scheduled time has NOT expired.
- if (now.before(schedrun))
- {
- runtime = schedrun.getTime().getTime();
- }
- else
- {
- // Scheduled time has expired; roll forward 24 hours.
- schedrun.add(Calendar.HOUR_OF_DAY, 24);
- runtime = schedrun.getTime().getTime();
- }
- break;
-
- default:
- // Do nothing.
- }
-
- log.info("Next runtime for task " + this.getTask() + " is " +
this.getNextRunDate());
- }
-
- /**
- * What schedule am I on?
- *
- * I know this is kinda ugly! If you can think of a cleaner way
- * to do this, please jump in!
- *
- * @return A number specifying the type of schedule. See
- * calcRunTime().
- * @exception TurbineException a generic exception.
- */
- private int evaluateJobType()
- throws TurbineException
- {
-
- // First start by checking if it's a day of the month job.
- if (getDayOfMonth() < 0)
- {
- // Not a day of the month job... check weekday.
- if (getWeekDay() < 0)
- {
- // Not a weekday job...check if by the hour.
- if (getHour() < 0)
- {
- // Not an hourly job...check if it is by the minute
- if (getMinute() < 0)
- {
- // Not a by the minute job so must be by the second
- if (getSecond() < 0)
- throw new TurbineException("Error in JobEntry. Bad
Job parameter.");
-
- return SECOND;
- }
- else
- {
- // Must be a job run by the minute so we need minutes
and
- // seconds.
- if (getMinute() < 0 || getSecond() < 0)
- throw new TurbineException("Error in JobEntry. Bad
Job parameter.");
-
- return MINUTE;
- }
- }
- else
- {
- // Must be a daily job by hours minutes, and seconds. In
- // this case, we need the minute, second, and hour params.
- if (getMinute() < 0 || getHour() < 0 || getSecond() < 0)
- throw new TurbineException("Error in JobEntry. Bad Job
parameter.");
-
- return DAILY;
- }
- }
- else
- {
- // Must be a weekday job. In this case, we need
- // minute, second, and hour params
- if (getMinute() < 0 || getHour() < 0 || getSecond() < 0)
- throw new TurbineException("Error in JobEntry. Bad Job
parameter.");
-
- return WEEK_DAY;
- }
- }
- else
- {
- // Must be a day of the month job. In this case, we need
- // minute, second, and hour params
- if (getMinute() < 0 || getHour() < 0)
- throw new TurbineException("Error in JobEntry. Bad Job
parameter.");
-
- return DAY_OF_MONTH;
- }
- }
+ String getNextRunAsString();
+
+ /**
+ * Calculate how long before the next runtime. <br>
+ *
+ * The runtime determines it's position in the job queue. Here's the
logic: <br>
+ * 1. Create a date the represents when this job is to run. <br>
+ * 2. If this date has expired, them "roll" appropriate date fields forward
+ * to the next date. <br>
+ * 3. Calculate the diff in time between the current time and the next run
+ * time. <br>
+ *
+ * @exception TurbineException
+ * a generic exception.
+ */
+ void calcRunTime() throws TurbineException;
}
Added:
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntryNonPersistent.java
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntryNonPersistent.java?rev=1692637&view=auto
==============================================================================
---
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntryNonPersistent.java
(added)
+++
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntryNonPersistent.java
Sat Jul 25 19:22:57 2015
@@ -0,0 +1,277 @@
+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 org.apache.turbine.util.TurbineException;
+
+/**
+ * This is an implementation of a JobEntry with no persistence. It is used by
the
+ * {@link TurbineNonPersistentSchedulerService}
+ *
+ */
+public class JobEntryNonPersistent extends AbstractJobEntry
+{
+ private int jobId;
+ private int sec;
+ private int min;
+ private int hour;
+ private int wd;
+ private int day_mo;
+ private String task;
+ private boolean isnew = true;
+
+ /**
+ * Default constructor
+ */
+ public JobEntryNonPersistent()
+ {
+ super();
+ }
+
+ /**
+ * Constructor.
+ *
+ * Schedule a job to run on a certain point of time.<br>
+ *
+ * Example 1: Run the DefaultScheduledJob at 8:00am every 15th of
+ * the month - <br>
+ *
+ * JobEntry je = new JobEntry(0,0,8,15,"DefaultScheduledJob");<br>
+ *
+ * Example 2: Run the DefaultScheduledJob at 8:00am every day -
+ * <br>
+ *
+ * JobEntry je = new JobEntry(0,0,8,-1,"DefaultScheduledJob");<br>
+ *
+ * Example 3: Run the DefaultScheduledJob every 2 hours. - <br>
+ *
+ * JobEntry je = new JobEntry(0,120,-1,-1,"DefaultScheduledJob");<br>
+ *
+ * Example 4: Run the DefaultScheduledJob every 30 seconds. - <br>
+ *
+ * JobEntry je = new JobEntry(30,-1,-1,-1,"DefaultScheduledJob");<br>
+ *
+ * @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".
+ * @param task Task to execute.
+ * @exception TurbineException a generic exception.
+ */
+ public JobEntryNonPersistent(int sec,
+ int min,
+ int hour,
+ int wd,
+ int day_mo,
+ String task)
+ throws TurbineException
+ {
+ super(sec, min, hour, wd, day_mo, task);
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode()
+ {
+ return Integer.valueOf(jobId).hashCode();
+ }
+
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof JobEntry)
+ {
+ return compareTo((JobEntry)obj) == 0;
+ }
+
+ return false;
+ }
+
+ /**
+ * Return true, if the entry is not yet persisted
+ */
+ @Override
+ public boolean isNew()
+ {
+ boolean _isnew = isnew;
+ isnew = false;
+ return _isnew;
+ }
+
+ /**
+ * Get the value of jobId.
+ *
+ * @return int
+ */
+ @Override
+ public int getJobId()
+ {
+ return jobId;
+ }
+
+ /**
+ * Set the value of jobId.
+ *
+ * @param v new value
+ */
+ @Override
+ public void setJobId(int v)
+ {
+ this.jobId = v;
+ }
+
+ /**
+ * Get the value of second.
+ *
+ * @return int
+ */
+ @Override
+ public int getSecond()
+ {
+ return sec;
+ }
+
+ /**
+ * Set the value of second.
+ *
+ * @param v new value
+ */
+ @Override
+ public void setSecond(int v)
+ {
+ this.sec = v;
+ }
+
+ /**
+ * Get the value of minute.
+ *
+ * @return int
+ */
+ @Override
+ public int getMinute()
+ {
+ return min;
+ }
+
+ /**
+ * Set the value of minute.
+ *
+ * @param v new value
+ */
+ @Override
+ public void setMinute(int v)
+ {
+ this.min = v;
+ }
+
+ /**
+ * Get the value of hour.
+ *
+ * @return int
+ */
+ @Override
+ public int getHour()
+ {
+ return hour;
+ }
+
+ /**
+ * Set the value of hour.
+ *
+ * @param v new value
+ */
+ @Override
+ public void setHour(int v)
+ {
+ this.hour = v;
+ }
+
+ /**
+ * Get the value of weekDay.
+ *
+ * @return int
+ */
+ @Override
+ public int getWeekDay()
+ {
+ return wd;
+ }
+
+ /**
+ * Set the value of weekDay.
+ *
+ * @param v new value
+ */
+ @Override
+ public void setWeekDay(int v)
+ {
+ this.wd = v;
+ }
+
+ /**
+ * Get the value of dayOfMonth.
+ *
+ * @return int
+ */
+ @Override
+ public int getDayOfMonth()
+ {
+ return day_mo;
+ }
+
+ /**
+ * Set the value of dayOfMonth.
+ *
+ * @param v new value
+ */
+ @Override
+ public void setDayOfMonth(int v)
+ {
+ this.day_mo = v;
+ }
+
+ /**
+ * Get the value of task.
+ *
+ * @return String
+ */
+ @Override
+ public String getTask()
+ {
+ return task;
+ }
+
+ /**
+ * Set the value of task.
+ *
+ * @param v new value
+ */
+ @Override
+ public void setTask(String v)
+ {
+ this.task = v;
+ }
+}
Propchange:
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntryNonPersistent.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntryQuartz.java
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntryQuartz.java?rev=1692637&view=auto
==============================================================================
---
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntryQuartz.java
(added)
+++
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntryQuartz.java
Sat Jul 25 19:22:57 2015
@@ -0,0 +1,253 @@
+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.Date;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.turbine.modules.ScheduledJobLoader;
+import org.apache.turbine.util.TurbineException;
+import org.quartz.Job;
+import org.quartz.JobBuilder;
+import org.quartz.JobDetail;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.quartz.Trigger;
+
+public class JobEntryQuartz implements JobEntry, Job
+{
+ private int jobId;
+ private Trigger jobTrigger;
+ private JobDetail jobDetail;
+ private String task;
+ private boolean isnew = true;
+ private AtomicBoolean active = new AtomicBoolean(false);
+
+ public static final String DEFAULT_JOB_GROUP_NAME = "TURBINE";
+
+ /**
+ * Default constructor
+ */
+ public JobEntryQuartz()
+ {
+ super();
+ }
+
+ /**
+ * Constructor
+ *
+ * @param jobTrigger Job time table
+ */
+ public JobEntryQuartz(Trigger jobTrigger)
+ {
+ this(jobTrigger, JobBuilder
+ .newJob(JobEntryQuartz.class)
+ .withIdentity(jobTrigger.getJobKey().getName(),
DEFAULT_JOB_GROUP_NAME).build());
+ }
+
+ /**
+ * Constructor
+ *
+ * @param jobTrigger Job time table
+ * @param jobDetail job details
+ */
+ public JobEntryQuartz(Trigger jobTrigger, JobDetail jobDetail)
+ {
+ this();
+ setTask(jobTrigger.getJobKey().getName());
+ this.jobTrigger = jobTrigger;
+ this.jobDetail = jobDetail;
+ }
+
+ /**
+ * Return true, if the entry is not yet persisted
+ */
+ @Override
+ public boolean isNew()
+ {
+ boolean _isnew = isnew;
+ isnew = false;
+ return _isnew;
+ }
+
+ /**
+ * Get the value of jobId.
+ *
+ * @return int
+ */
+ @Override
+ public int getJobId()
+ {
+ return jobId;
+ }
+
+ /**
+ * Set the value of jobId.
+ *
+ * @param v new value
+ */
+ @Override
+ public void setJobId(int v)
+ {
+ this.jobId = v;
+ }
+
+ /**
+ * Get the value of task.
+ *
+ * @return String
+ */
+ @Override
+ public String getTask()
+ {
+ return task;
+ }
+
+ /**
+ * Set the value of task.
+ *
+ * @param v new value
+ */
+ @Override
+ public void setTask(String v)
+ {
+ this.task = v;
+ }
+
+ /**
+ * @return the jobTrigger
+ */
+ public Trigger getJobTrigger()
+ {
+ return jobTrigger;
+ }
+
+ /**
+ * @param jobTrigger the jobTrigger to set
+ */
+ public void setJobTrigger(Trigger jobTrigger)
+ {
+ this.jobTrigger = jobTrigger;
+ }
+
+ /**
+ * @return the jobDetail
+ */
+ public JobDetail getJobDetail()
+ {
+ return jobDetail;
+ }
+
+ /**
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @Override
+ public int compareTo(JobEntry o)
+ {
+ return jobTrigger.compareTo(((JobEntryQuartz)o).getJobTrigger());
+ }
+
+ /**
+ * @see org.apache.turbine.services.schedule.JobEntry#setActive(boolean)
+ */
+ @Override
+ public void setActive(boolean isActive)
+ {
+ this.active.set(isActive);
+ }
+
+ /**
+ * @see org.apache.turbine.services.schedule.JobEntry#isActive()
+ */
+ @Override
+ public boolean isActive()
+ {
+ return active.get();
+ }
+
+ /**
+ * @see org.apache.turbine.services.schedule.JobEntry#getNextRuntime()
+ */
+ @Override
+ public long getNextRuntime()
+ {
+ return getNextRunDate().getTime();
+ }
+
+ /**
+ * @see org.apache.turbine.services.schedule.JobEntry#getNextRunDate()
+ */
+ @Override
+ public Date getNextRunDate()
+ {
+ return jobTrigger.getNextFireTime();
+ }
+
+ /**
+ * @see org.apache.turbine.services.schedule.JobEntry#getNextRunAsString()
+ */
+ @Override
+ public String getNextRunAsString()
+ {
+ return getNextRunDate().toString();
+ }
+
+ /**
+ * @see org.apache.turbine.services.schedule.JobEntry#calcRunTime()
+ */
+ @Override
+ public void calcRunTime() throws TurbineException
+ {
+ // do nothing
+ }
+
+ /**
+ * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
+ */
+ @Override
+ public void execute(JobExecutionContext context) throws
JobExecutionException
+ {
+ if (active.compareAndSet(false, true) == false)
+ {
+ return;
+ }
+
+ try
+ {
+ String task = getTask();
+ if (StringUtils.isEmpty(task))
+ {
+ // This happens when the job is configured in the Quartz
configuration file
+ task = context.getJobDetail().getKey().getName();
+ }
+ ScheduledJobLoader.getInstance().exec(this, task);
+ }
+ catch (Exception e)
+ {
+ throw new JobExecutionException("Error executing scheduled job #" +
+ getJobId() + ", task: " + getTask(), e);
+ }
+ finally
+ {
+ active.compareAndSet(true, false);
+ }
+ }
+}
Propchange:
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/JobEntryQuartz.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=1692637&r1=1692636&r2=1692637&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
Sat Jul 25 19:22:57 2015
@@ -33,19 +33,19 @@ import org.apache.turbine.util.TurbineEx
* @author <a href="mailto:[email protected]">Quinton McCombs</a>
* @version $Id: JobQueue.java 615328 2008-01-25 20:25:05Z tv $
*/
-public class JobQueue
+public class JobQueue<J extends JobEntry>
{
/**
* The queue of <code>JobEntry</code> objects.
*/
- private Vector<JobEntry> queue = null;
+ private Vector<J> queue = null;
/**
* Creates a new instance.
*/
public JobQueue()
{
- queue = new Vector<JobEntry>(10);
+ queue = new Vector<J>(10);
}
/**
@@ -54,7 +54,7 @@ public class JobQueue
*
* @return The next job in the queue.
*/
- public JobEntry getNext()
+ public J getNext()
{
if (queue.size() > 0)
{
@@ -72,7 +72,7 @@ public class JobQueue
* @param je The JobEntry we are looking for.
* @return A JobEntry.
*/
- public JobEntry getJob(JobEntry je)
+ public J getJob(J je)
{
int index = -1;
@@ -97,11 +97,11 @@ public class JobQueue
* @return A Vector of <code>JobEntry</code> objects.
*/
@SuppressWarnings("unchecked")
- public Vector<JobEntry> list()
+ public Vector<J> list()
{
if (queue != null && queue.size() > 0)
{
- return (Vector<JobEntry>) queue.clone();
+ return (Vector<J>) queue.clone();
}
else
{
@@ -114,7 +114,7 @@ public class JobQueue
*
* @param je A JobEntry job.
*/
- public synchronized void add(JobEntry je)
+ public synchronized void add(J je)
{
queue.addElement(je);
sortQueue();
@@ -126,7 +126,7 @@ public class JobQueue
*
* @param jobEntries A list of the <code>JobEntry</code> objects to load.
*/
- public synchronized void batchLoad(List<JobEntry> jobEntries)
+ public synchronized void batchLoad(List<J> jobEntries)
{
if (jobEntries != null)
{
@@ -141,7 +141,7 @@ public class JobQueue
*
* @param je A JobEntry with the job to remove.
*/
- public synchronized void remove(JobEntry je)
+ public synchronized void remove(J je)
{
queue.removeElement(je);
sortQueue();
@@ -152,7 +152,7 @@ public class JobQueue
*
* @param je A JobEntry with the job to modify
*/
- public synchronized void modify(JobEntry je)
+ public synchronized void modify(J je)
throws TurbineException
{
remove(je);
@@ -167,7 +167,7 @@ public class JobQueue
* @param je A JobEntry to be updated.
* @exception TurbineException a generic exception.
*/
- public synchronized void updateQueue(JobEntry je)
+ public synchronized void updateQueue(J je)
throws TurbineException
{
je.calcRunTime();
@@ -180,9 +180,10 @@ public class JobQueue
*/
private void sortQueue()
{
- Comparator<JobEntry> aComparator = new Comparator<JobEntry>()
+ Comparator<J> aComparator = new Comparator<J>()
{
- public int compare(JobEntry o1, JobEntry o2)
+ @Override
+ public int compare(J o1, J o2)
{
Long time1 = Long.valueOf(o1.getNextRuntime());
Long time2 = Long.valueOf(o2.getNextRuntime());
Added:
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=1692637&view=auto
==============================================================================
---
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/QuartzSchedulerService.java
(added)
+++
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/QuartzSchedulerService.java
Sat Jul 25 19:22:57 2015
@@ -0,0 +1,318 @@
+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 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.JobDetail;
+import org.quartz.JobKey;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.Trigger;
+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.
+ *
+ * @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);
+ }
+ }
+
+ /**
+ * 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 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.
+ * @exception 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());
+ }
+ }
+}
+
Propchange:
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/QuartzSchedulerService.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/ScheduleService.java
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/schedule/ScheduleService.java?rev=1692637&r1=1692636&r2=1692637&view=diff
==============================================================================
---
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/ScheduleService.java
(original)
+++
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/ScheduleService.java
Sat Jul 25 19:22:57 2015
@@ -50,7 +50,7 @@ public interface ScheduleService
*
* @param oid The int id for the job.
* @return A JobEntry.
- * @exception TurbineException could not retreive job
+ * @exception TurbineException could not retrieve job
*/
JobEntry getJob(int oid)
throws TurbineException;
@@ -87,7 +87,7 @@ public interface ScheduleService
*
* @return A List of jobs.
*/
- List<JobEntry> listJobs();
+ List<? extends JobEntry> listJobs();
/**
* Determines if the scheduler service is currently active.
Modified:
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/SchedulerTool.java
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/schedule/SchedulerTool.java?rev=1692637&r1=1692636&r2=1692637&view=diff
==============================================================================
---
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/SchedulerTool.java
(original)
+++
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/SchedulerTool.java
Sat Jul 25 19:22:57 2015
@@ -43,6 +43,7 @@ public class SchedulerTool implements Ap
/**
* Initialize the pull tool
*/
+ @Override
public void init(Object data)
{
if (!TurbineServices.getInstance().isRegistered(
@@ -56,6 +57,7 @@ public class SchedulerTool implements Ap
/**
* Does nothing
*/
+ @Override
public void refresh()
{
// empty
@@ -66,7 +68,7 @@ public class SchedulerTool implements Ap
*
* @return List of JobEntry objects.
*/
- public List<JobEntry> getScheduledJobs()
+ public List<? extends JobEntry> getScheduledJobs()
{
return TurbineScheduler.listJobs();
}
Copied:
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TorqueSchedulerService.java
(from r1620557,
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TurbineSchedulerService.java)
URL:
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TorqueSchedulerService.java?p2=turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TorqueSchedulerService.java&p1=turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TurbineSchedulerService.java&r1=1620557&r2=1692637&rev=1692637&view=diff
==============================================================================
---
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TurbineSchedulerService.java
(original)
+++
turbine/core/trunk/src/java/org/apache/turbine/services/schedule/TorqueSchedulerService.java
Sat Jul 25 19:22:57 2015
@@ -19,11 +19,9 @@ package org.apache.turbine.services.sche
* under the License.
*/
-import java.util.Iterator;
+import java.util.ArrayList;
import java.util.List;
-import javax.servlet.ServletConfig;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.torque.TorqueException;
@@ -37,17 +35,15 @@ import org.apache.turbine.util.TurbineEx
*
* @author <a href="mailto:[email protected]">Dave Bryson</a>
* @author <a href="mailto:[email protected]">Quinton McCombs</a>
- * @version $Id: TurbineSchedulerService.java 534527 2007-05-02 16:10:59Z tv $
+ * @version $Id: TorqueSchedulerService.java 534527 2007-05-02 16:10:59Z tv $
*/
-public class TurbineSchedulerService
- extends TurbineBaseService
- implements ScheduleService
+public class TorqueSchedulerService extends TurbineBaseService implements
ScheduleService
{
/** Logging */
protected static Log log = LogFactory.getLog(ScheduleService.LOGGER_NAME);
/** The queue */
- protected JobQueue scheduleQueue = null;
+ protected JobQueue<JobEntry> scheduleQueue = null;
/** Current status of the scheduler */
protected boolean enabled = false;
@@ -55,13 +51,13 @@ public class TurbineSchedulerService
/** The main loop for starting jobs. */
protected MainLoop mainLoop;
- /** The thread used to process commands. */
+ /** The thread used to process commands. */
protected Thread thread;
/**
* Creates a new instance.
*/
- public TurbineSchedulerService()
+ public TorqueSchedulerService()
{
mainLoop = null;
thread = null;
@@ -70,29 +66,31 @@ public class TurbineSchedulerService
/**
* Initializes the SchedulerService.
*
- * @throws InitializationException Something went wrong in the init
- * stage
+ * @throws InitializationException
+ * Something went wrong in the init stage
*/
@Override
- public void init()
- throws InitializationException
+ public void init() throws InitializationException
{
try
{
setEnabled(getConfiguration().getBoolean("enabled", true));
- scheduleQueue = new JobQueue();
+ scheduleQueue = new JobQueue<JobEntry>();
mainLoop = new MainLoop();
// Load all from cold storage.
- List<JobEntry> jobs = JobEntryPeer.doSelect(new Criteria());
+ List<JobEntryTorque> jobsTorque = JobEntryTorquePeer.doSelect(new
Criteria());
- if (jobs != null && jobs.size() > 0)
+ if (jobsTorque != null)
{
- Iterator<JobEntry> it = jobs.iterator();
- while (it.hasNext())
+ List<JobEntry> jobs = new
ArrayList<JobEntry>(jobsTorque.size());
+
+ for (JobEntryTorque job : jobsTorque)
{
- it.next().calcRunTime();
+ job.calcRunTime();
+ jobs.add(job);
}
+
scheduleQueue.batchLoad(jobs);
restart();
@@ -102,29 +100,11 @@ public class TurbineSchedulerService
}
catch (Exception e)
{
- String errorMessage = "Could not initialize the scheduler service";
- log.error(errorMessage, e);
- throw new InitializationException(errorMessage, e);
+ throw new InitializationException("Could not initialize the
scheduler service", e);
}
}
/**
- * 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.
- *
- * @param config A ServletConfig.
- * @deprecated use init() instead.
- */
- @Deprecated
- public void init(ServletConfig config) throws InitializationException
- {
- init();
- }
-
- /**
* Shutdowns the service.
*
* This methods interrupts the housekeeping thread.
@@ -141,34 +121,36 @@ public class TurbineSchedulerService
/**
* Get a specific Job from Storage.
*
- * @param oid The int id for the job.
+ * @param oid
+ * The int id for the job.
* @return A JobEntry.
- * @exception TurbineException job could not be retreived.
+ * @exception TurbineException
+ * job could not be retrieved.
*/
- public JobEntry getJob(int oid)
- throws TurbineException
+ @Override
+ public JobEntry getJob(int oid) throws TurbineException
{
try
{
- JobEntry je = JobEntryPeer.retrieveByPK(oid);
+ JobEntryTorque je = JobEntryTorquePeer.retrieveByPK(oid);
return scheduleQueue.getJob(je);
}
catch (TorqueException e)
{
- String errorMessage = "Error retrieving job from persistent
storage.";
- log.error(errorMessage, e);
- throw new TurbineException(errorMessage, e);
+ throw new TurbineException("Error retrieving job from persistent
storage.", e);
}
}
/**
* Add a new job to the queue.
*
- * @param je A JobEntry with the job to add.
- * @throws TurbineException job could not be added
+ * @param je
+ * A JobEntry with the job to add.
+ * @throws TurbineException
+ * job could not be added
*/
- public void addJob(JobEntry je)
- throws TurbineException
+ @Override
+ public void addJob(JobEntry je) throws TurbineException
{
updateJob(je);
}
@@ -176,17 +158,19 @@ public class TurbineSchedulerService
/**
* Remove a job from the queue.
*
- * @param je A JobEntry with the job to remove.
- * @exception TurbineException job could not be removed
+ * @param je
+ * A JobEntry with the job to remove.
+ * @exception TurbineException
+ * job could not be removed
*/
- public void removeJob(JobEntry je)
- throws TurbineException
+ @Override
+ public void removeJob(JobEntry je) throws TurbineException
{
try
{
// First remove from DB.
- Criteria c = new Criteria().where(JobEntryPeer.JOB_ID,
je.getPrimaryKey());
- JobEntryPeer.doDelete(c);
+ Criteria c = new Criteria().where(JobEntryTorquePeer.JOB_ID,
Integer.valueOf(je.getJobId()));
+ JobEntryTorquePeer.doDelete(c);
// Remove from the queue.
scheduleQueue.remove(je);
@@ -194,22 +178,22 @@ public class TurbineSchedulerService
// restart the scheduler
restart();
}
- catch (Exception e)
+ catch (TorqueException e)
{
- String errorMessage = "Problem removing Scheduled Job: " +
je.getTask();
- log.error(errorMessage, e);
- throw new TurbineException(errorMessage, 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
+ * @param je
+ * A JobEntry with the job to modify
+ * @throws TurbineException
+ * job could not be updated
*/
- public void updateJob(JobEntry je)
- throws TurbineException
+ @Override
+ public void updateJob(JobEntry je) throws TurbineException
{
try
{
@@ -225,23 +209,29 @@ public class TurbineSchedulerService
scheduleQueue.modify(je);
}
- je.save();
+ if (je instanceof JobEntryTorque)
+ {
+ ((JobEntryTorque)je).save();
+ }
restart();
}
- catch (Exception e)
+ catch (TorqueException e)
{
- String errorMessage = "Problem updating Scheduled Job: " +
je.getTask();
- log.error(errorMessage, e);
- throw new TurbineException(errorMessage, e);
+ throw new TurbineException("Problem persisting Scheduled Job: " +
je.getTask(), e);
+ }
+ catch (TurbineException e)
+ {
+ throw new TurbineException("Problem updating Scheduled Job: " +
je.getTask(), e);
}
}
/**
- * List jobs in the queue. This is used by the scheduler UI.
+ * 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();
@@ -263,6 +253,7 @@ public class TurbineSchedulerService
*
* @return Status of the scheduler service.
*/
+ @Override
public boolean isEnabled()
{
return enabled;
@@ -271,6 +262,7 @@ public class TurbineSchedulerService
/**
* Starts or restarts the scheduler if not already running.
*/
+ @Override
public synchronized void startScheduler()
{
setEnabled(true);
@@ -280,6 +272,7 @@ public class TurbineSchedulerService
/**
* Stops the scheduler if it is currently running.
*/
+ @Override
public synchronized void stopScheduler()
{
log.info("Stopping job scheduler");
@@ -292,9 +285,9 @@ public class TurbineSchedulerService
}
/**
- * 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 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.
*/
@@ -312,10 +305,10 @@ public class TurbineSchedulerService
}
/**
- * 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.
+ * 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()
{
@@ -324,14 +317,14 @@ public class TurbineSchedulerService
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.
+ // 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.
+ // 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();
}
@@ -343,14 +336,13 @@ public class TurbineSchedulerService
}
/**
- * Return the next Job to execute, or null if thread is
- * interrupted.
+ * Return the next Job to execute, or null if thread is interrupted.
*
* @return A JobEntry.
- * @exception TurbineException a generic exception.
+ * @exception TurbineException
+ * a generic exception.
*/
- protected synchronized JobEntry nextJob()
- throws TurbineException
+ protected synchronized JobEntry nextJob() throws TurbineException
{
try
{
@@ -394,16 +386,16 @@ public class TurbineSchedulerService
}
/**
- * 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.
+ * 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
+ protected class MainLoop implements Runnable
{
/**
* Method to run the class.
*/
+ @Override
public void run()
{
String taskName = null;