Java 类org.quartz.Calendar 实例源码

项目:asura    文件:JobStoreSupport.java   
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);
    }
}
项目:asura    文件:StdJDBCDelegate.java   
/**
 * <p>
 * Update a calendar.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @param calendarName
 *          the name for the new calendar
 * @param calendar
 *          the calendar
 * @return the number of rows updated
 * @throws IOException
 *           if there were problems serializing the calendar
 */
public int updateCalendar(Connection conn, String calendarName,
        Calendar calendar) throws IOException, SQLException {
    ByteArrayOutputStream baos = serializeObject(calendar);

    PreparedStatement ps = null;

    try {
        ps = conn.prepareStatement(rtp(UPDATE_CALENDAR));
        setBytes(ps, 1, baos);
        ps.setString(2, calendarName);

        return ps.executeUpdate();
    } finally {
        closeStatement(ps);
    }
}
项目:lams    文件:DefaultClusteredJobStore.java   
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;
}
项目:asura    文件:PointbaseDelegate.java   
/**
 * <p>
 * Insert a new calendar.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @param calendarName
 *          the name for the new calendar
 * @param calendar
 *          the calendar
 * @return the number of rows inserted
 * @throws IOException
 *           if there were problems serializing the calendar
 */
public int insertCalendar(Connection conn, String calendarName,
        Calendar calendar) throws IOException, SQLException {
    //log.debug( "Inserting Calendar " + calendarName + " : " + calendar
    // );
    ByteArrayOutputStream baos = serializeObject(calendar);
    byte buf[] = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(buf);

    PreparedStatement ps = null;

    try {
        ps = conn.prepareStatement(rtp(INSERT_CALENDAR));
        ps.setString(1, calendarName);
        ps.setBinaryStream(2, bais, buf.length);

        return ps.executeUpdate();
    } finally {
        closeStatement(ps);
    }
}
项目:lams    文件:AnnualCalendar.java   
/**
 * <p>
 * Redefine a certain day to be excluded (true) or included (false).
 * </p>
 */
public void setDayExcluded(java.util.Calendar day, boolean exclude) {
    if (exclude) {
        if (isDayExcluded(day)) {
            return;
        }

        excludeDays.add(day);
        dataSorted = false;
    } else {
        if (!isDayExcluded(day)) {
            return;
        }

        removeExcludedDay(day, true);
    }
}
项目:lams    文件:AnnualCalendar.java   
public int compare(java.util.Calendar c1, java.util.Calendar c2) {

  int month1 = c1.get(java.util.Calendar.MONTH);
  int month2 = c2.get(java.util.Calendar.MONTH);

  int day1 = c1.get(java.util.Calendar.DAY_OF_MONTH);
  int day2 = c2.get(java.util.Calendar.DAY_OF_MONTH);

  if (month1 < month2) {
      return -1;
  }
  if (month1 > month2) {
      return 1; 
  }
  if (day1 < day2) {
      return -1;
  }
  if (day1 > day2) {
      return 1;
  }
  return 0;
}
项目:lams    文件:WeeklyCalendar.java   
/**
 * <p>
 * Determine whether the given time (in milliseconds) is 'included' by the
 * Calendar.
 * </p>
 *
 * <p>
 * Note that this Calendar is only has full-day precision.
 * </p>
 */
@Override
public boolean isTimeIncluded(long timeStamp) {
    if (excludeAll == true) {
        return false;
    }

    // Test the base calendar first. Only if the base calendar not already
    // excludes the time/date, continue evaluating this calendar instance.
    if (super.isTimeIncluded(timeStamp) == false) { return false; }

    java.util.Calendar cl = createJavaCalendar(timeStamp);
    int wday = cl.get(java.util.Calendar.DAY_OF_WEEK);

    return !(isDayExcluded(wday));
}
项目:lams    文件:HolidayCalendar.java   
/**
 * <p>
 * Determine the next time (in milliseconds) that is 'included' by the
 * Calendar after the given time.
 * </p>
 * 
 * <p>
 * Note that this Calendar is only has full-day precision.
 * </p>
 */
@Override
public long getNextIncludedTime(long timeStamp) {

    // Call base calendar implementation first
    long baseTime = super.getNextIncludedTime(timeStamp);
    if ((baseTime > 0) && (baseTime > timeStamp)) {
        timeStamp = baseTime;
    }

    // Get timestamp for 00:00:00
    java.util.Calendar day = getStartOfDayJavaCalendar(timeStamp);
    while (isTimeIncluded(day.getTime().getTime()) == false) {
        day.add(java.util.Calendar.DATE, 1);
    }

    return day.getTime().getTime();
}
项目:asura    文件:AnnualCalendar.java   
/**
 * <p>
 * Redefine a certain day to be excluded (true) or included (false).
 * </p>
 */
public void setDayExcluded(java.util.Calendar day, boolean exclude) {
    if (exclude) {
        if (isDayExcluded(day)) {
            return;
        }

        excludeDays.add(day);
        dataSorted = false;
    } else {
        if (!isDayExcluded(day)) {
            return;
        }

        removeExcludedDay(day, true);
    }
}
项目:lams    文件:PointbaseDelegate.java   
/**
 * <p>
 * Insert a new calendar.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @param calendarName
 *          the name for the new calendar
 * @param calendar
 *          the calendar
 * @return the number of rows inserted
 * @throws IOException
 *           if there were problems serializing the calendar
 */
@Override           
public int insertCalendar(Connection conn, String calendarName,
        Calendar calendar) throws IOException, SQLException {
    //log.debug( "Inserting Calendar " + calendarName + " : " + calendar
    // );
    ByteArrayOutputStream baos = serializeObject(calendar);
    byte buf[] = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(buf);

    PreparedStatement ps = null;

    try {
        ps = conn.prepareStatement(rtp(INSERT_CALENDAR));
        ps.setString(1, calendarName);
        ps.setBinaryStream(2, bais, buf.length);

        return ps.executeUpdate();
    } finally {
        closeStatement(ps);
    }
}
项目:lams    文件:PointbaseDelegate.java   
/**
 * <p>
 * Update a calendar.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @param calendarName
 *          the name for the new calendar
 * @param calendar
 *          the calendar
 * @return the number of rows updated
 * @throws IOException
 *           if there were problems serializing the calendar
 */
@Override           
public int updateCalendar(Connection conn, String calendarName,
        Calendar calendar) throws IOException, SQLException {
    //log.debug( "Updating calendar " + calendarName + " : " + calendar );
    ByteArrayOutputStream baos = serializeObject(calendar);
    byte buf[] = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(buf);

    PreparedStatement ps = null;

    try {
        ps = conn.prepareStatement(rtp(UPDATE_CALENDAR));
        ps.setBinaryStream(1, bais, buf.length);
        ps.setString(2, calendarName);

        return ps.executeUpdate();
    } finally {
        closeStatement(ps);
    }
}
项目:lams    文件:StdJDBCDelegate.java   
/**
 * <p>
 * Update a calendar.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @param calendarName
 *          the name for the new calendar
 * @param calendar
 *          the calendar
 * @return the number of rows updated
 * @throws IOException
 *           if there were problems serializing the calendar
 */
public int updateCalendar(Connection conn, String calendarName,
        Calendar calendar) throws IOException, SQLException {
    ByteArrayOutputStream baos = serializeObject(calendar);

    PreparedStatement ps = null;

    try {
        ps = conn.prepareStatement(rtp(UPDATE_CALENDAR));
        setBytes(ps, 1, baos);
        ps.setString(2, calendarName);

        return ps.executeUpdate();
    } finally {
        closeStatement(ps);
    }
}
项目:lams    文件:SimpleTriggerImpl.java   
/**
 * <p>
 * Called when the <code>{@link Scheduler}</code> has decided to 'fire'
 * the trigger (execute the associated <code>Job</code>), in order to
 * give the <code>Trigger</code> a chance to update itself for its next
 * triggering (if any).
 * </p>
 * 
 * @see #executionComplete(JobExecutionContext, JobExecutionException)
 */
@Override
public void triggered(Calendar calendar) {
    timesTriggered++;
    previousFireTime = nextFireTime;
    nextFireTime = getFireTimeAfter(nextFireTime);

    while (nextFireTime != null && calendar != null
            && !calendar.isTimeIncluded(nextFireTime.getTime())) {

        nextFireTime = getFireTimeAfter(nextFireTime);

        if(nextFireTime == null)
            break;

        //avoid infinite loop
        java.util.Calendar c = java.util.Calendar.getInstance();
        c.setTime(nextFireTime);
        if (c.get(java.util.Calendar.YEAR) > YEAR_TO_GIVEUP_SCHEDULING_AT) {
            nextFireTime = null;
        }
    }
}
项目:lams    文件:SimpleTriggerImpl.java   
/**
 * <p>
 * Called by the scheduler at the time a <code>Trigger</code> is first
 * added to the scheduler, in order to have the <code>Trigger</code>
 * compute its first fire time, based on any associated calendar.
 * </p>
 * 
 * <p>
 * After this method has been called, <code>getNextFireTime()</code>
 * should return a valid answer.
 * </p>
 * 
 * @return the first time at which the <code>Trigger</code> will be fired
 *         by the scheduler, which is also the same value <code>getNextFireTime()</code>
 *         will return (until after the first firing of the <code>Trigger</code>).
 *         </p>
 */
@Override
public Date computeFirstFireTime(Calendar calendar) {
    nextFireTime = getStartTime();

    while (nextFireTime != null && calendar != null
            && !calendar.isTimeIncluded(nextFireTime.getTime())) {
        nextFireTime = getFireTimeAfter(nextFireTime);

        if(nextFireTime == null)
            break;

        //avoid infinite loop
        java.util.Calendar c = java.util.Calendar.getInstance();
        c.setTime(nextFireTime);
        if (c.get(java.util.Calendar.YEAR) > YEAR_TO_GIVEUP_SCHEDULING_AT) {
            return null;
        }
    }

    return nextFireTime;
}
项目:lams    文件:QuartzScheduler.java   
/**
 * <p>
 * Schedule the given <code>{@link org.quartz.Trigger}</code> with the
 * <code>Job</code> identified by the <code>Trigger</code>'s settings.
 * </p>
 * 
 * @throws SchedulerException
 *           if the indicated Job does not exist, or the Trigger cannot be
 *           added to the Scheduler, or there is an internal Scheduler
 *           error.
 */
public Date scheduleJob(Trigger trigger)
    throws SchedulerException {
    validateState();

    if (trigger == null) {
        throw new SchedulerException("Trigger cannot be null");
    }

    OperableTrigger trig = (OperableTrigger)trigger;

    trig.validate();

    Calendar cal = null;
    if (trigger.getCalendarName() != null) {
        cal = resources.getJobStore().retrieveCalendar(trigger.getCalendarName());
        if(cal == null) {
            throw new SchedulerException(
                "Calendar not found: " + trigger.getCalendarName());
        }
    }
    Date ft = trig.computeFirstFireTime(cal);

    if (ft == null) {
        throw new SchedulerException(
                "Based on configured schedule, the given trigger '" + trigger.getKey() + "' will never fire.");
    }

    resources.getJobStore().storeTrigger(trig, false);
    notifySchedulerThread(trigger.getNextFireTime().getTime());
    notifySchedulerListenersSchduled(trigger);

    return ft;
}
项目:asura    文件:PointbaseDelegate.java   
/**
 * <p>
 * Update a calendar.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @param calendarName
 *          the name for the new calendar
 * @param calendar
 *          the calendar
 * @return the number of rows updated
 * @throws IOException
 *           if there were problems serializing the calendar
 */
public int updateCalendar(Connection conn, String calendarName,
        Calendar calendar) throws IOException, SQLException {
    //log.debug( "Updating calendar " + calendarName + " : " + calendar );
    ByteArrayOutputStream baos = serializeObject(calendar);
    byte buf[] = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(buf);

    PreparedStatement ps = null;

    try {
        ps = conn.prepareStatement(rtp(UPDATE_CALENDAR));
        ps.setBinaryStream(1, bais, buf.length);
        ps.setString(2, calendarName);

        return ps.executeUpdate();
    } finally {
        closeStatement(ps);
    }
}
项目:lams    文件:AbstractTerracottaJobStore.java   
@Override
public Calendar retrieveCalendar(String calName) throws JobPersistenceException {
  try {
    return realJobStore.retrieveCalendar(calName);
  } catch (RejoinException e) {
    throw new JobPersistenceException("Calendar retrieval failed due to client rejoin", e);
  }
}
项目:uflo    文件:SchedulerServiceImpl.java   
public void addReminderJob(TaskReminder reminder,ProcessInstance processInstance,Task task) {
    try {
        AbstractTrigger<? extends Trigger> trigger=null;
        if(reminder.getType().equals(ReminderType.Once)){
            SimpleTriggerImpl simpleTrigger=new SimpleTriggerImpl();
            simpleTrigger.setRepeatCount(0);
            trigger=simpleTrigger;
            long executeTime=reminder.getStartDate().getTime()+10000;
            long now=(new Date()).getTime();
            if(executeTime<=now){
                return;
            }
        }else{
            CronTriggerImpl cronTrigger=new CronTriggerImpl();
            cronTrigger.setCronExpression(reminder.getCron());
            trigger=cronTrigger;
        }
        trigger.setName("trigger_"+reminder.getId());
        trigger.setStartTime(reminder.getStartDate());
        ReminderJobDetail jobDetail=new ReminderJobDetail();
        jobDetail.setJobClass(ReminderJob.class);
        ReminderHandler handler=(ReminderHandler)applicationContext.getBean(reminder.getReminderHandlerBean());
        jobDetail.setReminderHandlerBean(handler);
        if(task==null){
            task=taskService.getTask(reminder.getTaskId());             
        }
        jobDetail.setTask(task);
        jobDetail.setProcessInstance(processService.getProcessInstanceById(task.getProcessInstanceId()));
        jobDetail.setKey(new JobKey(JOB_NAME_PREFIX+reminder.getId(),JOB_GROUP_PREFIX));
        Calendar calendar=getCalendar(reminder,processInstance,task);
        if(calendar!=null){
            String calendarName=REMINDER_CALENDAR_PREFIX+reminder.getId();
            scheduler.addCalendar(calendarName, calendar,false, false);
            trigger.setCalendarName(calendarName);
        }
        scheduler.scheduleJob(jobDetail, trigger);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }   
}
项目:lams    文件:AnnualCalendar.java   
/**
 * <p>
 * Determine whether the given time (in milliseconds) is 'included' by the
 * Calendar.
 * </p>
 * 
 * <p>
 * Note that this Calendar is only has full-day precision.
 * </p>
 */
@Override
public boolean isTimeIncluded(long timeStamp) {
    // Test the base calendar first. Only if the base calendar not already
    // excludes the time/date, continue evaluating this calendar instance.
    if (super.isTimeIncluded(timeStamp) == false) { return false; }

    java.util.Calendar day = createJavaCalendar(timeStamp);

    return !(isDayExcluded(day));
}
项目:asura    文件:RemoteScheduler.java   
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>,
 * passing the <code>SchedulingContext</code> associated with this
 * instance.
 * </p>
 */
public Calendar getCalendar(String calName) throws SchedulerException {
    try {
        return getRemoteScheduler().getCalendar(schedCtxt, calName);
    } catch (RemoteException re) {
        throw invalidateHandleCreateException(
                "Error communicating with remote scheduler.", re);
    }
}
项目:lams    文件:MonthlyCalendar.java   
/**
 * <p>
 * Determine the next time (in milliseconds) that is 'included' by the
 * Calendar after the given time. Return the original value if timeStamp is
 * included. Return 0 if all days are excluded.
 * </p>
 *
 * <p>
 * Note that this Calendar is only has full-day precision.
 * </p>
 */
@Override
public long getNextIncludedTime(long timeStamp) {
    if (excludeAll == true) {
        return 0;
    }

    // Call base calendar implementation first
    long baseTime = super.getNextIncludedTime(timeStamp);
    if ((baseTime > 0) && (baseTime > timeStamp)) {
        timeStamp = baseTime;
    }

    // Get timestamp for 00:00:00
    java.util.Calendar cl = getStartOfDayJavaCalendar(timeStamp);
    int day = cl.get(java.util.Calendar.DAY_OF_MONTH);

    if (!isDayExcluded(day)) {
        return timeStamp; // return the original value
    }

    while (isDayExcluded(day) == true) {
        cl.add(java.util.Calendar.DATE, 1);
        day = cl.get(java.util.Calendar.DAY_OF_MONTH);
    }

    return cl.getTime().getTime();
}
项目:lams    文件:BaseCalendar.java   
/**
 * Build a <code>{@link java.util.Calendar}</code> with the current time.
 * The new Calendar will use the <code>BaseCalendar</code> time zone if
 * it is not <code>null</code>.
 */
protected java.util.Calendar createJavaCalendar() {
    return
        (getTimeZone() == null) ?
            java.util.Calendar.getInstance() :
            java.util.Calendar.getInstance(getTimeZone());
}
项目:lams    文件:WeeklyCalendar.java   
public WeeklyCalendar(Calendar baseCalendar, TimeZone timeZone) {
    super(baseCalendar, timeZone);

    excludeDays[java.util.Calendar.SUNDAY] = true;
    excludeDays[java.util.Calendar.SATURDAY] = true;
    excludeAll = areAllDaysExcluded();
}
项目:lams    文件:WeeklyCalendar.java   
/**
 * <p>
 * Check if all week days are excluded. That is no day is included.
 * </p>
 *
 * @return boolean
 */
public boolean areAllDaysExcluded() {
    return
        isDayExcluded(java.util.Calendar.SUNDAY) &&
        isDayExcluded(java.util.Calendar.MONDAY) &&
        isDayExcluded(java.util.Calendar.TUESDAY) &&
        isDayExcluded(java.util.Calendar.WEDNESDAY) &&
        isDayExcluded(java.util.Calendar.THURSDAY) &&
        isDayExcluded(java.util.Calendar.FRIDAY) &&
        isDayExcluded(java.util.Calendar.SATURDAY);
}
项目:lams    文件:WeeklyCalendar.java   
/**
 * <p>
 * Determine the next time (in milliseconds) that is 'included' by the
 * Calendar after the given time. Return the original value if timeStamp is
 * included. Return 0 if all days are excluded.
 * </p>
 *
 * <p>
 * Note that this Calendar is only has full-day precision.
 * </p>
 */
@Override
public long getNextIncludedTime(long timeStamp) {
    if (excludeAll == true) {
        return 0;
    }

    // Call base calendar implementation first
    long baseTime = super.getNextIncludedTime(timeStamp);
    if ((baseTime > 0) && (baseTime > timeStamp)) {
        timeStamp = baseTime;
    }

    // Get timestamp for 00:00:00
    java.util.Calendar cl = getStartOfDayJavaCalendar(timeStamp);
    int wday = cl.get(java.util.Calendar.DAY_OF_WEEK);

    if (!isDayExcluded(wday)) {
        return timeStamp; // return the original value
    }

    while (isDayExcluded(wday) == true) {
        cl.add(java.util.Calendar.DATE, 1);
        wday = cl.get(java.util.Calendar.DAY_OF_WEEK);
    }

    return cl.getTime().getTime();
}
项目:asura    文件:BaseCalendar.java   
/**
 * Build a <code>{@link java.util.Calendar}</code> with the current time.
 * The new Calendar will use the <code>BaseCalendar</code> time zone if
 * it is not <code>null</code>.
 */
protected java.util.Calendar createJavaCalendar() {
    return
        (getTimeZone() == null) ?
            java.util.Calendar.getInstance() :
            java.util.Calendar.getInstance(getTimeZone());
}
项目:lams    文件:RemoteMBeanScheduler.java   
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>,
 * passing the <code>SchedulingContext</code> associated with this
 * instance.
 * </p>
 */
public void addCalendar(String calName, Calendar calendar, boolean replace, boolean updateTriggers)
    throws SchedulerException {
    invoke(
        "addCalendar", 
        new Object[] { calName, calendar, replace, updateTriggers },
        new String[] { String.class.getName(), 
                Calendar.class.getName(), boolean.class.getName(), boolean.class.getName() });
}
项目:asura    文件:WeeklyCalendar.java   
/**
 * <p>
 * Check if all week days are excluded. That is no day is included.
 * </p>
 *
 * @return boolean
 */
public boolean areAllDaysExcluded() {
    return
        isDayExcluded(java.util.Calendar.SUNDAY) &&
        isDayExcluded(java.util.Calendar.MONDAY) &&
        isDayExcluded(java.util.Calendar.TUESDAY) &&
        isDayExcluded(java.util.Calendar.WEDNESDAY) &&
        isDayExcluded(java.util.Calendar.THURSDAY) &&
        isDayExcluded(java.util.Calendar.FRIDAY) &&
        isDayExcluded(java.util.Calendar.SATURDAY);
}
项目:lams    文件:OracleDelegate.java   
@Override
public int insertCalendar(Connection conn, String calendarName,
        Calendar calendar) throws IOException, SQLException {
    ByteArrayOutputStream baos = serializeObject(calendar);

    PreparedStatement ps = null;
    PreparedStatement ps2 = null;
    ResultSet rs = null;

    try {
        ps = conn.prepareStatement(rtp(INSERT_ORACLE_CALENDAR));
        ps.setString(1, calendarName);

        ps.executeUpdate();
        ps.close();

        ps = conn.prepareStatement(rtp(SELECT_ORACLE_CALENDAR_BLOB));
        ps.setString(1, calendarName);

        rs = ps.executeQuery();

        if (rs.next()) {
            Blob dbBlob = writeDataToBlob(rs, 1, baos.toByteArray());
            ps2 = conn.prepareStatement(rtp(UPDATE_ORACLE_CALENDAR_BLOB));

            ps2.setBlob(1, dbBlob);
            ps2.setString(2, calendarName);

            return ps2.executeUpdate();
        }

        return 0;

    } finally {
        closeResultSet(rs);
        closeStatement(ps);
        closeStatement(ps2);
    }
}
项目:lams    文件:OracleDelegate.java   
@Override
public int updateCalendar(Connection conn, String calendarName,
        Calendar calendar) throws IOException, SQLException {
    ByteArrayOutputStream baos = serializeObject(calendar);

    PreparedStatement ps = null;
    PreparedStatement ps2 = null;
    ResultSet rs = null;

    try {
        ps = conn.prepareStatement(rtp(SELECT_ORACLE_CALENDAR_BLOB));
        ps.setString(1, calendarName);

        rs = ps.executeQuery();

        if (rs.next()) {
            Blob dbBlob = writeDataToBlob(rs, 1, baos.toByteArray());
            ps2 = conn.prepareStatement(rtp(UPDATE_ORACLE_CALENDAR_BLOB));

            ps2.setBlob(1, dbBlob);
            ps2.setString(2, calendarName);

            return ps2.executeUpdate();
        }

        return 0;

    } finally {
        closeResultSet(rs);
        closeStatement(ps);
        closeStatement(ps2);
    }
}
项目:lams    文件:SimpleTriggerImpl.java   
/**
 * @see org.quartz.impl.triggers.AbstractTrigger#updateWithNewCalendar(org.quartz.Calendar, long)
 */
@Override
public void updateWithNewCalendar(Calendar calendar, long misfireThreshold)
{
    nextFireTime = getFireTimeAfter(previousFireTime);

    if (nextFireTime == null || calendar == null) {
        return;
    }

    Date now = new Date();
    while (nextFireTime != null && !calendar.isTimeIncluded(nextFireTime.getTime())) {

        nextFireTime = getFireTimeAfter(nextFireTime);

        if(nextFireTime == null)
            break;

        //avoid infinite loop
        java.util.Calendar c = java.util.Calendar.getInstance();
        c.setTime(nextFireTime);
        if (c.get(java.util.Calendar.YEAR) > YEAR_TO_GIVEUP_SCHEDULING_AT) {
            nextFireTime = null;
        }

        if(nextFireTime != null && nextFireTime.before(now)) {
            long diff = now.getTime() - nextFireTime.getTime();
            if(diff >= misfireThreshold) {
                nextFireTime = getFireTimeAfter(nextFireTime);
            }
        }
    }
}
项目:lams    文件:RemoteScheduler.java   
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>.
 * </p>
 */
public void addCalendar(String calName, Calendar calendar, boolean replace, boolean updateTriggers)
    throws SchedulerException {
    try {
        getRemoteScheduler().addCalendar(calName, calendar,
                replace, updateTriggers);
    } catch (RemoteException re) {
        throw invalidateHandleCreateException(
                "Error communicating with remote scheduler.", re);
    }
}
项目:lams    文件:RemoteScheduler.java   
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>.
 * </p>
 */
public Calendar getCalendar(String calName) throws SchedulerException {
    try {
        return getRemoteScheduler().getCalendar(calName);
    } catch (RemoteException re) {
        throw invalidateHandleCreateException(
                "Error communicating with remote scheduler.", re);
    }
}
项目:lams    文件:QuartzScheduler.java   
/**
 * <p>
 * Add the <code>{@link org.quartz.Job}</code> identified by the given
 * <code>{@link org.quartz.JobDetail}</code> to the Scheduler, and
 * associate the given <code>{@link org.quartz.Trigger}</code> with it.
 * </p>
 * 
 * <p>
 * If the given Trigger does not reference any <code>Job</code>, then it
 * will be set to reference the Job passed with it into this method.
 * </p>
 * 
 * @throws SchedulerException
 *           if the Job or Trigger cannot be added to the Scheduler, or
 *           there is an internal Scheduler error.
 */
public Date scheduleJob(JobDetail jobDetail,
        Trigger trigger) throws SchedulerException {
    validateState();

    if (jobDetail == null) {
        throw new SchedulerException("JobDetail cannot be null");
    }

    if (trigger == null) {
        throw new SchedulerException("Trigger cannot be null");
    }

    if (jobDetail.getKey() == null) {
        throw new SchedulerException("Job's key cannot be null");
    }

    if (jobDetail.getJobClass() == null) {
        throw new SchedulerException("Job's class cannot be null");
    }

    OperableTrigger trig = (OperableTrigger)trigger;

    if (trigger.getJobKey() == null) {
        trig.setJobKey(jobDetail.getKey());
    } else if (!trigger.getJobKey().equals(jobDetail.getKey())) {
        throw new SchedulerException(
            "Trigger does not reference given job!");
    }

    trig.validate();

    Calendar cal = null;
    if (trigger.getCalendarName() != null) {
        cal = resources.getJobStore().retrieveCalendar(trigger.getCalendarName());
    }
    Date ft = trig.computeFirstFireTime(cal);

    if (ft == null) {
        throw new SchedulerException(
                "Based on configured schedule, the given trigger '" + trigger.getKey() + "' will never fire.");
    }

    resources.getJobStore().storeJobAndTrigger(jobDetail, trig);
    notifySchedulerListenersJobAdded(jobDetail);
    notifySchedulerThread(trigger.getNextFireTime().getTime());
    notifySchedulerListenersSchduled(trigger);

    return ft;
}
项目:lams    文件:QuartzScheduler.java   
/**
 * <p>
 * Remove (delete) the <code>{@link org.quartz.Trigger}</code> with the
 * given name, and store the new given one - which must be associated
 * with the same job.
 * </p>
 * @param newTrigger
 *          The new <code>Trigger</code> to be stored.
 * 
 * @return <code>null</code> if a <code>Trigger</code> with the given
 *         name & group was not found and removed from the store, otherwise
 *         the first fire time of the newly scheduled trigger.
 */
public Date rescheduleJob(TriggerKey triggerKey,
        Trigger newTrigger) throws SchedulerException {
    validateState();

    if (triggerKey == null) {
        throw new IllegalArgumentException("triggerKey cannot be null");
    }
    if (newTrigger == null) {
        throw new IllegalArgumentException("newTrigger cannot be null");
    }

    OperableTrigger trig = (OperableTrigger)newTrigger;
    Trigger oldTrigger = getTrigger(triggerKey);
    if (oldTrigger == null) {
        return null;
    } else {
        trig.setJobKey(oldTrigger.getJobKey());
    }
    trig.validate();

    Calendar cal = null;
    if (newTrigger.getCalendarName() != null) {
        cal = resources.getJobStore().retrieveCalendar(
                newTrigger.getCalendarName());
    }
    Date ft = trig.computeFirstFireTime(cal);

    if (ft == null) {
        throw new SchedulerException(
                "Based on configured schedule, the given trigger will never fire.");
    }

    if (resources.getJobStore().replaceTrigger(triggerKey, trig)) {
        notifySchedulerThread(newTrigger.getNextFireTime().getTime());
        notifySchedulerListenersUnscheduled(triggerKey);
        notifySchedulerListenersSchduled(newTrigger);
    } else {
        return null;
    }

    return ft;

}
项目:lams    文件:QuartzScheduler.java   
/**
 * <p>
 * Get the <code>{@link Calendar}</code> instance with the given name.
 * </p>
 */
public Calendar getCalendar(String calName)
    throws SchedulerException {
    validateState();

    return resources.getJobStore().retrieveCalendar(calName);
}
项目:asura    文件:TriggerFiredBundle.java   
public TriggerFiredBundle(JobDetail job, Trigger trigger, Calendar cal,
        boolean jobIsRecovering, Date fireTime, Date scheduledFireTime,
        Date prevFireTime, Date nextFireTime) {
    this.job = job;
    this.trigger = trigger;
    this.cal = cal;
    this.jobIsRecovering = jobIsRecovering;
    this.fireTime = fireTime;
    this.scheduledFireTime = scheduledFireTime;
    this.prevFireTime = prevFireTime;
    this.nextFireTime = nextFireTime;
}
项目:asura    文件:MonthlyCalendar.java   
/**
 * <p>
 * Determine whether the given time (in milliseconds) is 'included' by the
 * Calendar.
 * </p>
 *
 * <p>
 * Note that this Calendar is only has full-day precision.
 * </p>
 */
public boolean isTimeIncluded(long timeStamp) {
    if (excludeAll == true) {
        return false;
    }

    // Test the base calendar first. Only if the base calendar not already
    // excludes the time/date, continue evaluating this calendar instance.
    if (super.isTimeIncluded(timeStamp) == false) { return false; }

    java.util.Calendar cl = createJavaCalendar(timeStamp);
    int day = cl.get(java.util.Calendar.DAY_OF_MONTH);

    return !(isDayExcluded(day));
}
项目:lams    文件:PlainTerracottaJobStore.java   
@Override
public void storeCalendar(String name, Calendar calendar, boolean replaceExisting, boolean updateTriggers)
    throws JobPersistenceException {
  clusteredJobStore.storeCalendar(name, calendar, replaceExisting, updateTriggers);
}
项目:lams    文件:TriggerWrapper.java   
public void updateAfterMisfire(Calendar cal, TriggerFacade triggerFacade) {
  this.trigger.updateAfterMisfire(cal);
  rePut(triggerFacade);
}