View Javadoc

1   /**
2    * Copyright 2005-2006 the original author or authors.
3    *
4    * Licensed under the Gnu General Pubic License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    *
8    *      http://www.opensource.org/licenses/gpl-license.php
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13   * See the Gnu General Public License for more details.
14   */
15  package org.figure8.join.services.scheduling;
16  
17  import org.figure8.join.util.LogUtil;
18  
19  import org.apache.commons.logging.Log;
20  import org.quartz.Job;
21  import org.quartz.JobExecutionContext;
22  
23  import java.util.List;
24  import java.util.ArrayList;
25  import java.util.Iterator;
26  /**
27   * This is a simple, dummy Quartz job that just echoes job execution context using
28   * commons logging and store processed context into a list. List can be flushed using
29   * <code>flushContexts()</code> method. This implementation is suited for
30   * tests and debugging mainly.
31   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
32   * @version $Revision: 1.3 $
33   */
34  public class EchoQuartzJob implements Job{
35  
36     // Static -------------------------------------------------------------------
37  
38     /** Commons logger. */
39     protected static Log log = LogUtil.getLog(EchoQuartzJob.class);
40  
41  
42     // Attributes ---------------------------------------------------------------
43  
44     /** List of processed contexts */
45     private List contexts = new ArrayList();
46  
47  
48     // Public -------------------------------------------------------------------
49  
50     /** @return All the contexts on the list so far, clearing the buffer. */
51     public synchronized List flushContexts(){
52        List answer = new ArrayList(contexts);
53        contexts.clear();
54        return answer;
55     }
56  
57     /** @return true if job has been triggered (ie: has received context), false otherwise. */
58     public boolean hasBeenTriggered(){
59        return !contexts.isEmpty();
60     }
61  
62  
63     // Implementation of Job ----------------------------------------------------
64  
65     /**
66      * Simply output the context of execution context.
67      * @param context The Job exception context
68      */
69     public void execute(JobExecutionContext context){
70        log.info("[" + this + "] Processing the context: " + context);
71        // Log the job parameters found into context.
72        Iterator keys = context.getJobDetail().getJobDataMap().keySet().iterator();
73        while (keys != null && keys.hasNext()){
74           Object key = keys.next();
75           Object value = context.getJobDetail().getJobDataMap().get(key);
76           log.info("[" + this + "] Found the parameter " + key + "[" + value + "]");
77        }
78        contexts.add(context);
79     }
80  }