org.quartz.JobPersistenceException Java Examples

The following examples show how to use org.quartz.JobPersistenceException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JobStoreSupport.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public boolean removeTriggers(final List<TriggerKey> triggerKeys)
        throws JobPersistenceException {
    return (Boolean) executeInLock(
            LOCK_TRIGGER_ACCESS,
            new TransactionCallback() {
                public Object execute(Connection conn) throws JobPersistenceException {
                    boolean allFound = true;

                    // FUTURE_TODO: make this more efficient with a true bulk operation...
                    for (TriggerKey triggerKey : triggerKeys)
                        allFound = removeTrigger(conn, triggerKey) && allFound;

                    return allFound ? Boolean.TRUE : Boolean.FALSE;
                }
            });
}
 
Example #2
Source File: JobStoreSupport.java    From AsuraFramework with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Resume (un-pause) all of the <code>{@link org.quartz.Job}s</code> in
 * the given group.
 * </p>
 * 
 * <p>
 * If any of the <code>Job</code> s had <code>Trigger</code> s that
 * missed one or more fire-times, then the <code>Trigger</code>'s
 * misfire instruction will be applied.
 * </p>
 * 
 * @see #pauseJobGroup(SchedulingContext, String)
 */
public void resumeJobGroup(final SchedulingContext ctxt, final String groupName)
    throws JobPersistenceException {
    executeInLock(
        LOCK_TRIGGER_ACCESS,
        new VoidTransactionCallback() {
            public void execute(Connection conn) throws JobPersistenceException {
                String[] jobNames = getJobNames(conn, ctxt, groupName);

                for (int i = 0; i < jobNames.length; i++) {
                    Trigger[] triggers = getTriggersForJob(conn, ctxt, jobNames[i], groupName);
                    for (int j = 0; j < triggers.length; j++) {
                        resumeTrigger(conn, ctxt, triggers[j].getName(), triggers[j].getGroup());
                    }
                }
            }
        });
}
 
Example #3
Source File: JobStoreSupport.java    From AsuraFramework with Apache License 2.0 6 votes vote down vote up
private void doUpdateOfMisfiredTrigger(Connection conn, SchedulingContext ctxt, Trigger trig, boolean forceState, String newStateIfNotComplete, boolean recovering) throws JobPersistenceException {
    Calendar cal = null;
    if (trig.getCalendarName() != null) {
        cal = retrieveCalendar(conn, ctxt, trig.getCalendarName());
    }

    schedSignaler.notifyTriggerListenersMisfired(trig);

    trig.updateAfterMisfire(cal);

    if (trig.getNextFireTime() == null) {
        storeTrigger(conn, ctxt, trig,
            null, true, STATE_COMPLETE, forceState, recovering);
    } else {
        storeTrigger(conn, ctxt, trig, null, true, newStateIfNotComplete,
                forceState, false);
    }
}
 
Example #4
Source File: JobStoreSupport.java    From AsuraFramework with Apache License 2.0 6 votes vote down vote up
protected Trigger retrieveTrigger(Connection conn, String triggerName, String groupName)
    throws JobPersistenceException {
    try {
        Trigger trigger = getDelegate().selectTrigger(conn, triggerName,
                groupName);
        if (trigger == null) {
            return null;
        }
        
        // In case Trigger was BLOB, clear out any listeners that might 
        // have been serialized.
        trigger.clearAllTriggerListeners();
        
        String[] listeners = getDelegate().selectTriggerListeners(conn,
                triggerName, groupName);
        for (int i = 0; i < listeners.length; ++i) {
            trigger.addTriggerListener(listeners[i]);
        }

        return trigger;
    } catch (Exception e) {
        throw new JobPersistenceException("Couldn't retrieve trigger: "
                + e.getMessage(), e);
    }
}
 
Example #5
Source File: DefaultClusteredJobStore.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>
 * Get the current state of the identified <code>{@link Trigger}</code>.
 * </p>
 * 
 * @see Trigger.TriggerState
 */
@Override
public Trigger.TriggerState getTriggerState(org.quartz.TriggerKey key) throws JobPersistenceException {

  TriggerWrapper tw;
  lock();
  try {
    tw = triggerFacade.get(key);
  } finally {
    unlock();
  }

  if (tw == null) { return Trigger.TriggerState.NONE; }

  if (tw.getState() == TriggerState.COMPLETE) { return Trigger.TriggerState.COMPLETE; }

  if (tw.getState() == TriggerState.PAUSED) { return Trigger.TriggerState.PAUSED; }

  if (tw.getState() == TriggerState.PAUSED_BLOCKED) { return Trigger.TriggerState.PAUSED; }

  if (tw.getState() == TriggerState.BLOCKED) { return Trigger.TriggerState.BLOCKED; }

  if (tw.getState() == TriggerState.ERROR) { return Trigger.TriggerState.ERROR; }

  return Trigger.TriggerState.NORMAL;
}
 
Example #6
Source File: JobStoreSupport.java    From AsuraFramework with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Pause all of the <code>{@link org.quartz.Trigger}s</code> in the
 * given group.
 * </p>
 * 
 * @see #resumeTriggerGroup(Connection, SchedulingContext, String)
 */
public void pauseTriggerGroup(Connection conn, SchedulingContext ctxt,
        String groupName) throws JobPersistenceException {

    try {

        getDelegate().updateTriggerGroupStateFromOtherStates(
                conn, groupName, STATE_PAUSED, STATE_ACQUIRED,
                STATE_WAITING, STATE_WAITING);

        getDelegate().updateTriggerGroupStateFromOtherState(
                conn, groupName, STATE_PAUSED_BLOCKED, STATE_BLOCKED);
        
        if (!getDelegate().isTriggerGroupPaused(conn, groupName)) {
            getDelegate().insertPausedTriggerGroup(conn, groupName);
        }

    } catch (SQLException e) {
        throw new JobPersistenceException("Couldn't pause trigger group '"
                + groupName + "': " + e.getMessage(), e);
    }
}
 
Example #7
Source File: QuartzSchedulerThread.java    From AsuraFramework with Apache License 2.0 6 votes vote down vote up
private boolean releaseIfScheduleChangedSignificantly(Trigger trigger, long triggerTime) {
    if(isCandidateNewTimeEarlierWithinReason(triggerTime, true)) {
        // above call does a clearSignaledSchedulingChange()
        try {
            qsRsrcs.getJobStore().releaseAcquiredTrigger(
                    ctxt, trigger);
        } catch (JobPersistenceException jpe) {
            qs.notifySchedulerListenersError(
                    "An error occured while releasing trigger '"
                            + trigger.getFullName() + "'",
                    jpe);
            // db connection must have failed... keep
            // retrying until it's up...
            releaseTriggerRetryLoop(trigger);
        } catch (RuntimeException e) {
            getLog().error(
                "releaseTriggerRetryLoop: RuntimeException "
                +e.getMessage(), e);
            // db connection must have failed... keep
            // retrying until it's up...
            releaseTriggerRetryLoop(trigger);
        }
        return true;
    }
    return false;
}
 
Example #8
Source File: JobStoreSupport.java    From AsuraFramework with Apache License 2.0 5 votes vote down vote up
protected String[] getTriggerNames(Connection conn, SchedulingContext ctxt,
        String groupName) throws JobPersistenceException {

    String[] trigNames = null;

    try {
        trigNames = getDelegate().selectTriggersInGroup(conn, groupName);
    } catch (SQLException e) {
        throw new JobPersistenceException("Couldn't obtain trigger names: "
                + e.getMessage(), e);
    }

    return trigNames;
}
 
Example #9
Source File: AbstractTerracottaJobStore.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void storeCalendar(String name, Calendar calendar, boolean replaceExisting, boolean updateTriggers)
    throws ObjectAlreadyExistsException, JobPersistenceException {
  try {
    realJobStore.storeCalendar(name, calendar, replaceExisting, updateTriggers);
  } catch (RejoinException e) {
    throw new JobPersistenceException("Storing calendar failed due to client rejoin", e);
  }
}
 
Example #10
Source File: JobStoreSupport.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected List<String> getJobGroupNames(Connection conn)
    throws JobPersistenceException {

    List<String> groupNames;

    try {
        groupNames = getDelegate().selectJobGroups(conn);
    } catch (SQLException e) {
        throw new JobPersistenceException("Couldn't obtain job groups: "
                + e.getMessage(), e);
    }

    return groupNames;
}
 
Example #11
Source File: JobStoreSupport.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public Set<String> getPausedTriggerGroups() 
    throws JobPersistenceException {
    return (Set<String>)executeWithoutLock( // no locks necessary for read...
        new TransactionCallback() {
            public Object execute(Connection conn) throws JobPersistenceException {
                return getPausedTriggerGroups(conn);
            }
        });
}
 
Example #12
Source File: JobStoreSupport.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Pause all of the <code>{@link org.quartz.Trigger}s</code> matching the
 * given groupMatcher.
 * </p>
 * 
 * @see #resumeTriggerGroup(java.sql.Connection, org.quartz.impl.matchers.GroupMatcher)
 */
public Set<String> pauseTriggerGroup(Connection conn,
        GroupMatcher<TriggerKey> matcher) throws JobPersistenceException {

    try {

        getDelegate().updateTriggerGroupStateFromOtherStates(
                conn, matcher, STATE_PAUSED, STATE_ACQUIRED,
                STATE_WAITING, STATE_WAITING);

        getDelegate().updateTriggerGroupStateFromOtherState(
                conn, matcher, STATE_PAUSED_BLOCKED, STATE_BLOCKED);

        List<String> groups = getDelegate().selectTriggerGroups(conn, matcher);
        
        // make sure to account for an exact group match for a group that doesn't yet exist
        StringMatcher.StringOperatorName operator = matcher.getCompareWithOperator();
        if (operator.equals(StringOperatorName.EQUALS) && !groups.contains(matcher.getCompareToValue())) {
          groups.add(matcher.getCompareToValue());
        }

        for (String group : groups) {
            if (!getDelegate().isTriggerGroupPaused(conn, group)) {
                getDelegate().insertPausedTriggerGroup(conn, group);
            }
        }

        return new HashSet<String>(groups);

    } catch (SQLException e) {
        throw new JobPersistenceException("Couldn't pause trigger group '"
                + matcher + "': " + e.getMessage(), e);
    }
}
 
Example #13
Source File: AbstractTerracottaJobStore.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean removeJobs(List<JobKey> arg0) throws JobPersistenceException {
  try {
    return realJobStore.removeJobs(arg0);
  } catch (RejoinException e) {
    throw new JobPersistenceException("Removing jobs failed due to client rejoin", e);
  }
}
 
Example #14
Source File: AbstractTerracottaJobStore.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean removeTrigger(TriggerKey triggerKey) throws JobPersistenceException {
  try {
    return realJobStore.removeTrigger(triggerKey);
  } catch (RejoinException e) {
    throw new JobPersistenceException("Removing trigger failed due to client rejoin", e);
  }
}
 
Example #15
Source File: JobStoreSupport.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Retrieve the given <code>{@link org.quartz.Trigger}</code>.
 * </p>
 * 
 * @return The desired <code>Trigger</code>, or null if there is no
 *         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);
            }
        });
}
 
Example #16
Source File: JobStoreSupport.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected void clearAllSchedulingData(Connection conn) throws JobPersistenceException {
    try {
        getDelegate().clearData(conn);
    } catch (SQLException e) {
        throw new JobPersistenceException("Error clearing scheduling data: " + e.getMessage(), e);
    }
}
 
Example #17
Source File: DefaultClusteredJobStore.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see org.quartz.spi.JobStore#getPausedTriggerGroups()
 */
@Override
public Set<String> getPausedTriggerGroups() throws JobPersistenceException {
  lock();
  try {
    return new HashSet<String>(triggerFacade.allPausedTriggersGroupNames());
  } finally {
    unlock();
  }
}
 
Example #18
Source File: JobStoreSupport.java    From AsuraFramework with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Pause the <code>{@link org.quartz.Job}</code> with the given name - by
 * pausing all of its current <code>Trigger</code>s.
 * </p>
 * 
 * @see #resumeJob(SchedulingContext, String, String)
 */
public void pauseJob(final SchedulingContext ctxt, final String jobName,
        final String groupName) throws JobPersistenceException {
    executeInLock(
        LOCK_TRIGGER_ACCESS,
        new VoidTransactionCallback() {
            public void execute(Connection conn) throws JobPersistenceException {
                Trigger[] triggers = getTriggersForJob(conn, ctxt, jobName, groupName);
                for (int j = 0; j < triggers.length; j++) {
                    pauseTrigger(conn, ctxt, triggers[j].getName(), triggers[j].getGroup());
                }
            }
        });
}
 
Example #19
Source File: JobStoreSupport.java    From AsuraFramework with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Removes all volatile data.
 * </p>
 * 
 * @throws JobPersistenceException
 *           if jobs could not be recovered
 */
protected void cleanVolatileTriggerAndJobs(Connection conn)
    throws JobPersistenceException {
    try {
        // find volatile jobs & triggers...
        Key[] volatileTriggers = getDelegate().selectVolatileTriggers(conn);
        Key[] volatileJobs = getDelegate().selectVolatileJobs(conn);

        for (int i = 0; i < volatileTriggers.length; i++) {
            removeTrigger(conn, null, volatileTriggers[i].getName(),
                    volatileTriggers[i].getGroup());
        }
        getLog().info(
                "Removed " + volatileTriggers.length
                        + " Volatile Trigger(s).");

        for (int i = 0; i < volatileJobs.length; i++) {
            removeJob(conn, null, volatileJobs[i].getName(),
                    volatileJobs[i].getGroup(), true);
        }
        getLog().info(
                "Removed " + volatileJobs.length + " Volatile Job(s).");

        // clean up any fired trigger entries
        getDelegate().deleteVolatileFiredTriggers(conn);

    } catch (Exception e) {
        throw new JobPersistenceException("Couldn't clean volatile data: "
                + e.getMessage(), e);
    }
}
 
Example #20
Source File: AbstractTerracottaJobStore.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<String> getCalendarNames() throws JobPersistenceException {
  try {
    return realJobStore.getCalendarNames();
  } catch (RejoinException e) {
    throw new JobPersistenceException("Calendar name retrieval failed due to client rejoin", e);
  }
}
 
Example #21
Source File: DefaultClusteredJobStore.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Retrieve the given <code>{@link org.quartz.Trigger}</code>.
 * </p>
 * 
 * @param triggerKey The key of the <code>Trigger</code> to be retrieved.
 * @return The desired <code>Trigger</code>, or null if there is no match.
 */
@Override
public OperableTrigger retrieveTrigger(TriggerKey triggerKey) throws JobPersistenceException {
  lock();
  try {
    TriggerWrapper tw = triggerFacade.get(triggerKey);
    return (tw != null) ? (OperableTrigger) tw.getTriggerClone() : null;
  } finally {
    unlock();
  }
}
 
Example #22
Source File: DefaultClusteredJobStore.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Get the number of <code>{@link org.quartz.JobDetail}</code> s that are stored in the <code>JobsStore</code>.
 * </p>
 */
@Override
public int getNumberOfJobs() throws JobPersistenceException {
  lock();
  try {
    return jobFacade.numberOfJobs();
  } finally {
    unlock();
  }
}
 
Example #23
Source File: DefaultClusteredJobStore.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Get the names of all of the <code>{@link org.quartz.Calendar}</code> s in the <code>JobStore</code>.
 * </p>
 * <p>
 * If there are no Calendars in the given group name, the result should be a zero-length array (not <code>null</code>
 * ).
 * </p>
 */
@Override
public List<String> getCalendarNames() throws JobPersistenceException {
  lock();
  try {
    Set<String> names = calendarsByName.keySet();
    return new ArrayList<String>(names);
  } finally {
    unlock();
  }
}
 
Example #24
Source File: JobStoreSupport.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected boolean checkExists(Connection conn, TriggerKey triggerKey) throws JobPersistenceException {
    try {
        return getDelegate().triggerExists(conn, triggerKey);
    } catch (SQLException e) {
        throw new JobPersistenceException("Couldn't check for existence of job: "
                + e.getMessage(), e);
    }
}
 
Example #25
Source File: JobStoreSupport.java    From AsuraFramework with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Get all of the Triggers that are associated to the given Job.
 * </p>
 * 
 * <p>
 * If there are no matches, a zero-length array should be returned.
 * </p>
 */
public Trigger[] getTriggersForJob(final SchedulingContext ctxt, final String jobName,
    final String groupName) throws JobPersistenceException {
    return (Trigger[])executeWithoutLock( // no locks necessary for read...
        new TransactionCallback() {
            public Object execute(Connection conn) throws JobPersistenceException {
                return getTriggersForJob(conn, ctxt, jobName, groupName);
            }
        });
}
 
Example #26
Source File: DefaultClusteredJobStore.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Pause the <code>{@link Trigger}</code> with the given name.
 * </p>
 */
@Override
public void pauseTrigger(TriggerKey triggerKey) throws JobPersistenceException {
  lock();
  try {
    TriggerWrapper tw = triggerFacade.get(triggerKey);

    // does the trigger exist?
    if (tw == null) { return; }

    // if the trigger is "complete" pausing it does not make sense...
    if (tw.getState() == TriggerState.COMPLETE) { return; }

    if (tw.getState() == TriggerState.BLOCKED) {
      tw.setState(TriggerState.PAUSED_BLOCKED, terracottaClientId, triggerFacade);
    } else {
      tw.setState(TriggerState.PAUSED, terracottaClientId, triggerFacade);
    }

    timeTriggers.remove(tw);
    if (triggerRemovedFromCandidateFiringListHandler != null) {
      triggerRemovedFromCandidateFiringListHandler.removeCandidateTrigger(tw);
    }
  } finally {
    unlock();
  }
}
 
Example #27
Source File: DefaultClusteredJobStore.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
boolean applyMisfire(TriggerWrapper tw) throws JobPersistenceException {
  long misfireTime = System.currentTimeMillis();
  if (getMisfireThreshold() > 0) {
    misfireTime -= getMisfireThreshold();
  }

  Date tnft = tw.getNextFireTime();
  if (tnft == null || tnft.getTime() > misfireTime
      || tw.getMisfireInstruction() == Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY) { return false; }

  Calendar cal = null;
  if (tw.getCalendarName() != null) {
    cal = retrieveCalendar(tw.getCalendarName());
  }

  signaler.notifyTriggerListenersMisfired(tw.getTriggerClone());

  tw.updateAfterMisfire(cal, triggerFacade);

  if (tw.getNextFireTime() == null) {
    tw.setState(TriggerState.COMPLETE, terracottaClientId, triggerFacade);
    signaler.notifySchedulerListenersFinalized(tw.getTriggerClone());
    timeTriggers.remove(tw);
  } else if (tnft.equals(tw.getNextFireTime())) { return false; }

  return true;
}
 
Example #28
Source File: StdJDBCDelegate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Select the triggers for a job
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @return an array of <code>(@link org.quartz.Trigger)</code> objects
 *         associated with a given job.
 * @throws SQLException
 * @throws JobPersistenceException 
 */
public List<OperableTrigger> selectTriggersForJob(Connection conn, JobKey jobKey) throws SQLException, ClassNotFoundException,
        IOException, JobPersistenceException {

    LinkedList<OperableTrigger> trigList = new LinkedList<OperableTrigger>();
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        ps = conn.prepareStatement(rtp(SELECT_TRIGGERS_FOR_JOB));
        ps.setString(1, jobKey.getName());
        ps.setString(2, jobKey.getGroup());
        rs = ps.executeQuery();

        while (rs.next()) {
            OperableTrigger t = selectTrigger(conn, triggerKey(rs.getString(COL_TRIGGER_NAME), rs.getString(COL_TRIGGER_GROUP)));
            if(t != null) {
                trigList.add(t);
            }
        }
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
    }

    return trigList;
}
 
Example #29
Source File: JobStoreSupport.java    From AsuraFramework with Apache License 2.0 5 votes vote down vote up
protected int getNumberOfTriggers(Connection conn, SchedulingContext ctxt)
    throws JobPersistenceException {
    try {
        return getDelegate().selectNumTriggers(conn);
    } catch (SQLException e) {
        throw new JobPersistenceException(
                "Couldn't obtain number of triggers: " + e.getMessage(), e);
    }
}
 
Example #30
Source File: JobStoreSupport.java    From AsuraFramework with Apache License 2.0 5 votes vote down vote up
/**
 * Commit the supplied connection
 *
 * @param conn (Optional)
 * @throws JobPersistenceException thrown if a SQLException occurs when the
 * connection is committed
 */
protected void commitConnection(Connection conn)
    throws JobPersistenceException {

    if (conn != null) {
        try {
            conn.commit();
        } catch (SQLException e) {
            throw new JobPersistenceException(
                "Couldn't commit jdbc connection. "+e.getMessage(), e);
        }
    }
}