Java Code Examples for org.quartz.JobDetail#getJobClass()

The following examples show how to use org.quartz.JobDetail#getJobClass() . 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: QuartzSchedulerBeanTargetEditor.java    From light-task-scheduler with Apache License 2.0 7 votes vote down vote up
private QuartzJobContext buildQuartzJobContext(QuartzJobContext quartzJobContext, Trigger trigger) {
    JobDataMap triggerJobDataMap = trigger.getJobDataMap();
    JobDetail jobDetail = (JobDetail) triggerJobDataMap.get("jobDetail");
    // 要执行的类
    MethodInvoker methodInvoker = (MethodInvoker) jobDetail.getJobDataMap().get("methodInvoker");
    Map<String, Object> jobDataMap = new HashMap<String, Object>();
    jobDataMap.putAll(triggerJobDataMap);
    jobDataMap.putAll(jobDetail.getJobDataMap());
    jobDataMap.remove("jobDetail");
    jobDataMap.remove("methodInvoker");

    quartzJobContext.setJobDataMap(jobDataMap);
    if (methodInvoker != null) {
        quartzJobContext.setJobExecution(new MethodInvokeJobExecution(methodInvoker));
    } else {
        Class<? extends Job> jobClass = jobDetail.getJobClass();
        try {
            Job job = jobClass.newInstance();
            quartzJobContext.setJobExecution(new JobDetailJobExecution(job));
        } catch (Exception e) {
            throw new QuartzProxyException("Instance JobClass[" + (jobClass == null ? null : jobClass.getName()) + "] error", e);
        }
    }
    return quartzJobContext;
}
 
Example 2
Source File: SimpleJobFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public Job newJob(TriggerFiredBundle bundle, Scheduler Scheduler) throws SchedulerException {

        JobDetail jobDetail = bundle.getJobDetail();
        Class<? extends Job> jobClass = jobDetail.getJobClass();
        try {
            if(log.isDebugEnabled()) {
                log.debug(
                    "Producing instance of Job '" + jobDetail.getKey() + 
                    "', class=" + jobClass.getName());
            }
            
            return jobClass.newInstance();
        } catch (Exception e) {
            SchedulerException se = new SchedulerException(
                    "Problem instantiating class '"
                            + jobDetail.getJobClass().getName() + "'", e);
            throw se;
        }
    }
 
Example 3
Source File: SimpleJobFactory.java    From AsuraFramework with Apache License 2.0 6 votes vote down vote up
public Job newJob(TriggerFiredBundle bundle) throws SchedulerException {

        JobDetail jobDetail = bundle.getJobDetail();
        Class jobClass = jobDetail.getJobClass();
        try {
            if(log.isDebugEnabled()) {
                log.debug(
                    "Producing instance of Job '" + jobDetail.getFullName() + 
                    "', class=" + jobClass.getName());
            }
            
            return (Job) jobClass.newInstance();
        } catch (Exception e) {
            SchedulerException se = new SchedulerException(
                    "Problem instantiating class '"
                            + jobDetail.getJobClass().getName() + "'", e);
            throw se;
        }
    }
 
Example 4
Source File: JobDetailEntity.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Populate entity fields used for indexing.
 */
@Override
public void setValue(final JobDetail value) {
  super.setValue(value);

  JobKey key = value.getKey();
  checkState(key != null, "Missing key");
  setName(key.getName());
  setGroup(key.getGroup());

  Class clazz = value.getJobClass();
  checkState(clazz != null, "Missing job-class");
  setJobType(clazz.getCanonicalName());
}
 
Example 5
Source File: GuiceJobFactory.java    From Raigad with Apache License 2.0 5 votes vote down vote up
@Override
public Job newJob(TriggerFiredBundle bundle) throws SchedulerException
{
    JobDetail jobDetail = bundle.getJobDetail();
    Class<?> jobClass = jobDetail.getJobClass();
    Job job = (Job) guice.getInstance(jobClass);
    guice.injectMembers(job);
    return job;
}
 
Example 6
Source File: NewJobForm.java    From quartz-glass with Apache License 2.0 5 votes vote down vote up
public NewJobForm(JobDetail jobDetail) {
    super();
    this.group = jobDetail.getKey().getGroup();
    this.name = jobDetail.getKey().getName();
    this.clazz = jobDetail.getJobClass();
    this.dataMap = JobDataMapUtils.toProperties(jobDetail.getJobDataMap());
}
 
Example 7
Source File: QuartzScheduler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * <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;
}
 
Example 8
Source File: QuartzAdapter.java    From javamelody with Apache License 2.0 4 votes vote down vote up
Class<?> getJobClass(JobDetail jobDetail) {
	return jobDetail.getJobClass();
}
 
Example 9
Source File: Quartz2Adapter.java    From javamelody with Apache License 2.0 4 votes vote down vote up
@Override
Class<?> getJobClass(JobDetail jobDetail) {
	return jobDetail.getJobClass();
}
 
Example 10
Source File: NavigableEventLogListener.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private void info (EVENTTYPE eventType, Trigger trig, JobExecutionContext context, JobExecutionException exception, CompletedExecutionInstruction instructionCode) {
    JobDetail
        detail = (context != null)?context.getJobDetail():null;
    final JobDataMap
        dataMap = (context != null)?context.getMergedJobDataMap():null;
    final String
        jobName = (detail != null)?detail.getKey().getName():null,
        jobDesc = (detail != null)?detail.getDescription():null;
    final Class
        jobClass = (detail != null)?detail.getJobClass():null;
    final Trigger
        trigger = (trig != null)?trig:((context != null)?context.getTrigger():null);
    final String
        trigName = (trigger != null)?trigger.getKey().getName():null,
        trigDesc = (trigger != null)?trigger.getDescription():null;
    final Date
        trigStart = (trigger != null)?trigger.getStartTime():null,
        trigEnd = (trigger != null)?trigger.getEndTime():null;

    StringBuilder
        sb = new StringBuilder();

    switch (eventType)
    {
        case JOB_EXECUTING:
        {
            sb.append("Job Executing: [");
            sb.append("name: ").append(jobName).append(", description: ").append((jobDesc != null)?jobDesc:"")
                    .append(", class: ").append(jobClass.getName());
            sb.append("]");
            break;
        }
        case JOB_VETOED:
        {
            sb.append("Job Vetoed: [");
            sb.append("name: ").append(jobName).append(", description: ").append((jobDesc != null)?jobDesc:"")
                    .append(", class: ").append(jobClass.getName());
            break;
        }
        case JOB_EXECUTED:
        {
            sb.append("Job Executed: [");
            sb.append("name: ").append(jobName).append(", description: ").append((jobDesc != null)?jobDesc:"")
              .append(", class: ").append(jobClass.getName());

            if (exception != null)
            {
                sb.append (", exception: ").append(exception.getMessage());
                if (exception.getCause() != null)
                {
                  sb.append(", exception cause: ").append(exception.getCause().getClass().getName());
                }
            }
            sb.append("]");

            break;
        }
        case TRIGGER_FIRED:
        {
            sb.append("Trigger Fired: [");
            sb.append("trigger: ").append(trigName).append(", trigger description: ").append((trigDesc != null)?trigDesc:"")
              .append(", start: ").append((trigStart != null)?trigStart.toString():null)
              .append(", end: ").append((trigEnd != null)?trigEnd.toString():null);
            sb.append(", job: ").append(jobName).append(", job description: ").append((jobDesc != null)?jobDesc:"")
                    .append(", class: ").append(jobClass.getName());
            sb.append("]");
            break;
        }
        case TRIGGER_MISFIRED:
        {
            sb.append("Trigger Misfired: [");
            sb.append("trigger: ").append(trigName).append(", trigger description: ").append((trigDesc != null)?trigDesc:"")
              .append(", start: ").append((trigStart!=null)?trigStart.toString():null)
              .append(", end: ").append((trigEnd!=null)?trigEnd.toString():null);
            sb.append("]");
            break;
        }
        case TRIGGER_COMPLETED:
        {
            sb.append("Trigger Completed: [");
            sb.append("trigger: ").append(trigName).append(", trigger description: ").append((trigDesc != null)?trigDesc:"")
              .append(", start: ").append((trigStart!=null)?trigStart.toString():null)
              .append(", end: ").append((trigEnd!=null)?trigEnd.toString():null);
            sb.append(", job: ").append(jobName).append(", job description: ").append((jobDesc != null)?jobDesc:"")
              .append(", class: ").append(jobClass.getName())
              .append(", execution result: ").append(instructionCode);
            sb.append("]");
            break;
        }
    }
    if (log.isDebugEnabled())
    {
    	log.debug(sb.toString());
    }
}
 
Example 11
Source File: NavigableEventLogListener.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private void info (EVENTTYPE eventType, Trigger trig, JobExecutionContext context, JobExecutionException exception, CompletedExecutionInstruction instructionCode) {
    JobDetail
        detail = (context != null)?context.getJobDetail():null;
    final JobDataMap
        dataMap = (context != null)?context.getMergedJobDataMap():null;
    final String
        jobName = (detail != null)?detail.getKey().getName():null,
        jobDesc = (detail != null)?detail.getDescription():null;
    final Class
        jobClass = (detail != null)?detail.getJobClass():null;
    final Trigger
        trigger = (trig != null)?trig:((context != null)?context.getTrigger():null);
    final String
        trigName = (trigger != null)?trigger.getKey().getName():null,
        trigDesc = (trigger != null)?trigger.getDescription():null;
    final Date
        trigStart = (trigger != null)?trigger.getStartTime():null,
        trigEnd = (trigger != null)?trigger.getEndTime():null;

    StringBuilder
        sb = new StringBuilder();

    switch (eventType)
    {
        case JOB_EXECUTING:
        {
            sb.append("Job Executing: [");
            sb.append("name: ").append(jobName).append(", description: ").append((jobDesc != null)?jobDesc:"")
                    .append(", class: ").append(jobClass.getName());
            sb.append("]");
            break;
        }
        case JOB_VETOED:
        {
            sb.append("Job Vetoed: [");
            sb.append("name: ").append(jobName).append(", description: ").append((jobDesc != null)?jobDesc:"")
                    .append(", class: ").append(jobClass.getName());
            break;
        }
        case JOB_EXECUTED:
        {
            sb.append("Job Executed: [");
            sb.append("name: ").append(jobName).append(", description: ").append((jobDesc != null)?jobDesc:"")
              .append(", class: ").append(jobClass.getName());

            if (exception != null)
            {
                sb.append (", exception: ").append(exception.getMessage());
                if (exception.getCause() != null)
                {
                  sb.append(", exception cause: ").append(exception.getCause().getClass().getName());
                }
            }
            sb.append("]");

            break;
        }
        case TRIGGER_FIRED:
        {
            sb.append("Trigger Fired: [");
            sb.append("trigger: ").append(trigName).append(", trigger description: ").append((trigDesc != null)?trigDesc:"")
              .append(", start: ").append((trigStart != null)?trigStart.toString():null)
              .append(", end: ").append((trigEnd != null)?trigEnd.toString():null);
            sb.append(", job: ").append(jobName).append(", job description: ").append((jobDesc != null)?jobDesc:"")
                    .append(", class: ").append(jobClass.getName());
            sb.append("]");
            break;
        }
        case TRIGGER_MISFIRED:
        {
            sb.append("Trigger Misfired: [");
            sb.append("trigger: ").append(trigName).append(", trigger description: ").append((trigDesc != null)?trigDesc:"")
              .append(", start: ").append((trigStart!=null)?trigStart.toString():null)
              .append(", end: ").append((trigEnd!=null)?trigEnd.toString():null);
            sb.append("]");
            break;
        }
        case TRIGGER_COMPLETED:
        {
            sb.append("Trigger Completed: [");
            sb.append("trigger: ").append(trigName).append(", trigger description: ").append((trigDesc != null)?trigDesc:"")
              .append(", start: ").append((trigStart!=null)?trigStart.toString():null)
              .append(", end: ").append((trigEnd!=null)?trigEnd.toString():null);
            sb.append(", job: ").append(jobName).append(", job description: ").append((jobDesc != null)?jobDesc:"")
              .append(", class: ").append(jobClass.getName())
              .append(", execution result: ").append(instructionCode);
            sb.append("]");
            break;
        }
    }
    if (log.isDebugEnabled())
    {
    	log.debug(sb.toString());
    }
}
 
Example 12
Source File: HK2JobFactory.java    From dropwizard-experiment with MIT License 4 votes vote down vote up
@Override
public Job newJob(TriggerFiredBundle triggerFiredBundle, Scheduler scheduler) throws SchedulerException {
    JobDetail jobDetail = triggerFiredBundle.getJobDetail();
    Class<? extends Job> jobClass = jobDetail.getJobClass();
    return locator.getService(jobClass);
}
 
Example 13
Source File: ReportJobFactory.java    From AisAbnormal with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Job newJob(TriggerFiredBundle triggerFiredBundle, Scheduler scheduler) throws SchedulerException {
    JobDetail jobDetail = triggerFiredBundle.getJobDetail();
    Class jobClass = jobDetail.getJobClass();
    return (Job) injector.getInstance(jobClass);
}
 
Example 14
Source File: Jobs.java    From quartz-glass with Apache License 2.0 4 votes vote down vote up
public static Class<?> jobCass(JobDetail jobDetail) {
    JobDataMap jobDataMap = jobDetail.getJobDataMap();
    PojoJobMeta pojoJobMeta = (PojoJobMeta) jobDataMap.get(GlassConstants.POJO_JOB_META);
    return pojoJobMeta == null ? jobDetail.getJobClass() : pojoJobMeta.getTargetClass();
}