| <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="de"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>JobEntryQuartz.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Turbine</a> > <a href="index.source.html" class="el_package">org.apache.turbine.services.schedule</a> > <span class="el_source">JobEntryQuartz.java</span></div><h1>JobEntryQuartz.java</h1><pre class="source lang-java linenums">package org.apache.turbine.services.schedule; |
| |
| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| |
| import java.util.Date; |
| import java.util.concurrent.atomic.AtomicBoolean; |
| |
| import org.apache.commons.lang3.StringUtils; |
| import org.apache.turbine.modules.ScheduledJobLoader; |
| import org.apache.turbine.util.TurbineException; |
| import org.quartz.Job; |
| import org.quartz.JobBuilder; |
| import org.quartz.JobDetail; |
| import org.quartz.JobExecutionContext; |
| import org.quartz.JobExecutionException; |
| import org.quartz.Trigger; |
| import org.quartz.core.QuartzScheduler; |
| |
| /** |
| * This implements a Turbine scheduled job model for the {@link QuartzScheduler}. |
| * |
| * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a> |
| */ |
| public class JobEntryQuartz implements JobEntry, Job |
| { |
| private int jobId; |
| private Trigger jobTrigger; |
| private JobDetail jobDetail; |
| private String task; |
| <span class="fc" id="L47"> private boolean isnew = true;</span> |
| <span class="fc" id="L48"> private AtomicBoolean active = new AtomicBoolean(false);</span> |
| |
| /** |
| * the default Quartz schedule group name for Turbine jobs |
| */ |
| public static final String DEFAULT_JOB_GROUP_NAME = "TURBINE"; |
| |
| /** |
| * Default constructor |
| */ |
| public JobEntryQuartz() |
| { |
| <span class="fc" id="L60"> super();</span> |
| <span class="fc" id="L61"> }</span> |
| |
| /** |
| * Constructor |
| * |
| * @param jobTrigger Job time table |
| */ |
| public JobEntryQuartz(Trigger jobTrigger) |
| { |
| <span class="nc" id="L70"> this(jobTrigger, JobBuilder</span> |
| <span class="nc" id="L71"> .newJob(JobEntryQuartz.class)</span> |
| <span class="nc" id="L72"> .withIdentity(jobTrigger.getJobKey().getName(), DEFAULT_JOB_GROUP_NAME).build());</span> |
| <span class="nc" id="L73"> }</span> |
| |
| /** |
| * Constructor |
| * |
| * @param jobTrigger Job time table |
| * @param jobDetail job details |
| */ |
| public JobEntryQuartz(Trigger jobTrigger, JobDetail jobDetail) |
| { |
| <span class="fc" id="L83"> this();</span> |
| <span class="fc" id="L84"> setTask(jobTrigger.getJobKey().getName());</span> |
| <span class="fc" id="L85"> this.jobTrigger = jobTrigger;</span> |
| <span class="fc" id="L86"> this.jobDetail = jobDetail;</span> |
| <span class="fc" id="L87"> }</span> |
| |
| /** |
| * Return true, if the entry is not yet persisted |
| */ |
| @Override |
| public boolean isNew() |
| { |
| <span class="nc" id="L95"> boolean _isnew = isnew;</span> |
| <span class="nc" id="L96"> isnew = false;</span> |
| <span class="nc" id="L97"> return _isnew;</span> |
| } |
| |
| /** |
| * Get the value of jobId. |
| * |
| * @return int |
| */ |
| @Override |
| public int getJobId() |
| { |
| <span class="fc" id="L108"> return jobId;</span> |
| } |
| |
| /** |
| * Set the value of jobId. |
| * |
| * @param v new value |
| */ |
| @Override |
| public void setJobId(int v) |
| { |
| <span class="fc" id="L119"> this.jobId = v;</span> |
| <span class="fc" id="L120"> }</span> |
| |
| /** |
| * Get the value of task. |
| * |
| * @return String |
| */ |
| @Override |
| public String getTask() |
| { |
| <span class="fc" id="L130"> return task;</span> |
| } |
| |
| /** |
| * Set the value of task. |
| * |
| * @param v new value |
| */ |
| @Override |
| public void setTask(String v) |
| { |
| <span class="fc" id="L141"> this.task = v;</span> |
| <span class="fc" id="L142"> }</span> |
| |
| /** |
| * @return the jobTrigger |
| */ |
| public Trigger getJobTrigger() |
| { |
| <span class="fc" id="L149"> return jobTrigger;</span> |
| } |
| |
| /** |
| * @param jobTrigger the jobTrigger to set |
| */ |
| public void setJobTrigger(Trigger jobTrigger) |
| { |
| <span class="nc" id="L157"> this.jobTrigger = jobTrigger;</span> |
| <span class="nc" id="L158"> }</span> |
| |
| /** |
| * @return the jobDetail |
| */ |
| public JobDetail getJobDetail() |
| { |
| <span class="fc" id="L165"> return jobDetail;</span> |
| } |
| |
| /** |
| * @see java.lang.Comparable#compareTo(java.lang.Object) |
| */ |
| @Override |
| public int compareTo(JobEntry o) |
| { |
| <span class="nc" id="L174"> return jobTrigger.compareTo(((JobEntryQuartz)o).getJobTrigger());</span> |
| } |
| |
| /** |
| * @see org.apache.turbine.services.schedule.JobEntry#setActive(boolean) |
| */ |
| @Override |
| public void setActive(boolean isActive) |
| { |
| <span class="nc" id="L183"> this.active.set(isActive);</span> |
| <span class="nc" id="L184"> }</span> |
| |
| /** |
| * @see org.apache.turbine.services.schedule.JobEntry#isActive() |
| */ |
| @Override |
| public boolean isActive() |
| { |
| <span class="nc" id="L192"> return active.get();</span> |
| } |
| |
| /** |
| * @see org.apache.turbine.services.schedule.JobEntry#getNextRuntime() |
| */ |
| @Override |
| public long getNextRuntime() |
| { |
| <span class="nc" id="L201"> return getNextRunDate().getTime();</span> |
| } |
| |
| /** |
| * @see org.apache.turbine.services.schedule.JobEntry#getNextRunDate() |
| */ |
| @Override |
| public Date getNextRunDate() |
| { |
| <span class="nc" id="L210"> return jobTrigger.getNextFireTime();</span> |
| } |
| |
| /** |
| * @see org.apache.turbine.services.schedule.JobEntry#getNextRunAsString() |
| */ |
| @Override |
| public String getNextRunAsString() |
| { |
| <span class="nc" id="L219"> return getNextRunDate().toString();</span> |
| } |
| |
| /** |
| * @see org.apache.turbine.services.schedule.JobEntry#calcRunTime() |
| */ |
| @Override |
| public void calcRunTime() throws TurbineException |
| { |
| // do nothing |
| <span class="nc" id="L229"> }</span> |
| |
| /** |
| * @see org.quartz.Job#execute(org.quartz.JobExecutionContext) |
| */ |
| @Override |
| public void execute(JobExecutionContext context) throws JobExecutionException |
| { |
| <span class="pc bpc" id="L237" title="1 of 2 branches missed."> if (active.compareAndSet(false, true) == false)</span> |
| { |
| <span class="nc" id="L239"> return;</span> |
| } |
| |
| try |
| { |
| <span class="fc" id="L244"> String task = getTask();</span> |
| <span class="pc bpc" id="L245" title="1 of 2 branches missed."> if (StringUtils.isEmpty(task))</span> |
| { |
| // This happens when the job is configured in the Quartz configuration file |
| <span class="fc" id="L248"> task = context.getJobDetail().getKey().getName();</span> |
| } |
| <span class="fc" id="L250"> ScheduledJobLoader.getInstance().exec(this, task);</span> |
| } |
| <span class="nc" id="L252"> catch (Exception e)</span> |
| { |
| <span class="nc" id="L254"> throw new JobExecutionException("Error executing scheduled job #" +</span> |
| <span class="nc" id="L255"> getJobId() + ", task: " + getTask(), e);</span> |
| } |
| finally |
| { |
| <span class="fc" id="L259"> active.compareAndSet(true, false);</span> |
| } |
| <span class="fc" id="L261"> }</span> |
| } |
| </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.12.202403310830</span></div></body></html> |