cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From giac...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/cron/java/org/apache/cocoon/components/cron QuartzJobScheduler.java
Date Thu, 04 Sep 2003 15:57:41 GMT
giacomo     2003/09/04 08:57:41

  Modified:    src/blocks/cron/java/org/apache/cocoon/components/cron
                        QuartzJobScheduler.java
  Log:
  added management functionallity
  
  Revision  Changes    Path
  1.4       +66 -23    cocoon-2.1/src/blocks/cron/java/org/apache/cocoon/components/cron/QuartzJobScheduler.java
  
  Index: QuartzJobScheduler.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/cron/java/org/apache/cocoon/components/cron/QuartzJobScheduler.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -d -b -u -r1.3 -r1.4
  --- QuartzJobScheduler.java	4 Sep 2003 12:42:44 -0000	1.3
  +++ QuartzJobScheduler.java	4 Sep 2003 15:57:41 -0000	1.4
  @@ -51,14 +51,11 @@
   package org.apache.cocoon.components.cron;
   
   import java.text.ParseException;
  +import java.util.Arrays;
   import java.util.Date;
   import java.util.Map;
   import java.util.NoSuchElementException;
   
  -import EDU.oswego.cs.dl.util.concurrent.BoundedBuffer;
  -import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
  -import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
  -
   import org.apache.avalon.framework.CascadingException;
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Startable;
  @@ -73,9 +70,15 @@
   import org.apache.avalon.framework.service.Serviceable;
   import org.apache.avalon.framework.thread.ThreadSafe;
   import org.quartz.*;
  +
   import org.quartz.impl.DirectSchedulerFactory;
  +
   import org.quartz.simpl.RAMJobStore;
   
  +import EDU.oswego.cs.dl.util.concurrent.BoundedBuffer;
  +import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
  +import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
  +
   
   /**
    * This component can either schedule jobs or directly execute one.
  @@ -85,9 +88,8 @@
    * @since 2.1.1
    */
   public class QuartzJobScheduler
  -    extends AbstractLogEnabled
  -    implements JobScheduler, Component, ThreadSafe, Serviceable, Configurable, Startable,
Disposable {
  -    
  +extends AbstractLogEnabled
  +implements JobScheduler, Component, ThreadSafe, Serviceable, Configurable, Startable, Disposable
{
       /** ThreadPool policy RUN */
       private static final String POLICY_RUN = "RUN";
   
  @@ -104,31 +106,34 @@
       private static final String POLICY_DISCARD_OLDEST = "DISCARDOLDEST";
   
       /** Map key for the component role */
  -    public static final String DATA_MAP_ROLE = "QuartzJobScheduler.ROLE";
  +    static final String DATA_MAP_ROLE = "QuartzJobScheduler.ROLE";
   
       /** Map key for the job object */
  -    public static final String DATA_MAP_OBJECT = "QuartzJobScheduler.Object";
  +    static final String DATA_MAP_OBJECT = "QuartzJobScheduler.Object";
   
       /** Map key for the job name */
  -    public static final String DATA_MAP_NAME = "QuartzJobScheduler.JobName";
  +    static final String DATA_MAP_NAME = "QuartzJobScheduler.JobName";
   
       /** Map key for the service manager */
  -    public static final String DATA_MAP_MANAGER = "QuartzJobScheduler.ServiceManager";
  +    static final String DATA_MAP_MANAGER = "QuartzJobScheduler.ServiceManager";
   
       /** Map key for the logger */
  -    public static final String DATA_MAP_LOGGER = "QuartzJobScheduler.Logger";
  +    static final String DATA_MAP_LOGGER = "QuartzJobScheduler.Logger";
   
       /** Map key for the concurrent run property */
  -    public static final String DATA_MAP_RUN_CONCURRENT = "QuartzJobScheduler.RunConcurrently";
  +    static final String DATA_MAP_RUN_CONCURRENT = "QuartzJobScheduler.RunConcurrently";
   
       /** Map key for additional Parameters */
  -    public static final String DATA_MAP_PARAMETERS = "QuartzJobScheduler.Parameters";
  +    static final String DATA_MAP_PARAMETERS = "QuartzJobScheduler.Parameters";
   
       /** Map key for additional Object Map */
  -    public static final String DATA_MAP_OBJECTMAP = "QuartzJobScheduler.Map";
  +    static final String DATA_MAP_OBJECTMAP = "QuartzJobScheduler.Map";
  +
  +    /** Map key for the last JobExecutionContext */
  +    static final String DATA_MAP_JOB_EXECUTION_CONTEXT = "QuartzJobScheduler.JobExecutionContext";
   
       /** The group name */
  -    private static final String DEFAULT_QUARTZ_JOB_GROUP = "Cocoon";
  +    static final String DEFAULT_QUARTZ_JOB_GROUP = "Cocoon";
   
       /** The PooledExecutor instance */
       private PooledExecutor m_executor;
  @@ -142,6 +147,34 @@
       /** Should we wait for running jobs to terminate on shutdown ? */
       private boolean m_shutdownGraceful;
   
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.components.cron.JobScheduler#getJobNames()
  +     */
  +    public String[] getJobNames() {
  +        try {
  +            final String[] names = m_scheduler.getJobNames(DEFAULT_QUARTZ_JOB_GROUP);
  +            Arrays.sort(names);
  +
  +            return names;
  +        } catch (final SchedulerException se) {
  +            getLogger().error("could not gather job names", se);
  +        }
  +
  +        return new String[0];
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.components.cron.JobScheduler#getSchedulerEntry(java.lang.String)
  +     */
  +    public JobSchedulerEntry getJobSchedulerEntry(String jobname) {
  +        try {
  +            return new QuartzJobSchedulerEntry(jobname, m_scheduler);
  +        } catch (final Exception e) {
  +            getLogger().error("cannot create QuartzJobSchedulerEntry", e);
  +        }
  +
  +        return null;
  +    }
   
       /**
        * Schedule a period job. Note that if a Job already has same name then it is overwritten.
  @@ -266,6 +299,7 @@
        */
       public boolean fireJob(final String jobrole) {
           Object job = null;
  +
           try {
               job = m_manager.lookup(jobrole);
   
  @@ -273,7 +307,7 @@
           } catch (final ServiceException se) {
               getLogger().error("cannot fire job " + jobrole, se);
           } finally {
  -            m_manager.release( job );
  +            m_manager.release(job);
           }
   
           return false;
  @@ -297,6 +331,7 @@
       public boolean fireJob(final String jobrole, final Parameters params, final Map objects)
       throws CascadingException {
           Object job = null;
  +
           try {
               job = m_manager.lookup(jobrole);
   
  @@ -308,7 +343,7 @@
           } catch (final ServiceException se) {
               getLogger().error("cannot fire job " + jobrole, se);
           } finally {
  -            m_manager.release( job );
  +            m_manager.release(job);
           }
   
           return false;
  @@ -358,8 +393,16 @@
       public void removeJob(final String name)
       throws NoSuchElementException {
           try {
  -            m_scheduler.deleteJob(name, DEFAULT_QUARTZ_JOB_GROUP);
  +            if( m_scheduler.deleteJob(name, DEFAULT_QUARTZ_JOB_GROUP) )
  +            {
  +                getLogger().info( "job " + name + " removed by request" );
  +            }
  +            else
  +            {
  +                getLogger().error( "couldn't remove requested job " + name  );
  +            }
           } catch (final SchedulerException se) {
  +            getLogger().error( "cannot remove job " + name, se );
               throw new NoSuchElementException(se.getMessage());
           }
       }
  
  
  

Mime
View raw message