try { conn = DBConnectionManager.getInstance().getConnection( getDataSource()); } catch (SQLException sqle) { throw new JobPersistenceException( "Failed to obtain DB connection from data source '" + getDataSource() + "': " + sqle.toString(), sqle); } catch (Throwable e) { throw new JobPersistenceException( "Failed to obtain DB connection from data source '" + getDataSource() + "': " + e.toString(), e); throw new JobPersistenceException( "Could not get connection from DataSource '" + getDataSource() + "'"); conn = getAttributeRestoringConnection(conn); if (!isDontSetAutoCommitFalse()) { conn.setAutoCommit(false); if(isTxIsolationLevelSerializable()) { conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); getLog().warn("Failed to override connection auto commit/transaction isolation.", sqle); } catch (Throwable e) { try { conn.close(); } catch(Throwable ignored) {}
if(isThreadsInheritInitializersClassLoadContext()) { log.info("JDBCJobStore threads will inherit ContextClassLoader of thread: " + Thread.currentThread().getName()); initializersLoader = Thread.currentThread().getContextClassLoader(); if (getLockHandler() == null) { if (isClustered()) { setUseDBLocks(true); if (getUseDBLocks()) { 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); getLog().info("Using db table-based data access locking (synchronization)."); setLockHandler(new StdRowLockSemaphore(getTablePrefix(), getInstanceName(), getSelectWithLockSQL())); } else { getLog().info( "Using thread monitor-based data access locking (synchronization)."); setLockHandler(new SimpleSemaphore());
public List<OperableTrigger> execute(Connection conn) throws JobPersistenceException { return acquireNextTrigger(conn, noLaterThan, maxCount, timeWindow); } },
Connection conn = getNonManagedTXConnection(); try { failedRecords = clusterCheckIn(conn); commitConnection(conn); getLockHandler().obtainLock(conn, LOCK_STATE_ACCESS); transStateOwner = true; failedRecords = (firstCheckIn) ? clusterCheckIn(conn) : findFailedInstances(conn); getLockHandler().obtainLock(conn, LOCK_TRIGGER_ACCESS); clusterRecover(conn, failedRecords); recovered = true; commitConnection(conn); } catch (JobPersistenceException e) { rollbackConnection(conn); throw e; } finally { try { releaseLock(LOCK_TRIGGER_ACCESS, transOwner); } finally { try { releaseLock(LOCK_STATE_ACCESS, transStateOwner); } finally { cleanupConnection(conn);
protected RecoverMisfiredJobsResult doRecoverMisfires() throws JobPersistenceException { boolean transOwner = false; Connection conn = getNonManagedTXConnection(); try { RecoverMisfiredJobsResult result = RecoverMisfiredJobsResult.NO_OP; int misfireCount = (getDoubleCheckLockMisfireHandler()) ? getDelegate().countMisfiredTriggersInState( conn, STATE_WAITING, getMisfireTime()) : Integer.MAX_VALUE; getLog().debug( "Found 0 triggers that missed their scheduled fire-time."); } else { transOwner = getLockHandler().obtainLock(conn, LOCK_TRIGGER_ACCESS); result = recoverMisfiredJobs(conn, false); commitConnection(conn); return result; } catch (JobPersistenceException e) { rollbackConnection(conn); throw e; } catch (SQLException e) { rollbackConnection(conn); throw new JobPersistenceException("Database error recovering from misfires.", e); } catch (RuntimeException e) { rollbackConnection(conn); throw new JobPersistenceException("Unexpected runtime exception: " + e.getMessage(), e);
if(isThreadsInheritInitializersClassLoadContext()) { log.info("JDBCJobStore threads will inherit ContextClassLoader of thread: " + Thread.currentThread().getName()); initializersLoader = Thread.currentThread().getContextClassLoader(); if (getLockHandler() == null) { if (isClustered()) { setUseDBLocks(true); if (getUseDBLocks()) { getLog().info( "Using db table-based data access locking (synchronization)."); setLockHandler( new StdRowLockSemaphore(getTablePrefix(), getSelectWithLockSQL())); } else { getLog().info( "Using thread monitor-based data access locking (synchronization)."); setLockHandler(new SimpleSemaphore()); if (!isClustered()) { try { cleanVolatileTriggerAndJobs(); } catch (SchedulerException se) { throw new SchedulerConfigException(
if (getLockHandler().requiresConnection()) { conn = getNonManagedTXConnection(); transOwner = getLockHandler().obtainLock(conn, lockName); conn = getNonManagedTXConnection(); commitConnection(conn); } catch (JobPersistenceException e) { rollbackConnection(conn); if (txValidator == null || !retryExecuteInNonManagedTXLock(lockName, new TransactionCallback<Boolean>() { @Override public Boolean execute(Connection conn) throws JobPersistenceException { Long sigTime = clearAndGetSignalSchedulingChangeOnTxCompletion(); if(sigTime != null && sigTime >= 0) { signalSchedulingChangeImmediately(sigTime); rollbackConnection(conn); throw e; } catch (RuntimeException e) { rollbackConnection(conn); throw new JobPersistenceException("Unexpected runtime exception: " + e.getMessage(), e); } finally { try { releaseLock(lockName, transOwner); } finally { cleanupConnection(conn);
long timeNow = System.currentTimeMillis(); List<SchedulerStateRecord> states = getDelegate().selectSchedulerStateRecords(conn, null); if (rec.getSchedulerInstanceId().equals(getInstanceId())) { foundThisScheduler = true; if (firstCheckIn) { if (calcFailedIfAfter(rec) < timeNow) { failedInstances.add(rec); failedInstances.addAll(findOrphanedFailedInstances(conn, states)); getLog().warn( "This scheduler instance (" + getInstanceId() + ") is still " + "active but was recovered by another instance in the cluster. " + "This may cause inconsistent behavior.");
((JobStoreSupport)js).setInstanceId(schedInstId); ((JobStoreSupport)js).setInstanceName(schedName); PROP_TABLE_PREFIX, ((JobStoreSupport)js).getTablePrefix()); ((JobStoreSupport)js).setLockHandler(lockHandler); getLog().info("Using custom data access locking (synchronization): " + lockHandlerClass); } catch (Exception e) { schedInstId = DEFAULT_INSTANCE_ID; if (js instanceof JobStoreSupport) { if(((JobStoreSupport)js).isClustered()) { schedInstId = instanceIdGenerator.generateInstanceId(); jjs.setInstanceId(schedInstId); jjs.setDbRetryInterval(dbFailureRetry); if(threadsInheritInitalizersClassLoader) jjs.setThreadsInheritInitializersClassLoadContext(threadsInheritInitalizersClassLoader);
boolean forceState, boolean recovering) throws ObjectAlreadyExistsException, JobPersistenceException { if (newTrigger.isVolatile() && isClustered()) { getLog().info( "note: volatile triggers are effectively non-volatile in a clustered environment."); boolean existingTrigger = triggerExists(conn, newTrigger.getName(), newTrigger.getGroup()); shouldBepaused = getDelegate().isTriggerGroupPaused( conn, newTrigger.getGroup()); shouldBepaused = getDelegate().isTriggerGroupPaused(conn, ALL_GROUPS_PAUSED); getDelegate().insertPausedTriggerGroup(conn, newTrigger.getGroup()); job = getDelegate().selectJobDetail(conn, newTrigger.getJobName(), newTrigger.getJobGroup(), getClassLoadHelper()); state = checkBlockedState(conn, ctxt, job.getName(), job.getGroup(), state); getDelegate().updateSimpleTrigger(conn, (SimpleTrigger) newTrigger); } else if (newTrigger instanceof CronTrigger && ((CronTrigger)newTrigger).hasAdditionalProperties() == false ) { getDelegate().updateCronTrigger(conn, (CronTrigger) newTrigger);
if (getLockHandler().requiresConnection()) { conn = getNonManagedTXConnection(); transOwner = getLockHandler().obtainLock(conn, lockName); conn = getNonManagedTXConnection(); commitConnection(conn); return result; } catch (JobPersistenceException e) { rollbackConnection(conn); throw e; } catch (RuntimeException e) { rollbackConnection(conn); throw new JobPersistenceException("Unexpected runtime exception: " + e.getMessage(), e); } finally { try { releaseLock(conn, lockName, transOwner); } finally { cleanupConnection(conn);
throws JobPersistenceException { try { boolean existingCal = calendarExists(conn, calName); if (existingCal && !replaceExisting) { throw new ObjectAlreadyExistsException( if (getDelegate().updateCalendar(conn, calName, calendar) < 1) { throw new JobPersistenceException( "Couldn't store calendar. Update failed."); List<OperableTrigger> trigs = getDelegate().selectTriggersForCalendar(conn, calName); trigger.updateWithNewCalendar(calendar, getMisfireThreshold()); storeTrigger(conn, trigger, null, true, STATE_WAITING, false, false); if (getDelegate().insertCalendar(conn, calName, calendar) < 1) { throw new JobPersistenceException( "Couldn't store calendar. Insert failed.");
PROP_TABLE_PREFIX, ((JobStoreSupport)js).getTablePrefix()); tProps.setProperty( PROP_SCHED_NAME, schedName); ((JobStoreSupport)js).setLockHandler(lockHandler); getLog().info("Using custom data access locking (synchronization): " + lockHandlerClass); } catch (Exception e) { jjs.setDbRetryInterval(dbFailureRetry); if(threadsInheritInitalizersClassLoader) jjs.setThreadsInheritInitializersClassLoadContext(threadsInheritInitalizersClassLoader); jjs.setThreadExecutor(threadExecutor);
JobDetail newJob, boolean replaceExisting) throws ObjectAlreadyExistsException, JobPersistenceException { if (newJob.isVolatile() && isClustered()) { getLog().info( "note: volatile jobs are effectively non-volatile in a clustered environment."); boolean existingJob = jobExists(conn, newJob.getName(), newJob .getGroup()); try { throw new ObjectAlreadyExistsException(newJob); getDelegate().updateJobDetail(conn, newJob); } else { getDelegate().insertJobDetail(conn, newJob);
try { TriggerStatus status = getDelegate().selectTriggerStatus(conn, key); String newState = checkBlockedState(conn, status.getJobKey(), STATE_WAITING); misfired = updateMisfiredTrigger(conn, key, newState, true); getDelegate().updateTriggerStateFromOtherState(conn, key, newState, STATE_PAUSED_BLOCKED); } else { getDelegate().updateTriggerStateFromOtherState(conn, key, newState, STATE_PAUSED);
throws JobPersistenceException { boolean existingTrigger = triggerExists(conn, newTrigger.getKey()); shouldBepaused = getDelegate().isTriggerGroupPaused( conn, newTrigger.getKey().getGroup()); shouldBepaused = getDelegate().isTriggerGroupPaused(conn, ALL_GROUPS_PAUSED); getDelegate().insertPausedTriggerGroup(conn, newTrigger.getKey().getGroup()); job = retrieveJob(conn, newTrigger.getJobKey()); state = checkBlockedState(conn, job.getKey(), state); getDelegate().updateTrigger(conn, newTrigger, state, job); } else { getDelegate().insertTrigger(conn, newTrigger, state, job);
if (!js.isClustered()) { return false Connection conn = DBConnectionManager.getInstance().getConnection(js.getDataSource()); PreparedStatement stmt = null try { stmt = conn.prepareStatement("SELECT 1 FROM " + js.getTablePrefix() + "FIRED_TRIGGERS where JOB_NAME = ?") stmt.setString(1, job) ResultSet rs = stmt.executeQuery()
/** * <P> * Get the driver delegate for DB operations. * </p> */ protected DriverDelegate getDelegate() throws NoSuchDelegateException { synchronized(this) { if(null == delegate) { try { if(delegateClassName != null) { delegateClass = getClassLoadHelper().loadClass(delegateClassName, DriverDelegate.class); } delegate = delegateClass.newInstance(); delegate.initialize(getLog(), tablePrefix, instanceName, instanceId, getClassLoadHelper(), canUseProperties(), getDriverDelegateInitString()); } catch (InstantiationException e) { throw new NoSuchDelegateException("Couldn't create delegate: " + e.getMessage(), e); } catch (IllegalAccessException e) { throw new NoSuchDelegateException("Couldn't create delegate: " + e.getMessage(), e); } catch (ClassNotFoundException e) { throw new NoSuchDelegateException("Couldn't load delegate class: " + e.getMessage(), e); } } return delegate; } }
/** * @see org.quartz.spi.JobStore#schedulerStarted() */ public void schedulerStarted() throws SchedulerException { if (isClustered()) { clusterManagementThread = new ClusterManager(); if(initializersLoader != null) clusterManagementThread.setContextClassLoader(initializersLoader); clusterManagementThread.initialize(); } else { try { recoverJobs(); } catch (SchedulerException se) { throw new SchedulerConfigException( "Failure occured during job recovery.", se); } } misfireHandler = new MisfireHandler(); if(initializersLoader != null) misfireHandler.setContextClassLoader(initializersLoader); misfireHandler.initialize(); schedulerRunning = true; getLog().debug("JobStore background threads started (as scheduler was started)."); }
DBConnectionManager.getInstance().shutdown(getDataSource()); } catch (SQLException sqle) { getLog().warn("Database connection shutdown unsuccessful.", sqle); getLog().debug("JobStore background threads shutdown.");