| <?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=""><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>JobQueue.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">JobQueue.java</span></div><h1>JobQueue.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.List; |
| import java.util.Vector; |
| import java.util.concurrent.ConcurrentSkipListSet; |
| |
| import org.apache.turbine.util.TurbineException; |
| |
| /** |
| * Queue for the scheduler. |
| * |
| * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a> |
| * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a> |
| * @version $Id: JobQueue.java 615328 2008-01-25 20:25:05Z tv $ |
| * @param <J> a specialized job entry type |
| */ |
| public class JobQueue<J extends JobEntry> |
| { |
| /** |
| * The queue of <code>JobEntry</code> objects. |
| */ |
| <span class="nc" id="L41"> private ConcurrentSkipListSet<J> queue = null;</span> |
| |
| /** |
| * Creates a new instance. |
| */ |
| public JobQueue() |
| <span class="nc" id="L47"> {</span> |
| <span class="nc" id="L48"> queue = new ConcurrentSkipListSet<J>((o1, o2) -> Long.compare(o1.getNextRuntime(), o2.getNextRuntime()));</span> |
| <span class="nc" id="L49"> }</span> |
| |
| /** |
| * Return the next job off the top of the queue and remove it from the queue, or <code>null</code> if |
| * there are no jobs in the queue. |
| * |
| * @return The next job in the queue. |
| */ |
| public J getNext() |
| { |
| <span class="nc" id="L59"> return queue.pollFirst();</span> |
| } |
| |
| /** |
| * Return the next job of the top of the queue or <code>null</code> if |
| * there are no jobs in the queue. |
| * |
| * @return The next job in the queue. |
| */ |
| public J getFirst() |
| { |
| <span class="nc bnc" id="L70" title="All 2 branches missed."> return !queue.isEmpty()? queue.first(): null;</span> |
| } |
| |
| /** |
| * Return a specific job. |
| * |
| * @param je The JobEntry we are looking for. Falls back to check job id, if job was not found. |
| * @return A JobEntry. |
| */ |
| public J getJob(J je) |
| { |
| <span class="nc bnc" id="L81" title="All 2 branches missed."> if (je != null)</span> |
| { |
| <span class="nc" id="L83"> J job = queue.floor(je);</span> |
| <span class="nc bnc" id="L84" title="All 2 branches missed."> if (je.equals(job))</span> |
| { |
| <span class="nc" id="L86"> return job;</span> |
| } |
| <span class="nc bnc" id="L88" title="All 2 branches missed."> for (J jobEntry : list())</span> |
| { |
| <span class="nc bnc" id="L90" title="All 2 branches missed."> if (jobEntry.getJobId() == je.getJobId())</span> |
| { |
| <span class="nc" id="L92"> return jobEntry;</span> |
| } |
| <span class="nc" id="L94"> } </span> |
| } |
| <span class="nc" id="L96"> return null;</span> |
| } |
| |
| /** |
| * List jobs in the queue. This is used by the scheduler UI. |
| * |
| * @return A Vector of <code>JobEntry</code> objects. |
| */ |
| public Vector<J> list() |
| { |
| <span class="nc bnc" id="L106" title="All 2 branches missed."> if (!queue.isEmpty())</span> |
| { |
| <span class="nc" id="L108"> return new Vector<>(queue);</span> |
| } |
| else |
| { |
| <span class="nc" id="L112"> return null;</span> |
| } |
| } |
| |
| /** |
| * Add a job to the queue. |
| * |
| * @param je A JobEntry job. |
| */ |
| public void add(J je) |
| { |
| <span class="nc" id="L123"> queue.add(je);</span> |
| <span class="nc" id="L124"> }</span> |
| |
| /** |
| * Batch load jobs. Retains any already enqueued jobs. Called on |
| * <code>SchedulerService</code> start-up. |
| * |
| * @param jobEntries A list of the <code>JobEntry</code> objects to load. |
| */ |
| public void batchLoad(List<J> jobEntries) |
| { |
| <span class="nc bnc" id="L134" title="All 2 branches missed."> if (jobEntries != null)</span> |
| { |
| <span class="nc" id="L136"> queue.addAll(jobEntries);</span> |
| } |
| <span class="nc" id="L138"> }</span> |
| |
| /** |
| * Remove a job from the queue. |
| * |
| * @param je A JobEntry with the job to remove. |
| */ |
| public void remove(J je) |
| { |
| <span class="nc" id="L147"> queue.remove(je);</span> |
| <span class="nc" id="L148"> }</span> |
| |
| /** |
| * Modify a job on the queue. |
| * |
| * @param je A JobEntry with the job to modify |
| * @throws TurbineException if the runtime calculation fails |
| */ |
| public void modify(J je) throws TurbineException |
| { |
| <span class="nc" id="L158"> remove(je);</span> |
| <span class="nc" id="L159"> je.calcRunTime();</span> |
| <span class="nc" id="L160"> add(je);</span> |
| <span class="nc" id="L161"> }</span> |
| |
| /** |
| * Update the job for its next run time. |
| * |
| * @param je A JobEntry to be updated. |
| * @throws TurbineException a generic exception. |
| */ |
| public void updateQueue(J je) |
| throws TurbineException |
| { |
| <span class="nc" id="L172"> modify(je);</span> |
| <span class="nc" id="L173"> }</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> |