Package org.quartz

Examples of org.quartz.Trigger


         start = new Date();
      if (repeat <= 0)
         repeat = SimpleTrigger.REPEAT_INDEFINITELY;
      else
         repeat = repeat - 1;
      Trigger trigger =
         TriggerBuilder
            .newTrigger()
            .withIdentity(jobinfo.getJobName(), jobinfo.getGroupName())
            .withSchedule(
               SimpleScheduleBuilder.simpleSchedule().withRepeatCount(repeat)
View Full Code Here


   }

   public void addCronJob(JobInfo jinfo, String exp) throws Exception
   {
      JobInfo jobinfo = getJobInfo(jinfo);
      Trigger trigger =
         TriggerBuilder.newTrigger().withIdentity(jobinfo.getJobName(), jobinfo.getGroupName())
            .forJob(jobinfo.getJobName(), jobinfo.getGroupName()).withSchedule(CronScheduleBuilder.cronSchedule(exp))
            .build();
      @SuppressWarnings("unchecked")
      JobDetail job =
View Full Code Here

   }

   public void addCronJob(JobInfo jinfo, String exp, JobDataMap jdatamap) throws Exception
   {
      JobInfo jobinfo = getJobInfo(jinfo);
      Trigger trigger =
         TriggerBuilder.newTrigger().withIdentity(jobinfo.getJobName(), jobinfo.getGroupName())
            .forJob(jobinfo.getJobName(), jobinfo.getGroupName()).withSchedule(CronScheduleBuilder.cronSchedule(exp))
            .build();
      @SuppressWarnings("unchecked")
      JobBuilder jb =
View Full Code Here

         start = new Date();
      if (repeat <= 0)
         repeat = SimpleTrigger.REPEAT_INDEFINITELY;
      else
         repeat = repeat - 1;
      Trigger trigger =
         TriggerBuilder
            .newTrigger()
            .withIdentity(jobinfo.getJobName(), jobinfo.getGroupName())
            .withSchedule(
               SimpleScheduleBuilder.simpleSchedule().withRepeatCount(repeat)
View Full Code Here

      scheduler_.resumeJob(JobKey.jobKey(jobName, getGroupName(groupName)));
   }

   public void executeJob(String jname, String jgroup, JobDataMap jdatamap) throws Exception
   {
      Trigger trigger = TriggerBuilder.newTrigger().withIdentity(jname, getGroupName(jgroup)).startNow().build();
      JobBuilder jb = JobBuilder.newJob().withIdentity(jname, getGroupName(jgroup));
      JobDetail job = jdatamap == null ? jb.build() : jb.usingJobData(jdatamap).build();
      scheduleJob(job, trigger);
   }
View Full Code Here

        Map<String, Object> triggerParameters = IntrospectionSupport.extractProperties(parameters, "trigger.");
        Map<String, Object> jobParameters = IntrospectionSupport.extractProperties(parameters, "job.");

        // create the trigger either cron or simple
        Trigger trigger;
        if (ObjectHelper.isNotEmpty(cron)) {
            trigger = createCronTrigger(cron);
        } else {
            trigger = new SimpleTrigger();
            if (fireNow) {
                String intervalString = (String) triggerParameters.get("repeatInterval");
                if (intervalString != null) {
                    long interval = Long.valueOf(intervalString);
                    trigger.setStartTime(new Date(System.currentTimeMillis() - interval));
                }
            }
        }
        answer.setTrigger(trigger);

        trigger.setName(name);
        trigger.setGroup(group);

        setProperties(trigger, triggerParameters);
        setProperties(answer.getJobDetail(), jobParameters);

        return answer;
View Full Code Here

    }

    private void setExecTime(final SchedTaskTO taskTO, final Task task) {
        String triggerName = JobInstanceLoader.getTriggerName(JobInstanceLoader.getJobName(task));

        Trigger trigger = null;
        try {
            trigger = scheduler.getScheduler().getTrigger(new TriggerKey(triggerName, Scheduler.DEFAULT_GROUP));
        } catch (SchedulerException e) {
            LOG.warn("While trying to get to " + triggerName, e);
        }

        if (trigger != null) {
            taskTO.setLastExec(trigger.getPreviousFireTime());
            taskTO.setNextExec(trigger.getNextFireTime());
        }
    }
View Full Code Here

    {
        // Force initialisation of any proxy, JBESB-2720
        Hibernate.initialize(timer) ;
        jobSession.saveJob(timer) ;
        final String name = getTimerName(timer) ;
        final Trigger trigger = new SimpleTrigger(name, JBPM_GROUP, timer.getDueDate()) ;
        final JobDetail jobDetail = new JobDetail(name, JBPM_GROUP, QuartzSchedulerServiceJob.class) ;

        final JobDataMap jobDataMap = new JobDataMap() ;
        jobDataMap.put(TIMER_ID, new Long(timer.getId())) ;
        jobDataMap.put(MAX_REFIRE_COUNT, Integer.valueOf(maxRefireCount)) ;
View Full Code Here

    Date startTime = null;;
    Date endTime = null;
    Date curTime = new Date();
    int repeat=0;
    long interval=0;
    Trigger trigger = null;
    JobDetail jobDetail = null;
   
    while (rs.next()) {
      curTask = rs.getString("TASK_ID");
      taskJob = rs.getString("JOB_CLASS");
      taskArgs = rs.getString("ARGUMENTS");
      if (taskArgs == null)
      {
        taskArgs = "";
      }
      taskTrigger = rs.getString("TRIGGER_TYPE");
     
      //verbose
      logger.info("Task " + curTask);
      logger.info("Task " + curTask + " - Job Class    = " + taskJob);
      logger.info("Task " + curTask + " - Trigger Type = " + taskTrigger);
      logger.info("Task " + curTask + " - Arguments    = " + taskArgs);
     
      //validation
      if (taskJob.length() == 0 || taskTrigger.length() == 0)
      {
        logger.error("You must provide both Job class and Trigger type for task "
                + curTask + "!");
        continue;
      }
     
      //get the trigger setting
      if (taskTrigger.compareToIgnoreCase("CronTrigger") == 0)
      {
        taskCron = rs.getString("TRIGGER_CRON");
        if (null == taskCron) {
          taskCron = DEF_CRONSTRING;
        } else {
          taskCron = taskCron.trim();
        }
        isSimpleTrigger = false;
        //verbose
        logger.info("Task " + curTask + " - Cron Value   = " + taskCron);
      }
      else if (taskTrigger.compareToIgnoreCase("SimpleTrigger") == 0)
      {
        taskStartTime = rs.getDate("TRIGGER_START");
        if (taskStartTime == null)
        {
          taskStartTime = new Date();
        }
        taskEndTime = rs.getDate("TRIGGER_END");
        taskRepeat = rs.getInt("TRIGGER_REPEAT");
        taskInterval = rs.getInt("TRIGGER_INTERVAL");
        isSimpleTrigger = true;
        //verbose
        logger.info("Task " + curTask + " - Start Time   = " + taskStartTime);
        logger.info("Task " + curTask + " - End Time     = " + taskEndTime);
        logger.info("Task " + curTask + " - Repeat Count = " + taskRepeat);
        logger.info("Task " + curTask + " - Interval     = " + taskInterval);
        if (taskEndTime != null &&
            (curTime.after(taskEndTime) || !taskStartTime.before(taskEndTime)))
        {
          logger.warn("Task " + curTask + " is OBSOLETE! Ignored.");
          continue;
        }
      }
      else
      {
        logger.error("Invalid trigger type ("+ taskTrigger + ") for task " + curTask + "!");
        continue;
      }
     
      //interpret parameters
      try
      {
        jobClass = Class.forName(taskJob);
        if (jobClass == null)
        {
          logger.error("Invalid job class (" + taskJob + ") for task " + curTask + "!");
          continue;
        }
      }
      catch (ClassNotFoundException e)
      {
        logger.error("Invalid job class (" + taskJob + ") for task " + curTask + "!");
        continue;
      }
      catch (NoClassDefFoundError e)
      {
        //NOTE: NoClassDefFoundError does not seem to extend Exception
        logger.error("Can not load class " + taskJob + ". Exception: " + e.toString());
        continue;
      }
      catch (Exception e)
      { 
        logger.error("Can not load class " + taskJob + ". Exception: " + e.toString());
        continue;
      }

      if (isSimpleTrigger)
      {
        //delay the execution until the agent is properly started
        startTime = new Date();
        startTime.setTime(startTime.getTime()+EXECUTION_DELAY_MILLIS);   
        if (taskStartTime != null && taskStartTime.after(startTime)) {
          startTime = taskStartTime;
        }
        endTime = taskEndTime;
        if (taskRepeat < 0) {
          repeat = SimpleTrigger.REPEAT_INDEFINITELY;
        } else {
          repeat = taskRepeat;
        }
        if (taskInterval < 0) {
          interval = 0;
        } else {
          interval = taskInterval;
        }
      }
     
      //create trigger
      logger.info("Task " + curTask + " - Creating trigger...");
      trigger = null;
      if (isSimpleTrigger) {
        try {
          trigger = new SimpleTrigger(curTask + "_Trigger", null, startTime, endTime, repeat, interval);
        } catch (Exception e) {
          logger.error("Cannot create trigger for task " + curTask + "!");
          logger.error("Exception: "+e.getMessage());
          continue;         
        }
      } else {
        try {
          trigger = new CronTrigger(curTask + "_Trigger", null, taskCron);
        } catch (ParseException e) {
          logger.error("Invalid cron epression (" + taskCron + ") for task " + curTask + "!");
          continue;
        }
      }

      trigger.getJobDataMap().put(SCHEDULER_ARG_STRING, this);
      trigger.getJobDataMap().put(TASK_ARG_STRING, curTask);
      trigger.getJobDataMap().put(ARGUMENT_ARG_STRING,taskArgs);
      trigger.setGroup(taskGroup);
     
      //create job
      logger.info("Task " + curTask + " - Creating job...");
      jobDetail = null;
      try {
View Full Code Here

    public void schedule(TimerData timerData) {
        if (scheduler == null) throw new IllegalStateException("scheduler is configured properly");
       
        timerData.setScheduler(scheduler);
       
        Trigger trigger = timerData.getTrigger();
        trigger.setJobName(OPENEJB_TIMEOUT_JOB_NAME);
        trigger.setJobGroup(OPENEJB_TIMEOUT_JOB_GROUP_NAME);
        JobDataMap triggerDataMap = trigger.getJobDataMap();
        triggerDataMap.put(EjbTimeoutJob.EJB_TIMERS_SERVICE, this);
        triggerDataMap.put(EjbTimeoutJob.TIMER_DATA,timerData);
        try {
            scheduler.scheduleJob(trigger);
        } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.quartz.Trigger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.