Search in sources :

Example 6 with IJob

use of nl.nn.adapterframework.scheduler.job.IJob in project iaf by ibissource.

the class ShowScheduler method getJobMessages.

private List<Map<String, Object>> getJobMessages(JobDetail jobDetail) throws ApiException {
    List<Map<String, Object>> messages = new ArrayList<Map<String, Object>>();
    IJob jobdef = (IJob) jobDetail.getJobDataMap().get(ConfiguredJob.JOBDEF_KEY);
    for (int t = 0; t < jobdef.getMessageKeeper().size(); t++) {
        Map<String, Object> message = new HashMap<String, Object>(3);
        MessageKeeperMessage job = jobdef.getMessageKeeper().getMessage(t);
        message.put("text", job.getMessageText());
        message.put("date", job.getMessageDate());
        message.put("level", job.getMessageLevel());
        messages.add(message);
    }
    return messages;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IJob(nl.nn.adapterframework.scheduler.job.IJob) MessageKeeperMessage(nl.nn.adapterframework.util.MessageKeeperMessage) ArrayList(java.util.ArrayList) Map(java.util.Map) JobDataMap(org.quartz.JobDataMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with IJob

use of nl.nn.adapterframework.scheduler.job.IJob in project iaf by ibissource.

the class ShowScheduler method getJobData.

private Map<String, Object> getJobData(JobKey jobKey, boolean expanded) throws SchedulerException {
    Map<String, Object> jobData = new HashMap<String, Object>();
    Scheduler scheduler = getScheduler();
    String jobName = jobKey.getName();
    JobDetail job = scheduler.getJobDetail(jobKey);
    jobData.put("fullName", job.getKey().getGroup() + "." + job.getKey().getName());
    jobData.put("name", job.getKey().getName());
    jobData.put("group", job.getKey().getGroup());
    String description = "-";
    if (StringUtils.isNotEmpty(job.getDescription()))
        description = job.getDescription();
    jobData.put("description", description);
    jobData.put("stateful", job.isPersistJobDataAfterExecution() && job.isConcurrentExectionDisallowed());
    jobData.put("durable", job.isDurable());
    jobData.put("jobClass", job.getJobClass().getSimpleName());
    if (job instanceof IbisJobDetail) {
        jobData.put("type", ((IbisJobDetail) job).getJobType());
    }
    TriggerState state = scheduler.getTriggerState(TriggerKey.triggerKey(jobName, jobKey.getGroup()));
    jobData.put("state", state.name());
    jobData.put("triggers", getJobTriggers(scheduler.getTriggersOfJob(jobKey)));
    jobData.put("messages", getJobMessages(job));
    JobDataMap jobMap = job.getJobDataMap();
    jobData.put("properties", getJobData(jobMap));
    if (expanded) {
        IJob jobDef = (IJob) jobMap.get(ConfiguredJob.JOBDEF_KEY);
        if (jobDef instanceof DatabaseJob) {
            DatabaseJob dbJob = (DatabaseJob) jobDef;
            jobData.put("adapter", dbJob.getAdapterName());
            jobData.put("listener", dbJob.getJavaListener());
            jobData.put("message", dbJob.getMessage());
        }
        Locker locker = jobDef.getLocker();
        if (locker != null) {
            jobData.put("locker", true);
            jobData.put("lockkey", locker.getObjectId());
        } else {
            jobData.put("locker", false);
        }
    }
    return jobData;
}
Also used : TriggerState(org.quartz.Trigger.TriggerState) JobDetail(org.quartz.JobDetail) IbisJobDetail(nl.nn.adapterframework.scheduler.IbisJobDetail) JobDataMap(org.quartz.JobDataMap) Locker(nl.nn.adapterframework.util.Locker) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Scheduler(org.quartz.Scheduler) IJob(nl.nn.adapterframework.scheduler.job.IJob) DatabaseJob(nl.nn.adapterframework.scheduler.job.DatabaseJob) IbisJobDetail(nl.nn.adapterframework.scheduler.IbisJobDetail)

Example 8 with IJob

use of nl.nn.adapterframework.scheduler.job.IJob in project iaf by ibissource.

the class ScheduleManager method configure.

@Override
public void configure() {
    if (!inState(BootState.STOPPED)) {
        log.warn("unable to configure [" + this + "] while in state [" + getState() + "]");
        return;
    }
    updateState(BootState.STARTING);
    for (IJob jobdef : getSchedulesList()) {
        try {
            jobdef.configure();
            log.info("job scheduled with properties :" + jobdef.toString());
        } catch (Exception e) {
            log.error("Could not schedule job [" + jobdef.getName() + "] cron [" + jobdef.getCronExpression() + "]", e);
        }
    }
}
Also used : IJob(nl.nn.adapterframework.scheduler.job.IJob) SchedulerException(org.quartz.SchedulerException)

Example 9 with IJob

use of nl.nn.adapterframework.scheduler.job.IJob in project iaf by ibissource.

the class ScheduleManager method start.

/**
 * Configure and start, managed through the Spring Lifecyle
 */
@Override
public void start() {
    if (!inState(BootState.STARTING)) {
        log.warn("unable to start [" + this + "] while in state [" + getState() + "]");
        return;
    }
    for (IJob jobdef : getSchedulesList()) {
        if (jobdef.isConfigured()) {
            try {
                schedulerHelper.scheduleJob(jobdef);
                log.info("job scheduled with properties :" + jobdef.toString());
            } catch (SchedulerException e) {
                log.error("Could not schedule job [" + jobdef.getName() + "] cron [" + jobdef.getCronExpression() + "]", e);
            }
        } else {
            log.info("Could not schedule job [" + jobdef.getName() + "] as it is not configured");
        }
    }
    try {
        schedulerHelper.startScheduler();
        log.info("Scheduler started");
    } catch (SchedulerException e) {
        log.error("Could not start scheduler", e);
    }
    updateState(BootState.STARTED);
}
Also used : SchedulerException(org.quartz.SchedulerException) IJob(nl.nn.adapterframework.scheduler.job.IJob)

Example 10 with IJob

use of nl.nn.adapterframework.scheduler.job.IJob in project iaf by ibissource.

the class ConfiguredJob method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    String ctName = Thread.currentThread().getName();
    try {
        JobDataMap dataMap = context.getJobDetail().getJobDataMap();
        IbisManager ibisManager = (IbisManager) dataMap.get(MANAGER_KEY);
        IJob jobDef = (IJob) dataMap.get(JOBDEF_KEY);
        Thread.currentThread().setName(jobDef.getName() + "[" + ctName + "]");
        log.info(getLogPrefix(jobDef) + "executing");
        jobDef.executeJob(ibisManager);
        log.debug(getLogPrefix(jobDef) + "completed");
    } catch (Exception e) {
        log.error("JobExecutionException while running " + getLogPrefix(context), e);
        throw new JobExecutionException(e, false);
    } finally {
        Thread.currentThread().setName(ctName);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) JobExecutionException(org.quartz.JobExecutionException) IbisManager(nl.nn.adapterframework.configuration.IbisManager) IJob(nl.nn.adapterframework.scheduler.job.IJob) JobExecutionException(org.quartz.JobExecutionException)

Aggregations

IJob (nl.nn.adapterframework.scheduler.job.IJob)10 JobDataMap (org.quartz.JobDataMap)4 SchedulerException (org.quartz.SchedulerException)4 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Locker (nl.nn.adapterframework.util.Locker)2 JobDetail (org.quartz.JobDetail)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Configuration (nl.nn.adapterframework.configuration.Configuration)1 IbisManager (nl.nn.adapterframework.configuration.IbisManager)1 INamedObject (nl.nn.adapterframework.core.INamedObject)1 IbisJobDetail (nl.nn.adapterframework.scheduler.IbisJobDetail)1 DatabaseJob (nl.nn.adapterframework.scheduler.job.DatabaseJob)1 Job (nl.nn.adapterframework.scheduler.job.Job)1 SendMessageJob (nl.nn.adapterframework.scheduler.job.SendMessageJob)1 MessageKeeperMessage (nl.nn.adapterframework.util.MessageKeeperMessage)1 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)1 JobExecutionException (org.quartz.JobExecutionException)1 JobKey (org.quartz.JobKey)1