diff --git a/fine-quartz/src/com/fr/third/v2/org/quartz/impl/jdbcjobstore/JobStoreSupport.java b/fine-quartz/src/com/fr/third/v2/org/quartz/impl/jdbcjobstore/JobStoreSupport.java index 7bbef3c4d..ab378483a 100644 --- a/fine-quartz/src/com/fr/third/v2/org/quartz/impl/jdbcjobstore/JobStoreSupport.java +++ b/fine-quartz/src/com/fr/third/v2/org/quartz/impl/jdbcjobstore/JobStoreSupport.java @@ -1,54 +1,37 @@ -/* - * Copyright 2001-2009 Terracotta, Inc. - * - * Licensed 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 +/* + * Copyright 2001-2009 Terracotta, Inc. + * + * Licensed 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. - * + * */ package com.fr.third.v2.org.quartz.impl.jdbcjobstore; -import java.io.IOException; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Proxy; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; - import com.fr.third.v2.org.quartz.Calendar; import com.fr.third.v2.org.quartz.Job; +import com.fr.third.v2.org.quartz.JobDataMap; import com.fr.third.v2.org.quartz.JobDetail; +import com.fr.third.v2.org.quartz.JobKey; +import com.fr.third.v2.org.quartz.JobPersistenceException; import com.fr.third.v2.org.quartz.ObjectAlreadyExistsException; import com.fr.third.v2.org.quartz.Scheduler; import com.fr.third.v2.org.quartz.SchedulerConfigException; -import com.fr.third.v2.org.quartz.TriggerKey; -import com.fr.third.v2.org.quartz.spi.OperableTrigger; -import com.fr.third.v2.org.quartz.spi.ThreadExecutor; -import com.fr.third.v2.org.quartz.spi.TriggerFiredResult; -import com.fr.third.v2.org.quartz.JobDataMap; -import com.fr.third.v2.org.quartz.JobKey; -import com.fr.third.v2.org.quartz.JobPersistenceException; import com.fr.third.v2.org.quartz.SchedulerException; import com.fr.third.v2.org.quartz.SimpleTrigger; import com.fr.third.v2.org.quartz.Trigger; import com.fr.third.v2.org.quartz.Trigger.CompletedExecutionInstruction; import com.fr.third.v2.org.quartz.Trigger.TriggerState; +import com.fr.third.v2.org.quartz.TriggerKey; import com.fr.third.v2.org.quartz.impl.DefaultThreadExecutor; import com.fr.third.v2.org.quartz.impl.matchers.GroupMatcher; import com.fr.third.v2.org.quartz.impl.matchers.StringMatcher; @@ -56,18 +39,35 @@ import com.fr.third.v2.org.quartz.impl.matchers.StringMatcher.StringOperatorName import com.fr.third.v2.org.quartz.impl.triggers.SimpleTriggerImpl; import com.fr.third.v2.org.quartz.spi.ClassLoadHelper; import com.fr.third.v2.org.quartz.spi.JobStore; +import com.fr.third.v2.org.quartz.spi.OperableTrigger; import com.fr.third.v2.org.quartz.spi.SchedulerSignaler; +import com.fr.third.v2.org.quartz.spi.ThreadExecutor; import com.fr.third.v2.org.quartz.spi.TriggerFiredBundle; +import com.fr.third.v2.org.quartz.spi.TriggerFiredResult; import com.fr.third.v2.org.quartz.utils.DBConnectionManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Proxy; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + /** *
* Contains base functionality for JDBC-based JobStore implementations. *
- * + * * @author Jeffrey Wescott * @author James House */ @@ -75,9 +75,9 @@ public abstract class JobStoreSupport implements JobStore, Constants { /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * + * * Constants. - * + * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ @@ -87,9 +87,9 @@ public abstract class JobStoreSupport implements JobStore, Constants { /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * + * * Data members. - * + * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ @@ -102,11 +102,11 @@ public abstract class JobStoreSupport implements JobStore, Constants { protected String instanceId; protected String instanceName; - + protected String delegateClassName; protected String delegateInitString; - + protected Class extends DriverDelegate> delegateClass = StdJDBCDelegate.class; protected HashMap* Set whether this instance should use database-based thread @@ -384,28 +385,28 @@ public abstract class JobStoreSupport implements JobStore, Constants { public boolean isLockOnInsert() { return lockOnInsert; } - + /** - * Whether or not to obtain locks when inserting new jobs/triggers. + * Whether or not to obtain locks when inserting new jobs/triggers. *
- * Defaults to true
, which is safest. Some databases (such as
+ * Defaults to true
, which is safest. Some databases (such as
* MS SQLServer) seem to require this to avoid deadlocks under high load,
* while others seem to do fine without. Settings this to false means
* isolation guarantees between job scheduling and trigger acquisition are
* entirely enforced by the database. Depending on the database and it's
* configuration this may cause unusual scheduling behaviors.
- *
- *
Setting this property to false
will provide a
- * significant performance increase during the addition of new jobs
+ *
+ *
Setting this property to false
will provide a
+ * significant performance increase during the addition of new jobs
* and triggers.
* However, if batch acquisition is used, it is important for this behavior * to be used for all dbs. */ @@ -482,19 +483,18 @@ public abstract class JobStoreSupport implements JobStore, Constants { this.acquireTriggersWithinLock = acquireTriggersWithinLock; } - + /** *
* Set the JDBC driver delegate class. *
- * - * @param delegateClassName - * the delegate class name + * + * @param delegateClassName the delegate class name */ @SuppressWarnings("UnusedDeclaration") /* called reflectively */ public void setDriverDelegateClass(String delegateClassName) - throws InvalidConfigurationException { - synchronized(this) { + throws InvalidConfigurationException { + synchronized (this) { this.delegateClassName = delegateClassName; } } @@ -503,7 +503,7 @@ public abstract class JobStoreSupport implements JobStore, Constants { ** Get the JDBC driver delegate class name. *
- * + * * @return the delegate class name */ public String getDriverDelegateClass() { @@ -514,13 +514,12 @@ public abstract class JobStoreSupport implements JobStore, Constants { ** Set the JDBC driver delegate's initialization string. *
- * - * @param delegateInitString - * the delegate init string + * + * @param delegateInitString the delegate init string */ @SuppressWarnings("UnusedDeclaration") /* called reflectively */ public void setDriverDelegateInitString(String delegateInitString) - throws InvalidConfigurationException { + throws InvalidConfigurationException { this.delegateInitString = delegateInitString; } @@ -528,7 +527,7 @@ public abstract class JobStoreSupport implements JobStore, Constants { ** Get the JDBC driver delegate's initialization string. *
- * + * * @return the delegate init string */ public String getDriverDelegateInitString() { @@ -544,7 +543,7 @@ public abstract class JobStoreSupport implements JobStore, Constants { * set the SQL statement to use to select and lock a row in the "locks" * table. * - * + * * @see StdRowLockSemaphore */ public void setSelectWithLockSQL(String string) { @@ -557,9 +556,9 @@ public abstract class JobStoreSupport implements JobStore, Constants { /** * Get whether the threads spawned by this JobStore should be - * marked as daemon. Possible threads include theMisfireHandler
+ * marked as daemon. Possible threads include the MisfireHandler
* and the ClusterManager
.
- *
+ *
* @see Thread#setDaemon(boolean)
*/
public boolean getMakeThreadsDaemons() {
@@ -568,7 +567,7 @@ public abstract class JobStoreSupport implements JobStore, Constants {
/**
* Set whether the threads spawned by this JobStore should be
- * marked as daemon. Possible threads include the MisfireHandler
+ * marked as daemon. Possible threads include the MisfireHandler
* and the ClusterManager
.
*
* @see Thread#setDaemon(boolean)
@@ -577,7 +576,7 @@ public abstract class JobStoreSupport implements JobStore, Constants {
public void setMakeThreadsDaemons(boolean makeThreadsDaemons) {
this.makeThreadsDaemons = makeThreadsDaemons;
}
-
+
/**
* Get whether to set the class load context of spawned threads to that
* of the initializing thread.
@@ -597,7 +596,7 @@ public abstract class JobStoreSupport implements JobStore, Constants {
/**
* Get whether to check to see if there are Triggers that have misfired
- * before actually acquiring the lock to recover them. This should be
+ * before actually acquiring the lock to recover them. This should be
* set to false if the majority of the time, there are are misfired
* Triggers.
*/
@@ -607,7 +606,7 @@ public abstract class JobStoreSupport implements JobStore, Constants {
/**
* Set whether to check to see if there are Triggers that have misfired
- * before actually acquiring the lock to recover them. This should be
+ * before actually acquiring the lock to recover them. This should be
* set to false if the majority of the time, there are are misfired
* Triggers.
*/
@@ -616,7 +615,7 @@ public abstract class JobStoreSupport implements JobStore, Constants {
boolean doubleCheckLockMisfireHandler) {
this.doubleCheckLockMisfireHandler = doubleCheckLockMisfireHandler;
}
-
+
//---------------------------------------------------------------------------
// interface methods
//---------------------------------------------------------------------------
@@ -632,33 +631,33 @@ public abstract class JobStoreSupport implements JobStore, Constants {
*
*/
public void initialize(ClassLoadHelper loadHelper,
- SchedulerSignaler signaler) throws SchedulerConfigException {
+ SchedulerSignaler signaler) throws SchedulerConfigException {
- if (dsName == null) {
- throw new SchedulerConfigException("DataSource name not set.");
+ if (dsName == null) {
+ throw new SchedulerConfigException("DataSource name not set.");
}
classLoadHelper = loadHelper;
- if(isThreadsInheritInitializersClassLoadContext()) {
+ if (isThreadsInheritInitializersClassLoadContext()) {
log.info("JDBCJobStore threads will inherit ContextClassLoader of thread: " + Thread.currentThread().getName());
initializersLoader = Thread.currentThread().getContextClassLoader();
}
-
+
this.schedSignaler = signaler;
// If the user hasn't specified an explicit lock handler, then
// choose one based on CMT/Clustered/UseDBLocks.
if (getLockHandler() == null) {
-
+
// If the user hasn't specified an explicit lock handler,
// then we *must* use DB locks with clustering
if (isClustered()) {
setUseDBLocks(true);
}
-
+
if (getUseDBLocks()) {
- if(getDriverDelegateClass() != null && getDriverDelegateClass().equals(MSSQLDelegate.class.getName())) {
- if(getSelectWithLockSQL() == null) {
+ if (getDriverDelegateClass() != null && getDriverDelegateClass().equals(MSSQLDelegate.class.getName())) {
+ if (getSelectWithLockSQL() == null) {
String msSqlDflt = "SELECT * FROM {0}LOCKS WITH (UPDLOCK,ROWLOCK) WHERE " + COL_SCHEDULER_NAME + " = {1} AND LOCK_NAME = ?";
getLog().info("Detected usage of MSSQLDelegate class - defaulting 'selectWithLockSQL' to '" + msSqlDflt + "'.");
setSelectWithLockSQL(msSqlDflt);
@@ -668,13 +667,13 @@ public abstract class JobStoreSupport implements JobStore, Constants {
setLockHandler(new StdRowLockSemaphore(getTablePrefix(), getInstanceName(), getSelectWithLockSQL()));
} else {
getLog().info(
- "Using thread monitor-based data access locking (synchronization).");
+ "Using thread monitor-based data access locking (synchronization).");
setLockHandler(new SimpleSemaphore());
}
}
}
-
+
/**
* @see JobStore#schedulerStarted()
*/
@@ -682,7 +681,7 @@ public abstract class JobStoreSupport implements JobStore, Constants {
if (isClustered()) {
clusterManagementThread = new ClusterManager();
- if(initializersLoader != null)
+ if (initializersLoader != null)
clusterManagementThread.setContextClassLoader(initializersLoader);
clusterManagementThread.initialize();
} else {
@@ -695,22 +694,22 @@ public abstract class JobStoreSupport implements JobStore, Constants {
}
misfireHandler = new MisfireHandler();
- if(initializersLoader != null)
+ if (initializersLoader != null)
misfireHandler.setContextClassLoader(initializersLoader);
misfireHandler.initialize();
schedulerRunning = true;
-
+
getLog().debug("JobStore background threads started (as scheduler was started).");
}
-
+
public void schedulerPaused() {
schedulerRunning = false;
}
-
+
public void schedulerResumed() {
schedulerRunning = true;
}
-
+
/**
*
* Called by the QuartzScheduler to inform the JobStore
that
@@ -720,7 +719,7 @@ public abstract class JobStoreSupport implements JobStore, Constants {
*/
public void shutdown() {
shutdown = true;
-
+
if (misfireHandler != null) {
misfireHandler.shutdown();
try {
@@ -741,8 +740,8 @@ public abstract class JobStoreSupport implements JobStore, Constants {
DBConnectionManager.getInstance().shutdown(getDataSource());
} catch (SQLException sqle) {
getLog().warn("Database connection shutdown unsuccessful.", sqle);
- }
-
+ }
+
getLog().debug("JobStore background threads shutdown.");
}
@@ -755,20 +754,20 @@ public abstract class JobStoreSupport implements JobStore, Constants {
//---------------------------------------------------------------------------
protected abstract Connection getNonManagedTXConnection()
- throws JobPersistenceException;
+ throws JobPersistenceException;
/**
- * Wrap the given Connection
in a Proxy such that attributes
- * that might be set will be restored before the connection is closed
+ * Wrap the given Connection
in a Proxy such that attributes
+ * that might be set will be restored before the connection is closed
* (and potentially restored to a pool).
*/
protected Connection getAttributeRestoringConnection(Connection conn) {
- return (Connection)Proxy.newProxyInstance(
+ return (Connection) Proxy.newProxyInstance(
Thread.currentThread().getContextClassLoader(),
- new Class[] { Connection.class },
+ new Class[]{Connection.class},
new AttributeRestoringConnectionInvocationHandler(conn));
}
-
+
protected Connection getConnection() throws JobPersistenceException {
Connection conn;
try {
@@ -777,17 +776,17 @@ public abstract class JobStoreSupport implements JobStore, Constants {
} catch (SQLException sqle) {
throw new JobPersistenceException(
"Failed to obtain DB connection from data source '"
- + getDataSource() + "': " + sqle.toString(), sqle);
+ + getDataSource() + "': " + sqle.toString(), sqle);
} catch (Throwable e) {
throw new JobPersistenceException(
"Failed to obtain DB connection from data source '"
- + getDataSource() + "': " + e.toString(), e);
+ + getDataSource() + "': " + e.toString(), e);
}
- if (conn == null) {
+ if (conn == null) {
throw new JobPersistenceException(
- "Could not get connection from DataSource '"
- + getDataSource() + "'");
+ "Could not get connection from DataSource '"
+ + getDataSource() + "'");
}
// Protect connection attributes we might change.
@@ -799,18 +798,21 @@ public abstract class JobStoreSupport implements JobStore, Constants {
conn.setAutoCommit(false);
}
- if(isTxIsolationLevelSerializable()) {
+ if (isTxIsolationLevelSerializable()) {
conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
}
} catch (SQLException sqle) {
getLog().warn("Failed to override connection auto commit/transaction isolation.", sqle);
} catch (Throwable e) {
- try { conn.close(); } catch(Throwable ignored) {}
-
+ try {
+ conn.close();
+ } catch (Throwable ignored) {
+ }
+
throw new JobPersistenceException(
- "Failure setting up connection.", e);
+ "Failure setting up connection.", e);
}
-
+
return conn;
}
@@ -827,27 +829,26 @@ public abstract class JobStoreSupport implements JobStore, Constants {
/**
* Recover any failed or misfired jobs and clean up the data store as
* appropriate.
- *
+ *
* @throws JobPersistenceException if jobs could not be recovered
*/
protected void recoverJobs() throws JobPersistenceException {
executeInNonManagedTXLock(
- LOCK_TRIGGER_ACCESS,
- new VoidTransactionCallback() {
- public void executeVoid(Connection conn) throws JobPersistenceException {
- recoverJobs(conn);
- }
- }, null);
+ LOCK_TRIGGER_ACCESS,
+ new VoidTransactionCallback() {
+ public void executeVoid(Connection conn) throws JobPersistenceException {
+ recoverJobs(conn);
+ }
+ }, null);
}
-
+
/**
*
* Will recover any failed or misfired jobs and clean up the data store as * appropriate. *
- * - * @throws JobPersistenceException - * if jobs could not be recovered + * + * @throws JobPersistenceException if jobs could not be recovered */ protected void recoverJobs(Connection conn) throws JobPersistenceException { try { @@ -856,15 +857,15 @@ public abstract class JobStoreSupport implements JobStore, Constants { STATE_WAITING, STATE_ACQUIRED, STATE_BLOCKED); rows += getDelegate().updateTriggerStatesFromOtherStates(conn, - STATE_PAUSED, STATE_PAUSED_BLOCKED, STATE_PAUSED_BLOCKED); - + STATE_PAUSED, STATE_PAUSED_BLOCKED, STATE_PAUSED_BLOCKED); + getLog().info( "Freed " + rows + " triggers from 'acquired' / 'blocked' state."); // clean up misfired jobs recoverMisfiredJobs(conn, true); - + // recover jobs marked for recovery that were not fully executed List
* Store the given {@link JobDetail}
and {@link Trigger}
.
*
JobDetail
to be stored.
- * @param newTrigger
- * The Trigger
to be stored.
- * @throws ObjectAlreadyExistsException
- * if a Job
with the same name/group already
- * exists.
+ *
+ * @param newJob The JobDetail
to be stored.
+ * @param newTrigger The Trigger
to be stored.
+ * @throws ObjectAlreadyExistsException if a Job
with the same name/group already
+ * exists.
*/
public void storeJobAndTrigger(final JobDetail newJob,
- final OperableTrigger newTrigger)
- throws JobPersistenceException {
+ final OperableTrigger newTrigger)
+ throws JobPersistenceException {
executeInLock(
- (isLockOnInsert()) ? LOCK_TRIGGER_ACCESS : null,
- new VoidTransactionCallback() {
- public void executeVoid(Connection conn) throws JobPersistenceException {
- storeJob(conn, newJob, false);
- storeTrigger(conn, newTrigger, newJob, false,
- STATE_WAITING, false, false);
- }
- });
+ (isLockOnInsert()) ? LOCK_TRIGGER_ACCESS : null,
+ new VoidTransactionCallback() {
+ public void executeVoid(Connection conn) throws JobPersistenceException {
+ storeJob(conn, newJob, false);
+ storeTrigger(conn, newTrigger, newJob, false,
+ STATE_WAITING, false, false);
+ }
+ });
}
-
+
/**
*
* Store the given {@link JobDetail}
.
*
JobDetail
to be stored.
- * @param replaceExisting
- * If true
, any Job
existing in the
- * JobStore
with the same name & group should be
- * over-written.
- * @throws ObjectAlreadyExistsException
- * if a Job
with the same name/group already
- * exists, and replaceExisting is set to false.
+ *
+ * @param newJob The JobDetail
to be stored.
+ * @param replaceExisting If true
, any Job
existing in the
+ * JobStore
with the same name & group should be
+ * over-written.
+ * @throws ObjectAlreadyExistsException if a Job
with the same name/group already
+ * exists, and replaceExisting is set to false.
*/
public void storeJob(final JobDetail newJob,
- final boolean replaceExisting) throws JobPersistenceException {
+ final boolean replaceExisting) throws JobPersistenceException {
executeInLock(
- (isLockOnInsert() || replaceExisting) ? LOCK_TRIGGER_ACCESS : null,
- new VoidTransactionCallback() {
- public void executeVoid(Connection conn) throws JobPersistenceException {
- storeJob(conn, newJob, replaceExisting);
- }
- });
+ (isLockOnInsert() || replaceExisting) ? LOCK_TRIGGER_ACCESS : null,
+ new VoidTransactionCallback() {
+ public void executeVoid(Connection conn) throws JobPersistenceException {
+ storeJob(conn, newJob, replaceExisting);
+ }
+ });
}
-
+
/**
* * Insert or update a job. @@ -1099,12 +1100,12 @@ public abstract class JobStoreSupport implements JobStore, Constants { */ protected void storeJob(Connection conn, JobDetail newJob, boolean replaceExisting) - throws JobPersistenceException { + throws JobPersistenceException { boolean existingJob = jobExists(conn, newJob.getKey()); try { if (existingJob) { - if (!replaceExisting) { + if (!replaceExisting) { throw new ObjectAlreadyExistsException(newJob); } getDelegate().updateJobDetail(conn, newJob); @@ -1139,29 +1140,26 @@ public abstract class JobStoreSupport implements JobStore, Constants { *
* Store the given {@link Trigger}
.
*
Trigger
to be stored.
- * @param replaceExisting
- * If true
, any Trigger
existing in
- * the JobStore
with the same name & group should
- * be over-written.
- * @throws ObjectAlreadyExistsException
- * if a Trigger
with the same name/group already
- * exists, and replaceExisting is set to false.
+ *
+ * @param newTrigger The Trigger
to be stored.
+ * @param replaceExisting If true
, any Trigger
existing in
+ * the JobStore
with the same name & group should
+ * be over-written.
+ * @throws ObjectAlreadyExistsException if a Trigger
with the same name/group already
+ * exists, and replaceExisting is set to false.
*/
public void storeTrigger(final OperableTrigger newTrigger,
- final boolean replaceExisting) throws JobPersistenceException {
+ final boolean replaceExisting) throws JobPersistenceException {
executeInLock(
- (isLockOnInsert() || replaceExisting) ? LOCK_TRIGGER_ACCESS : null,
- new VoidTransactionCallback() {
- public void executeVoid(Connection conn) throws JobPersistenceException {
- storeTrigger(conn, newTrigger, null, replaceExisting,
- STATE_WAITING, false, false);
- }
- });
+ (isLockOnInsert() || replaceExisting) ? LOCK_TRIGGER_ACCESS : null,
+ new VoidTransactionCallback() {
+ public void executeVoid(Connection conn) throws JobPersistenceException {
+ storeTrigger(conn, newTrigger, null, replaceExisting,
+ STATE_WAITING, false, false);
+ }
+ });
}
-
+
/**
*
* Insert or update a trigger.
@@ -1171,14 +1169,14 @@ public abstract class JobStoreSupport implements JobStore, Constants {
protected void storeTrigger(Connection conn,
OperableTrigger newTrigger, JobDetail job, boolean replaceExisting, String state,
boolean forceState, boolean recovering)
- throws JobPersistenceException {
+ throws JobPersistenceException {
boolean existingTrigger = triggerExists(conn, newTrigger.getKey());
- if ((existingTrigger) && (!replaceExisting)) {
+ if ((existingTrigger) && (!replaceExisting)) {
throw new ObjectAlreadyExistsException(newTrigger);
}
-
+
try {
boolean shouldBepaused;
@@ -1187,7 +1185,7 @@ public abstract class JobStoreSupport implements JobStore, Constants {
shouldBepaused = getDelegate().isTriggerGroupPaused(
conn, newTrigger.getKey().getGroup());
- if(!shouldBepaused) {
+ if (!shouldBepaused) {
shouldBepaused = getDelegate().isTriggerGroupPaused(conn,
ALL_GROUPS_PAUSED);
@@ -1201,7 +1199,7 @@ public abstract class JobStoreSupport implements JobStore, Constants {
}
}
- if(job == null) {
+ if (job == null) {
job = retrieveJob(conn, newTrigger.getJobKey());
}
if (job == null) {
@@ -1210,17 +1208,17 @@ public abstract class JobStoreSupport implements JobStore, Constants {
+ ") referenced by the trigger does not exist.");
}
- if (job.isConcurrentExectionDisallowed() && !recovering) {
+ if (job.isConcurrentExectionDisallowed() && !recovering) {
state = checkBlockedState(conn, job.getKey(), state);
}
-
+
if (existingTrigger) {
getDelegate().updateTrigger(conn, newTrigger, state, job);
} else {
getDelegate().insertTrigger(conn, newTrigger, state, job);
}
} catch (Exception e) {
- throw new JobPersistenceException("Couldn't store trigger '" + newTrigger.getKey() + "' for '"
+ throw new JobPersistenceException("Couldn't store trigger '" + newTrigger.getKey() + "' for '"
+ newTrigger.getJobKey() + "' job:" + e.getMessage(), e);
}
}
@@ -1245,15 +1243,15 @@ public abstract class JobStoreSupport implements JobStore, Constants {
* name, and any {@link Trigger}
s that reference
* it.
*
* If removal of the Job
results in an empty group, the
* group should be removed from the JobStore
's list of
* known group names.
*
true
if a Job
with the given name &
- * group was found and removed from the store.
+ * group was found and removed from the store.
*/
public boolean removeJob(final JobKey jobKey) throws JobPersistenceException {
return (Boolean) executeInLock(
@@ -1265,13 +1263,13 @@ public abstract class JobStoreSupport implements JobStore, Constants {
}
});
}
-
+
protected boolean removeJob(Connection conn, final JobKey jobKey)
- throws JobPersistenceException {
+ throws JobPersistenceException {
try {
List
* Retrieve the {@link JobDetail}
for the given
* {@link Job}
.
*
Job
, or null if there is no match.
*/
public JobDetail retrieveJob(final JobKey jobKey) throws JobPersistenceException {
- return (JobDetail)executeWithoutLock( // no locks necessary for read...
- new TransactionCallback() {
- public Object execute(Connection conn) throws JobPersistenceException {
- return retrieveJob(conn, jobKey);
- }
- });
+ return (JobDetail) executeWithoutLock( // no locks necessary for read...
+ new TransactionCallback() {
+ public Object execute(Connection conn) throws JobPersistenceException {
+ return retrieveJob(conn, jobKey);
+ }
+ });
}
-
+
protected JobDetail retrieveJob(Connection conn, JobKey key) throws JobPersistenceException {
try {
@@ -1403,21 +1401,21 @@ public abstract class JobStoreSupport implements JobStore, Constants {
* Remove (delete) the {@link Trigger}
with the
* given name.
*
- *
+ *
*
* If removal of the Trigger
results in an empty group, the
* group should be removed from the JobStore
's list of
* known group names.
*
* If removal of the Trigger
results in an 'orphaned' Job
* that is not 'durable', then the Job
should be deleted
* also.
*
true
if a Trigger
with the given
- * name & group was found and removed from the store.
+ * name & group was found and removed from the store.
*/
public boolean removeTrigger(final TriggerKey triggerKey) throws JobPersistenceException {
return (Boolean) executeInLock(
@@ -1429,17 +1427,17 @@ public abstract class JobStoreSupport implements JobStore, Constants {
}
});
}
-
+
protected boolean removeTrigger(Connection conn, TriggerKey key)
- throws JobPersistenceException {
+ throws JobPersistenceException {
boolean removedTrigger;
try {
// this must be called before we delete the trigger, obviously
JobDetail job = getDelegate().selectJobForTrigger(conn,
getClassLoadHelper(), key, false);
- removedTrigger =
- deleteTriggerAndChildren(conn, key);
+ removedTrigger =
+ deleteTriggerAndChildren(conn, key);
if (null != job && !job.isDurable()) {
int numTriggers = getDelegate().selectNumTriggersForJob(conn,
@@ -1461,11 +1459,11 @@ public abstract class JobStoreSupport implements JobStore, Constants {
return removedTrigger;
}
- /**
+ /**
* @see JobStore#replaceTrigger(TriggerKey, OperableTrigger)
*/
- public boolean replaceTrigger(final TriggerKey triggerKey,
- final OperableTrigger newTrigger) throws JobPersistenceException {
+ public boolean replaceTrigger(final TriggerKey triggerKey,
+ final OperableTrigger newTrigger) throws JobPersistenceException {
return (Boolean) executeInLock(
LOCK_TRIGGER_ACCESS,
new TransactionCallback() {
@@ -1475,10 +1473,10 @@ public abstract class JobStoreSupport implements JobStore, Constants {
}
});
}
-
- protected boolean replaceTrigger(Connection conn,
- TriggerKey key, OperableTrigger newTrigger)
- throws JobPersistenceException {
+
+ protected boolean replaceTrigger(Connection conn,
+ TriggerKey key, OperableTrigger newTrigger)
+ throws JobPersistenceException {
try {
// this must be called before we delete the trigger, obviously
JobDetail job = getDelegate().selectJobForTrigger(conn,
@@ -1487,14 +1485,14 @@ public abstract class JobStoreSupport implements JobStore, Constants {
if (job == null) {
return false;
}
-
+
if (!newTrigger.getJobKey().equals(job.getKey())) {
throw new JobPersistenceException("New trigger is not related to the same job as the old trigger.");
}
-
- boolean removedTrigger =
- deleteTriggerAndChildren(conn, key);
-
+
+ boolean removedTrigger =
+ deleteTriggerAndChildren(conn, key);
+
storeTrigger(conn, newTrigger, job, false, STATE_WAITING, false, false);
return removedTrigger;
@@ -1511,21 +1509,21 @@ public abstract class JobStoreSupport implements JobStore, Constants {
*
* Retrieve the given {@link Trigger}
.
*
Trigger
, or null if there is no
- * match.
+ * match.
*/
public OperableTrigger retrieveTrigger(final TriggerKey triggerKey) throws JobPersistenceException {
- return (OperableTrigger)executeWithoutLock( // no locks necessary for read...
- new TransactionCallback() {
- public Object execute(Connection conn) throws JobPersistenceException {
- return retrieveTrigger(conn, triggerKey);
- }
- });
+ return (OperableTrigger) executeWithoutLock( // no locks necessary for read...
+ new TransactionCallback() {
+ public Object execute(Connection conn) throws JobPersistenceException {
+ return retrieveTrigger(conn, triggerKey);
+ }
+ });
}
-
+
protected OperableTrigger retrieveTrigger(Connection conn, TriggerKey key)
- throws JobPersistenceException {
+ throws JobPersistenceException {
try {
return getDelegate().selectTrigger(conn, key);
@@ -1539,7 +1537,7 @@ public abstract class JobStoreSupport implements JobStore, Constants {
*
* Get the current state of the identified {@link Trigger}
.
*
* Store the given {@link Calendar}
.
*
Calendar
to be stored.
- * @param replaceExisting
- * If true
, any Calendar
existing
- * in the JobStore
with the same name & group
- * should be over-written.
- * @throws ObjectAlreadyExistsException
- * if a Calendar
with the same name already
- * exists, and replaceExisting is set to false.
+ *
+ * @param calName The name of the calendar.
+ * @param calendar The Calendar
to be stored.
+ * @param replaceExisting If true
, any Calendar
existing
+ * in the JobStore
with the same name & group
+ * should be over-written.
+ * @throws ObjectAlreadyExistsException if a Calendar
with the same name already
+ * exists, and replaceExisting is set to false.
*/
public void storeCalendar(final String calName,
final Calendar calendar, final boolean replaceExisting, final boolean updateTriggers)
- throws JobPersistenceException {
+ throws JobPersistenceException {
executeInLock(
- (isLockOnInsert() || updateTriggers) ? LOCK_TRIGGER_ACCESS : null,
- new VoidTransactionCallback() {
- public void executeVoid(Connection conn) throws JobPersistenceException {
- storeCalendar(conn, calName, calendar, replaceExisting, updateTriggers);
- }
- });
+ (isLockOnInsert() || updateTriggers) ? LOCK_TRIGGER_ACCESS : null,
+ new VoidTransactionCallback() {
+ public void executeVoid(Connection conn) throws JobPersistenceException {
+ storeCalendar(conn, calName, calendar, replaceExisting, updateTriggers);
+ }
+ });
}
-
+
protected void storeCalendar(Connection conn,
String calName, Calendar calendar, boolean replaceExisting, boolean updateTriggers)
- throws JobPersistenceException {
+ throws JobPersistenceException {
try {
boolean existingCal = calendarExists(conn, calName);
- if (existingCal && !replaceExisting) {
+ if (existingCal && !replaceExisting) {
throw new ObjectAlreadyExistsException(
- "Calendar with name '" + calName + "' already exists.");
+ "Calendar with name '" + calName + "' already exists.");
}
if (existingCal) {
- if (getDelegate().updateCalendar(conn, calName, calendar) < 1) {
+ if (getDelegate().updateCalendar(conn, calName, calendar) < 1) {
throw new JobPersistenceException(
- "Couldn't store calendar. Update failed.");
+ "Couldn't store calendar. Update failed.");
}
-
- if(updateTriggers) {
+
+ if (updateTriggers) {
List{@link Calendar}
with the
* given name.
*
- *
+ *
*
* If removal of the Calendar
would result in
* Trigger
s pointing to non-existent calendars, then a
* JobPersistenceException
will be thrown.
Calendar
to be removed.
* @return true
if a Calendar
with the given name
* was found and removed from the store.
*/
public boolean removeCalendar(final String calName)
- throws JobPersistenceException {
+ throws JobPersistenceException {
return (Boolean) executeInLock(
LOCK_TRIGGER_ACCESS,
new TransactionCallback() {
@@ -1710,13 +1705,13 @@ public abstract class JobStoreSupport implements JobStore, Constants {
}
});
}
-
- protected boolean removeCalendar(Connection conn,
- String calName) throws JobPersistenceException {
+
+ protected boolean removeCalendar(Connection conn,
+ String calName) throws JobPersistenceException {
try {
- if (getDelegate().calendarIsReferenced(conn, calName)) {
+ if (getDelegate().calendarIsReferenced(conn, calName)) {
throw new JobPersistenceException(
- "Calender cannot be removed if it referenced by a trigger!");
+ "Calender cannot be removed if it referenced by a trigger!");
}
if (!isClustered) {
@@ -1734,25 +1729,24 @@ public abstract class JobStoreSupport implements JobStore, Constants {
*
* Retrieve the given {@link Trigger}
.
*
Calendar
to be retrieved.
+ *
+ * @param calName The name of the Calendar
to be retrieved.
* @return The desired Calendar
, or null if there is no
- * match.
+ * match.
*/
public Calendar retrieveCalendar(final String calName)
- throws JobPersistenceException {
- return (Calendar)executeWithoutLock( // no locks necessary for read...
- new TransactionCallback() {
- public Object execute(Connection conn) throws JobPersistenceException {
- return retrieveCalendar(conn, calName);
- }
- });
+ throws JobPersistenceException {
+ return (Calendar) executeWithoutLock( // no locks necessary for read...
+ new TransactionCallback() {
+ public Object execute(Connection conn) throws JobPersistenceException {
+ return retrieveCalendar(conn, calName);
+ }
+ });
}
-
+
protected Calendar retrieveCalendar(Connection conn,
String calName)
- throws JobPersistenceException {
+ throws JobPersistenceException {
// all calendars are persistent, but we can lazy-cache them during run
// time as long as we aren't running clustered.
Calendar cal = (isClustered) ? null : calendarCache.get(calName);
@@ -1787,7 +1781,7 @@ public abstract class JobStoreSupport implements JobStore, Constants {
*
*/
public int getNumberOfJobs()
- throws JobPersistenceException {
+ throws JobPersistenceException {
return (Integer) executeWithoutLock( // no locks necessary for read...
new TransactionCallback() {
public Object execute(Connection conn) throws JobPersistenceException {
@@ -1795,9 +1789,9 @@ public abstract class JobStoreSupport implements JobStore, Constants {
}
});
}
-
+
protected int getNumberOfJobs(Connection conn)
- throws JobPersistenceException {
+ throws JobPersistenceException {
try {
return getDelegate().selectNumJobs(conn);
} catch (SQLException e) {
@@ -1813,7 +1807,7 @@ public abstract class JobStoreSupport implements JobStore, Constants {
*
*/
public int getNumberOfTriggers()
- throws JobPersistenceException {
+ throws JobPersistenceException {
return (Integer) executeWithoutLock( // no locks necessary for read...
new TransactionCallback() {
public Object execute(Connection conn) throws JobPersistenceException {
@@ -1821,9 +1815,9 @@ public abstract class JobStoreSupport implements JobStore, Constants {
}
});
}
-
+
protected int getNumberOfTriggers(Connection conn)
- throws JobPersistenceException {
+ throws JobPersistenceException {
try {
return getDelegate().selectNumTriggers(conn);
} catch (SQLException e) {
@@ -1839,7 +1833,7 @@ public abstract class JobStoreSupport implements JobStore, Constants {
*
*/
public int getNumberOfCalendars()
- throws JobPersistenceException {
+ throws JobPersistenceException {
return (Integer) executeWithoutLock( // no locks necessary for read...
new TransactionCallback() {
public Object execute(Connection conn) throws JobPersistenceException {
@@ -1847,9 +1841,9 @@ public abstract class JobStoreSupport implements JobStore, Constants {
}
});
}
-
+
protected int getNumberOfCalendars(Connection conn)
- throws JobPersistenceException {
+ throws JobPersistenceException {
try {
return getDelegate().selectNumCalendars(conn);
} catch (SQLException e) {
@@ -1863,24 +1857,24 @@ public abstract class JobStoreSupport implements JobStore, Constants {
* Get the names of all of the {@link Job}
s that
* matcher the given groupMatcher.
*
- *
+ *
* * If there are no jobs in the given group name, the result should be an empty Set *
*/ @SuppressWarnings("unchecked") public Set
* Get the names of all of the {@link Trigger}
s
* that match the given group Matcher.
*
* If there are no triggers in the given group name, the result should be a
* an empty Set (not null
).
@@ -1983,19 +1977,19 @@ public abstract class JobStoreSupport implements JobStore, Constants {
*/
@SuppressWarnings("unchecked")
public Set{@link Job}
* groups.
*
* If there are no known group names, the result should be a zero-length
* array (not null
).
@@ -2021,17 +2015,17 @@ public abstract class JobStoreSupport implements JobStore, Constants {
*/
@SuppressWarnings("unchecked")
public List{@link Trigger}
* groups.
*
* If there are no known group names, the result should be a zero-length
* array (not null
).
@@ -2058,15 +2052,15 @@ public abstract class JobStoreSupport implements JobStore, Constants {
*/
@SuppressWarnings("unchecked")
public List{@link Calendar}
s
* in the JobStore
.
*
* If there are no Calendars in the given group name, the result should be
* a zero-length array (not
* Get all of the Triggers that are associated to the given Job.
*
* If there are no matches, a zero-length array should be returned.
*
* Pause the
* Pause the null
).
@@ -2094,17 +2088,17 @@ public abstract class JobStoreSupport implements JobStore, Constants {
*/
@SuppressWarnings("unchecked")
public List{@link Trigger}
with the given name.
* {@link Trigger}
with the given name.
* {@link Job}
with the given name - by
* pausing all of its current Trigger
s.
*
* Pause all of the {@link Job}s
matching the given
* groupMatcher - by pausing all of their Trigger
s.
*
{@link Trigger}
with the
* given name.
*
- *
+ *
*
* If the Trigger
missed one or more fire-times, then the
* Trigger
's misfire instruction will be applied.
*
* Resume (un-pause) the {@link Trigger}
with the
* given name.
*
* If the Trigger
missed one or more fire-times, then the
* Trigger
's misfire instruction will be applied.
*
{@link Job}
with the
* given name.
*
- *
+ *
*
* If any of the Job
'sTrigger
s missed one
* or more fire-times, then the Trigger
's misfire
* instruction will be applied.
*
* Resume (un-pause) all of the {@link Job}s
in
* the given group.
*
* If any of the Job
s had Trigger
s that
* missed one or more fire-times, then the Trigger
's
* misfire instruction will be applied.
*
* Pause all of the {@link Trigger}s
matching the
* given groupMatcher.
*
* Pause all of the {@link Trigger}s
matching the
* given groupMatcher.
*
* Pause all of the {@link Trigger}s
in the
* given group.
*
* Resume (un-pause) all of the {@link Trigger}s
* matching the given groupMatcher.
*
* If any Trigger
missed one or more fire-times, then the
* Trigger
's misfire instruction will be applied.
*
* Resume (un-pause) all of the {@link Trigger}s
* matching the given groupMatcher.
*
* If any Trigger
missed one or more fire-times, then the
* Trigger
's misfire instruction will be applied.
*
pauseTriggerGroup(group)
* on every group.
*
- *
+ *
*
* When resumeAll()
is called (to un-pause), trigger misfire
* instructions WILL be applied.
*
* Pause all triggers - equivalent of calling pauseTriggerGroup(group)
* on every group.
*
* When resumeAll()
is called (to un-pause), trigger misfire
* instructions WILL be applied.
*
resumeTriggerGroup(group)
* on every group.
*
- *
+ *
*
* If any Trigger
missed one or more fire-times, then the
* Trigger
's misfire instruction will be applied.
*
* Resume (un-pause) all triggers - equivalent of calling resumeTriggerGroup(group)
* on every group.
*
* If any Trigger
missed one or more fire-times, then the
* Trigger
's misfire instruction will be applied.
*
* Inform the JobStore
that the scheduler no longer plans to
@@ -2879,17 +2873,17 @@ public abstract class JobStoreSupport implements JobStore, Constants {
*/
public void releaseAcquiredTrigger(final OperableTrigger trigger) {
retryExecuteInNonManagedTXLock(
- LOCK_TRIGGER_ACCESS,
- new VoidTransactionCallback() {
- public void executeVoid(Connection conn) throws JobPersistenceException {
- releaseAcquiredTrigger(conn, trigger);
- }
- });
+ LOCK_TRIGGER_ACCESS,
+ new VoidTransactionCallback() {
+ public void executeVoid(Connection conn) throws JobPersistenceException {
+ releaseAcquiredTrigger(conn, trigger);
+ }
+ });
}
-
+
protected void releaseAcquiredTrigger(Connection conn,
- OperableTrigger trigger)
- throws JobPersistenceException {
+ OperableTrigger trigger)
+ throws JobPersistenceException {
try {
getDelegate().updateTriggerStateFromOtherState(conn,
trigger.getKey(), STATE_WAITING, STATE_ACQUIRED);
@@ -2906,10 +2900,10 @@ public abstract class JobStoreSupport implements JobStore, Constants {
* given Trigger
(executing its associated Job
),
* that it had previously acquired (reserved).
*
SchedulerStateRecord
objects for fired triggers
* that have no scheduler state record. Checkin timestamp and interval are
* left as zero on these dummy SchedulerStateRecord
objects.
- *
+ *
* @param schedulerStateRecords List of all current SchedulerStateRecords
*/
private List- * This is separate from closeConnection() because the Spring + * This is separate from closeConnection() because the Spring * integration relies on being able to overload closeConnection() and * expects the same connection back that it originally returned - * from the datasource. + * from the datasource. *
- * + * * @see #closeConnection(Connection) */ protected void cleanupConnection(Connection conn) { if (conn != null) { if (conn instanceof Proxy) { - Proxy connProxy = (Proxy)conn; - - InvocationHandler invocationHandler = - Proxy.getInvocationHandler(connProxy); + Proxy connProxy = (Proxy) conn; + + InvocationHandler invocationHandler = + Proxy.getInvocationHandler(connProxy); if (invocationHandler instanceof AttributeRestoringConnectionInvocationHandler) { AttributeRestoringConnectionInvocationHandler connHandler = - (AttributeRestoringConnectionInvocationHandler)invocationHandler; - + (AttributeRestoringConnectionInvocationHandler) invocationHandler; + connHandler.restoreOriginalAtributes(); closeConnection(connHandler.getWrappedConnection()); return; } } - + // Wan't a Proxy, or was a Proxy, but wasn't ours. closeConnection(conn); } } - - + + /** * Closes the suppliedConnection
.
*
- * Ignores a null Connection
.
+ * Ignores a null Connection
.
* Any exception thrown trying to close the Connection
is
- * logged and ignored.
+ * logged and ignored.
*
Connection
to close (Optional).
*/
protected void closeConnection(Connection conn) {
@@ -3643,18 +3642,18 @@ public abstract class JobStoreSupport implements JobStore, Constants {
getLog().error("Failed to close Connection", e);
} catch (Throwable e) {
getLog().error(
- "Unexpected exception closing Connection." +
- " This is often due to a Connection being returned after or during shutdown.", e);
+ "Unexpected exception closing Connection." +
+ " This is often due to a Connection being returned after or during shutdown.", e);
}
}
}
/**
* Rollback the supplied connection.
- *
- * + * + *
* Logs any SQLException it gets trying to rollback, but will not propogate - * the exception lest it mask the exception that caused the caller to + * the exception lest it mask the exception that caused the caller to * need to rollback in the first place. *
* @@ -3666,36 +3665,36 @@ public abstract class JobStoreSupport implements JobStore, Constants { conn.rollback(); } catch (SQLException e) { getLog().error( - "Couldn't rollback jdbc connection. "+e.getMessage(), e); + "Couldn't rollback jdbc connection. " + e.getMessage(), e); } } } - + /** * Commit the supplied connection * * @param conn (Optional) * @throws JobPersistenceException thrown if a SQLException occurs when the - * connection is committed + * connection is committed */ protected void commitConnection(Connection conn) - throws JobPersistenceException { + throws JobPersistenceException { if (conn != null) { try { conn.commit(); } catch (SQLException e) { throw new JobPersistenceException( - "Couldn't commit jdbc connection. "+e.getMessage(), e); + "Couldn't commit jdbc connection. " + e.getMessage(), e); } } } - + /** * Implement this interface to provide the code to execute within * the a transaction template. If no return value is required, execute * should just return null. - * + * * @see JobStoreSupport#executeInNonManagedTXLock(String, TransactionCallback) * @see JobStoreSupport#executeInLock(String, TransactionCallback) * @see JobStoreSupport#executeWithoutLock(TransactionCallback) @@ -3707,11 +3706,11 @@ public abstract class JobStoreSupport implements JobStore, Constants { protected interface TransactionValidator* This method just forwards to executeInLock() with a null lockName. *
- * + * * @see #executeInLock(String, TransactionCallback) */ public