Search in sources :

Example 1 with IJob

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

the class IbisJobDetail method compareWith.

public boolean compareWith(IJob otherJobDef) {
    IJob thisJobDef = getJobDef();
    // If the CRON expression is different in both jobs, it's not equal!
    if (!StringUtils.equals(thisJobDef.getCronExpression(), otherJobDef.getCronExpression())) {
        return false;
    }
    // If the Interval expression is different in both jobs, it's not equal!
    if (thisJobDef.getInterval() != otherJobDef.getInterval()) {
        return false;
    }
    Locker thisLocker = thisJobDef.getLocker();
    Locker otherLocker = otherJobDef.getLocker();
    // If one is NULL but the other isn't, (locker has been removed or added, it's not equal!
    if ((thisLocker == null && otherLocker != null) || (thisLocker != null && otherLocker == null)) {
        return false;
    }
    // If both contain a locker but the key is different, it's not equal!
    if (thisLocker != null && otherLocker != null && !StringUtils.equals(thisLocker.getObjectId(), otherLocker.getObjectId())) {
        return false;
    }
    // If at this point the message is equal in both jobs, the jobs are equal!
    if (thisJobDef instanceof SendMessageJob && otherJobDef instanceof SendMessageJob) {
        String msg1 = ((SendMessageJob) thisJobDef).getMessage();
        String msg2 = ((SendMessageJob) otherJobDef).getMessage();
        return StringUtils.equals(msg1, msg2);
    }
    return true;
}
Also used : SendMessageJob(nl.nn.adapterframework.scheduler.job.SendMessageJob) Locker(nl.nn.adapterframework.util.Locker) IJob(nl.nn.adapterframework.scheduler.job.IJob)

Example 2 with IJob

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

the class SchedulerAdapter method getJobGroupNamesWithJobsToXml.

/**
 * Get all jobgroups, jobs within this group, the jobdetail and the
 * associated triggers in XML format.
 */
public XmlBuilder getJobGroupNamesWithJobsToXml(Scheduler theScheduler, IbisManager ibisManager) {
    XmlBuilder xbRoot = new XmlBuilder("jobGroups");
    try {
        // process groups
        List<String> jgnames = theScheduler.getJobGroupNames();
        for (int i = 0; i < jgnames.size(); i++) {
            XmlBuilder el = new XmlBuilder("jobGroup");
            String jobGroupName = jgnames.get(i);
            el.addAttribute("name", jobGroupName);
            // process jobs within group
            XmlBuilder jb = new XmlBuilder("jobs");
            Set<JobKey> jobKeys = theScheduler.getJobKeys(GroupMatcher.jobGroupEquals(jobGroupName));
            for (JobKey jobKey : jobKeys) {
                XmlBuilder jn = new XmlBuilder("job");
                String jobName = jobKey.getName();
                jn.addAttribute("name", jobName);
                // details for job
                JobDetail jobDetail = theScheduler.getJobDetail(jobKey);
                XmlBuilder jd = jobDetailToXmlBuilder(jobDetail);
                jn.addSubElement(jd);
                // get the triggers for this job
                List<? extends Trigger> triggers = theScheduler.getTriggersOfJob(jobKey);
                XmlBuilder tr = getJobTriggers(triggers);
                jn.addSubElement(tr);
                JobDataMap jobDataMap = jobDetail.getJobDataMap();
                XmlBuilder datamap = jobDataMapToXmlBuilder(jobDataMap);
                jn.addSubElement(datamap);
                jb.addSubElement(jn);
                IJob jobDef = null;
                if (ibisManager != null) {
                    for (Configuration configuration : ibisManager.getConfigurations()) {
                        jobDef = configuration.getScheduledJob(jobName);
                        if (jobDef != null) {
                            break;
                        }
                    }
                }
                XmlBuilder ms = getJobMessages(jobDef);
                jn.addSubElement(ms);
                XmlBuilder jrs = getJobRunStatistics(jobDef);
                jn.addSubElement(jrs);
            }
            el.addSubElement(jb);
            xbRoot.addSubElement(el);
        }
    } catch (SchedulerException se) {
        log.error(se);
    }
    return xbRoot;
}
Also used : JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) SchedulerException(org.quartz.SchedulerException) Configuration(nl.nn.adapterframework.configuration.Configuration) IJob(nl.nn.adapterframework.scheduler.job.IJob) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder)

Example 3 with IJob

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

the class ScheduleManager method close.

@Override
public void close() throws Exception {
    if (!inState(BootState.STOPPED)) {
        // Call this just in case...
        stop();
    }
    while (!getSchedulesList().isEmpty()) {
        IJob job = getSchedulesList().get(0);
        unRegister(job);
    }
}
Also used : IJob(nl.nn.adapterframework.scheduler.job.IJob)

Example 4 with IJob

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

the class DigesterRuleBase method begin.

@Override
public final void begin(String uri, String elementName, Attributes attributes) throws Exception {
    Object top = getBean();
    Map<String, String> map = copyAttrsToMap(attributes);
    if (top instanceof INamedObject) {
        // We must set the name first, to improve logging and configuration warnings
        String name = map.remove("name");
        if (StringUtils.isNotEmpty(name)) {
            BeanUtils.setProperty(top, "name", name);
        }
    }
    // They are however still required for the JobFactory to determine the correct job class, in order to avoid ConfigurationWarnings.
    if (top instanceof IJob && !(top instanceof Job)) {
        map.remove("function");
    }
    handleBean();
    for (Entry<String, String> entry : map.entrySet()) {
        String attribute = entry.getKey();
        if (log.isTraceEnabled()) {
            log.trace("checking attribute [" + attribute + "] on bean [" + getObjectName() + "]");
        }
        handleAttribute(attribute, entry.getValue(), map);
    }
}
Also used : INamedObject(nl.nn.adapterframework.core.INamedObject) IJob(nl.nn.adapterframework.scheduler.job.IJob) INamedObject(nl.nn.adapterframework.core.INamedObject) IJob(nl.nn.adapterframework.scheduler.job.IJob) Job(nl.nn.adapterframework.scheduler.job.Job)

Example 5 with IJob

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

the class ScheduleManager method stop.

/**
 * remove all registered jobs
 */
@Override
public void stop() {
    if (!inState(BootState.STARTED)) {
        log.warn("forcing [" + this + "] to stop while in state [" + getState() + "]");
    }
    updateState(BootState.STOPPING);
    log.info("stopping all adapters in AdapterManager [" + this + "]");
    List<IJob> scheduledJobs = getSchedulesList();
    Collections.reverse(scheduledJobs);
    for (IJob jobDef : scheduledJobs) {
        log.info("removing trigger for JobDef [" + jobDef.getName() + "]");
        try {
            getSchedulerHelper().deleteTrigger(jobDef);
        } catch (SchedulerException se) {
            log.error("unable to remove scheduled job [" + jobDef + "]", se);
        }
    }
    updateState(BootState.STOPPED);
}
Also used : SchedulerException(org.quartz.SchedulerException) IJob(nl.nn.adapterframework.scheduler.job.IJob)

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