CVS: plexus-components/scheduler/src/java/org/apache/plexus/scheduler AbstractJob.java,1.1.1.1,1.2 DefaultJobListener.java,1.1.1.1,1.2 DefaultScheduler.java,1.1.1.1,1.2
[email protected] Sun, 27 Apr 2003 20:55:46 -0500
| Newsgroups | gmane.comp.java.plexus.devel |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/plexus/plexus-components/scheduler/src/java/org/apache/plexus/scheduler
In directory eng.werken.com:/tmp/cvs-serv11018/src/java/org/apache/plexus/scheduler
Modified Files:
AbstractJob.java DefaultJobListener.java DefaultScheduler.java
Log Message:
o Conversion to plexus 0.4.
Index: AbstractJob.java
===================================================================
RCS file: /cvsroot/plexus/plexus-components/scheduler/src/java/org/apache/plexus/scheduler/AbstractJob.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- AbstractJob.java 15 Feb 2003 03:55:42 -0000 1.1.1.1
+++ AbstractJob.java 28 Apr 2003 01:55:44 -0000 1.2
@@ -63,9 +63,8 @@
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.configuration.Configuration;
-
-import org.apache.plexus.context.PlexusContext;
-import org.apache.plexus.service.ServiceBroker;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.context.Context;
/**
* Base class from which all <code>Job</code>s running in the
@@ -87,7 +86,7 @@
public static final String CONTEXT = "JOB_CONTEXT";
/** JobDataMap tag for the job's service broker. */
- public static final String SERVICE_BROKER = "JOB_SERVICE_BROKER";
+ public static final String SERVICE_MANAGER = "JOB_SERVICE_MANAGER";
/** JobDataMap tag for the job's configuration. */
public static final String EXECUTION_CONFIGURATION = "JOB_EXECUTION_CONFIGURATION";
@@ -114,15 +113,15 @@
}
/** Get the ServiceBroker. */
- public ServiceBroker getServiceBroker()
+ public ServiceManager getServiceBroker()
{
- return (ServiceBroker) getJobDataMap().get(SERVICE_BROKER);
+ return (ServiceManager) getJobDataMap().get(SERVICE_MANAGER);
}
/** Get the Context. */
- public PlexusContext getContext()
+ public Context getContext()
{
- return (PlexusContext) getJobDataMap().get(CONTEXT);
+ return (Context) getJobDataMap().get(CONTEXT);
}
/** Get the Configuration. */
Index: DefaultJobListener.java
===================================================================
RCS file: /cvsroot/plexus/plexus-components/scheduler/src/java/org/apache/plexus/scheduler/DefaultJobListener.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- DefaultJobListener.java 15 Feb 2003 03:55:42 -0000 1.1.1.1
+++ DefaultJobListener.java 28 Apr 2003 01:55:44 -0000 1.2
@@ -61,11 +61,6 @@
import org.quartz.JobExecutionException;
import org.quartz.JobListener;
-import org.apache.avalon.framework.logger.Logger;
-
-import org.apache.plexus.service.ServiceBroker;
-import org.apache.plexus.context.PlexusContext;
-
/**
* Currently the role this class plays is set the value of the <code>JobDataMap</code>
* in the job so that the convenience methods for accessing the logger, context,
@@ -92,7 +87,7 @@
* <p>
*
* Called by the <code>{@link Scheduler}</code> when a <code>{@link Job}</code>
- * is about to be executed (an associated <code>{@link Trigger}</code> has
+ * is about to be executed (an associated <code>{@link org.quartz.Trigger}</code> has
* occured).</p>
*/
public void jobToBeExecuted(JobExecutionContext context)
Index: DefaultScheduler.java
===================================================================
RCS file: /cvsroot/plexus/plexus-components/scheduler/src/java/org/apache/plexus/scheduler/DefaultScheduler.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- DefaultScheduler.java 15 Feb 2003 03:55:44 -0000 1.1.1.1
+++ DefaultScheduler.java 28 Apr 2003 01:55:44 -0000 1.2
@@ -55,52 +55,37 @@
*
* ----------------------------------------------------------------------------
*/
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.File;
-import java.io.FileFilter;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-import java.util.Vector;
-import java.util.Date;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-import java.util.zip.ZipEntry;
-import java.util.List;
-import java.util.Enumeration;
-import java.net.URL;
-import java.net.URLClassLoader;
-
-import org.quartz.SchedulerException;
-import org.quartz.Job;
-import org.quartz.JobDataMap;
-import org.quartz.JobDetail;
-import org.quartz.Trigger;
-import org.quartz.CronTrigger;
-import org.quartz.SchedulerFactory;
-import org.quartz.impl.StdSchedulerFactory;
-import org.quartz.impl.StdScheduler;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.activity.Startable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.thread.ThreadSafe;
-
-import org.apache.plexus.context.PlexusContext;
-import org.apache.plexus.context.Contextualizable;
-import org.apache.plexus.service.Serviceable;
-import org.apache.plexus.service.ServiceBroker;
-
import org.apache.plexus.classloader.PlexusClassLoader;
+import org.apache.plexus.configuration.DefaultConfigurationBuilder;
+import org.apache.plexus.logging.AbstractLogEnabled;
+import org.quartz.CronTrigger;
+import org.quartz.JobDataMap;
+import org.quartz.JobDetail;
+import org.quartz.SchedulerException;
+import org.quartz.SchedulerFactory;
+import org.quartz.Trigger;
+import org.quartz.impl.StdScheduler;
+import org.quartz.impl.StdSchedulerFactory;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
/**
* Default <code>Scheduler</code> implementation, backed by quartz.
@@ -113,16 +98,13 @@
* @todo logging needs to be reworked: logging per job
*/
public class DefaultScheduler
- extends AbstractLogEnabled
- implements Scheduler, Contextualizable, Configurable, Initializable, Startable, ThreadSafe, Serviceable
+ extends AbstractLogEnabled
+ implements Scheduler, Contextualizable, Configurable, Initializable, Startable, ThreadSafe, Serviceable
{
// ----------------------------------------------------------------------
// Instance members
// ----------------------------------------------------------------------
- /** Plexus context. */
- private PlexusContext context;
-
/** Scheduler properties. */
private Properties schedulerProperties;
@@ -133,17 +115,37 @@
private File jobDirectory;
/** ServiceBroker */
- private ServiceBroker serviceBroker;
+ private ServiceManager serviceManager;
/** Inline job descriptions in the components configuration file **/
private Configuration inlineJobConfigurations;
-
+
+ private File workDirectory;
+
+ private Context context;
+
// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------
/** Construct. */
- public DefaultScheduler() { }
+ public DefaultScheduler()
+ {
+ }
+
+ // ----------------------------------------------------------------------
+ // Accessors
+ // ----------------------------------------------------------------------
+
+ public Context getContext()
+ {
+ return context;
+ }
+
+ public void setContext( Context context )
+ {
+ this.context = context;
+ }
// ----------------------------------------------------------------------
// Instance methods
@@ -152,7 +154,7 @@
/**
* Sets the jobDirectory attribute of the DefaultScheduler object
*/
- public void setJobDirectory(File jobDirectory)
+ public void setJobDirectory( File jobDirectory )
{
this.jobDirectory = jobDirectory;
}
@@ -186,7 +188,7 @@
{
return this.inlineJobConfigurations;
}
-
+
/**
* Gets the schedulerProperties attribute of the DefaultScheduler object
*/
@@ -204,224 +206,218 @@
}
/**
- * Gets the context attribute of the DefaultScheduler object
- */
- PlexusContext getContext()
- {
- return this.context;
- }
-
- /**
- * Gets the serviceBroker attribute of the DefaultScheduler object
+ * Gets the serviceManager attribute of the DefaultScheduler object
*/
- ServiceBroker getServiceBroker()
+ ServiceManager getServiceManager()
{
- return this.serviceBroker;
+ return serviceManager;
}
/**
* Scheduler a new job for the scheduler to run
*
- * @param the JobDetail that the scheduler will run
- * @param the trigger to run the job
+ * @param jobDetail that the scheduler will run
+ * @param trigger to run the job
* @throws SchedulerException If an error occurs while attempting to
* schedule the job.
*/
- public void scheduleJob(JobDetail jobDetail,
- Trigger trigger)
+ public void scheduleJob( JobDetail jobDetail,
+ Trigger trigger )
throws SchedulerException
{
- getLogger().info("scheduling job: " + jobDetail + " " + trigger);
- getScheduler().scheduleJob(jobDetail, trigger);
+ getLogger().info( "scheduling job: " + jobDetail + " " + trigger );
+ getScheduler().scheduleJob( jobDetail, trigger );
}
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // org.apache.plexus.Contextualizable
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ // ----------------------------------------------------------------------
+ // Lifecylce Management
+ // ----------------------------------------------------------------------
- /**
- * Description of the Method
- */
- public void contextualize(PlexusContext context)
+ public void contextualize( Context context )
throws ContextException
{
- getLogger().info("contextualize");
this.context = context;
+
+ try
+ {
+ workDirectory = (File) context.get( "work.directory" );
+ }
+ catch ( ContextException e )
+ {
+ // do nothing.
+ }
}
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // org.apache.plexus.Serviceable
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ public void service( ServiceManager serviceManager )
+ {
+ this.serviceManager = serviceManager;
+ }
+
+ public void configure( Configuration configuration )
+ throws ConfigurationException
+ {
+ getLogger().info( "configure" );
+ configureComponent( configuration );
+ configureScheduler( configuration.getChild( "scheduler", true ) );
+ }
/**
- * Description of the Method
+ * Initialize scheduler component with any available jobs found in jars in
+ * the jobDirectory specified in the configuration file.
*/
- public void service(ServiceBroker serviceBroker)
+ public void initialize()
+ throws Exception
{
- this.serviceBroker = serviceBroker;
+ initializeScheduler();
+ initializeJobsFiles();
+ initializeInlineJobs();
}
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // org.apache.avalon.framework.configuration.Configurable
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
/**
- * Configure the Scheduler
+ * Start the scheduler.
+ *
+ * @throws Exception If an error occurs while attempting to start.
*/
- public void configure(Configuration configuration)
- throws ConfigurationException
+ public void start()
+ throws Exception
{
- getLogger().info("configure");
- configureComponent(configuration);
- configureScheduler(configuration.getChild("scheduler", true));
+ getLogger().info( "starting scheduler" );
+ getScheduler().start();
}
/**
- * Description of the Method
+ * Stop the scheduler.
+ *
+ * @throws Exception If an error occurs while attempting to stop.
*/
- void configureComponent(Configuration configuration)
+ public void stop()
+ throws Exception
+ {
+ getLogger().info( "stopping scheduler" );
+ getScheduler().shutdown();
+ }
+
+ // ----------------------------------------------------------------------
+ // Implementation
+ // ----------------------------------------------------------------------
+
+ void configureComponent( Configuration configuration )
throws ConfigurationException
{
setInlineJobConfigurations( configuration.getChild( "jobs" ) );
- String jobDir = configuration.getChild("job-directory").getValue("");
+ String jobDir = configuration.getChild( "job-directory" ).getValue( "" );
- if ( jobDir == null
- || jobDir.equals(""))
+ if ( jobDir == null
+ ||
+ jobDir.equals( "" ) )
{
- getLogger().info("job directory specified");
+ getLogger().info( "job directory specified" );
return;
}
- File plexusWorkDir = getContext().getWorkDirectory();
-
- if (plexusWorkDir == null)
+ if ( workDirectory == null )
{
- getLogger().warn("no plexus deployment directory - static job jars will not be loaded");
+ getLogger().warn( "no plexus deployment directory - static job jars will not be loaded" );
return;
}
-
- File jobDirectory = new File(plexusWorkDir, jobDir);
+
+ File jobDirectory = new File( workDirectory, jobDir );
if ( jobDirectory.exists() == false )
{
jobDirectory.mkdirs();
- }
-
+ }
+
setJobDirectory( jobDirectory );
}
- /**
- * Description of the Method
- */
- void configureScheduler(Configuration configuration)
+ void configureScheduler( Configuration configuration )
throws ConfigurationException
{
this.schedulerProperties = new Properties();
- Configuration[] propConfigs = configuration.getChildren("property");
+ Configuration[] propConfigs = configuration.getChildren( "property" );
String name = null;
String value = null;
- for (int i = 0; i < propConfigs.length; ++i)
+ for ( int i = 0; i < propConfigs.length; ++i )
{
- name = propConfigs[i].getAttribute("name");
- value = propConfigs[i].getAttribute("value");
+ name = propConfigs[i].getAttribute( "name" );
+ value = propConfigs[i].getAttribute( "value" );
- this.schedulerProperties.setProperty(name, value);
+ this.schedulerProperties.setProperty( name, value );
}
}
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // org.apache.avalon.framework.activity.Initializable
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- /**
- * Initialize scheduler component with any available jobs found in jars in
- * the jobDirectory specified in the configuration file.
- */
- public void initialize()
- throws Exception
- {
- getLogger().info("initialize");
- initializeScheduler();
- initializeJobsFiles();
- initializeInlineJobs();
- }
-
- /**
- * Description of the Method
- */
void initializeScheduler()
throws Exception
{
- SchedulerFactory factory = new StdSchedulerFactory(getSchedulerProperties());
+ SchedulerFactory factory = new StdSchedulerFactory( getSchedulerProperties() );
scheduler = (StdScheduler) factory.getScheduler();
DefaultJobListener jobListener = new DefaultJobListener();
- scheduler.addGlobalJobListener(jobListener);
+ scheduler.addGlobalJobListener( jobListener );
}
- /**
- * Description of the Method
- */
void initializeJobsFiles()
throws Exception
{
File jobDir = getJobDirectory();
- if (jobDir == null)
+ if ( jobDir == null )
{
- getLogger().info("no job directory configured");
+ getLogger().info( "no job directory configured" );
return;
}
File[] jobFiles = jobDir.listFiles(
new FileFilter()
{
- public boolean accept(File file)
+ public boolean accept( File file )
{
- return (file.getName().endsWith(".jar")
+ return ( file.getName().endsWith( ".jar" )
||
- file.getName().endsWith(".zip"));
+ file.getName().endsWith( ".zip" ) );
}
}
- );
+ );
- for (int i = 0; i < jobFiles.length; ++i)
+ for ( int i = 0; i < jobFiles.length; ++i )
{
- initializeJobFile(jobFiles[i]);
+ initializeJobFile( jobFiles[i] );
}
}
/**
* Adds a feature to the JobFile attribute of the DefaultScheduler object
*/
- public void addJobFile(File jobFile)
+ public void addJobFile( File jobFile )
throws Exception
{
- getLogger().info("adding job file: " + jobFile.getPath());
- initializeJobFile(jobFile);
+ getLogger().info( "adding job file: " + jobFile.getPath() );
+ initializeJobFile( jobFile );
}
/**
* Description of the Method
*/
- void initializeJobFile(File jobFile)
+ void initializeJobFile( File jobFile )
throws Exception
{
- JarFile jarFile = new JarFile(jobFile);
+ JarFile jarFile = new JarFile( jobFile );
Enumeration entryEnum = jarFile.entries();
ZipEntry eachEntry = null;
- while (entryEnum.hasMoreElements())
+ while ( entryEnum.hasMoreElements() )
{
eachEntry = (ZipEntry) entryEnum.nextElement();
- if (eachEntry.getName().equals("jobs.xml"))
+ if ( eachEntry.getName().equals( "jobs.xml" ) )
{
- initializeJobFile(jobFile,jarFile.getInputStream(eachEntry));
+ initializeJobFile( jobFile, jarFile.getInputStream( eachEntry ) );
break;
}
}
@@ -430,15 +426,15 @@
/**
* Description of the Method
*/
- void initializeJobFile(File jobFile,
- InputStream jobsConfigStream)
+ void initializeJobFile( File jobFile,
+ InputStream jobsConfigStream )
throws Exception
{
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
- getLogger().info("reading jobs.xml");
+ getLogger().info( "reading jobs.xml" );
- Configuration jobsConfig = builder.build(jobsConfigStream);
+ Configuration jobsConfig = builder.build( jobsConfigStream );
jobsConfigStream.close();
@@ -446,9 +442,9 @@
// PlexusClassLoader brought to life by the ResourceManager.
// This will be cleaner with Classworlds but this works just
// fine for now.
- ClassLoader parent = DefaultScheduler.class.getClassLoader();
- PlexusClassLoader loader = new PlexusClassLoader(parent);
- loader.addURL(jobFile.toURL());
+ ClassLoader parent = DefaultScheduler.class.getClassLoader();
+ PlexusClassLoader loader = new PlexusClassLoader( parent );
+ loader.addURL( jobFile.toURL() );
initializeJobs( loader, jobsConfig, jobFile.toString() );
}
@@ -469,7 +465,7 @@
initializeJobs( loader, getInlineJobConfigurations(), "inline source" );
}
-
+
/**
* Initializes a group of jobs.
*
@@ -487,7 +483,7 @@
{
try
{
- initializeJob( loader, jobConfigs[ i ] );
+ initializeJob( loader, jobConfigs[i] );
}
catch ( Exception e )
{
@@ -495,73 +491,45 @@
}
}
}
-
+
/**
* Description of the Method
*/
- void initializeJob(ClassLoader loader,
- Configuration jobConfig)
+ void initializeJob( ClassLoader loader,
+ Configuration jobConfig )
throws Exception
{
- String name = jobConfig.getChild("name").getValue();
- String group = jobConfig.getChild("group").getValue();
- String className = jobConfig.getChild("class").getValue();
- String cronSpec = jobConfig.getChild("cron-spec").getValue();
- Configuration jobExecutionConfiguration = jobConfig.getChild("configuration");
-
- getLogger().info("new job: " + group + "/" + name + " " + className + " " + cronSpec);
+ String name = jobConfig.getChild( "name" ).getValue();
+ String group = jobConfig.getChild( "group" ).getValue();
+ String className = jobConfig.getChild( "class" ).getValue();
+ String cronSpec = jobConfig.getChild( "cron-spec" ).getValue();
+ Configuration jobExecutionConfiguration = jobConfig.getChild( "configuration" );
- Class jobClass = loader.loadClass(className);
+ getLogger().info( "new job: " + group + "/" + name + " " + className + " " + cronSpec );
- JobDetail jobDetail = new JobDetail(name, group, jobClass);
+ Class jobClass = loader.loadClass( className );
+
+ JobDetail jobDetail = new JobDetail( name, group, jobClass );
JobDataMap jobDataMap = jobDetail.getJobDataMap();
-
- jobDataMap.put(AbstractJob.LOGGER, getLogger());
- jobDataMap.put(AbstractJob.CONTEXT, getContext());
- jobDataMap.put(AbstractJob.SERVICE_BROKER, getServiceBroker());
- jobDataMap.put(AbstractJob.EXECUTION_CONFIGURATION, jobExecutionConfiguration);
-
-
+
+ jobDataMap.put( AbstractJob.LOGGER, getLogger() );
+ jobDataMap.put( AbstractJob.CONTEXT, getContext() );
+ jobDataMap.put( AbstractJob.SERVICE_MANAGER, getServiceManager() );
+ jobDataMap.put( AbstractJob.EXECUTION_CONFIGURATION, jobExecutionConfiguration );
+
+
// Allow transient data in the job data map. This will make sure
// that non-serializable objects are nulled out before persistence
// is attempted in order to prevent errors.
- jobDataMap.setAllowsTransientData(true);
-
- CronTrigger trigger = new CronTrigger(name,
- group,
- name,
- group,
- cronSpec);
-
- scheduleJob(jobDetail, trigger);
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- // org.apache.avalon.framework.activity.Startable
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ jobDataMap.setAllowsTransientData( true );
- /**
- * Start the scheduler.
- *
- * @throws Exception If an error occurs while attempting to start.
- */
- public void start()
- throws Exception
- {
- getLogger().info("starting scheduler");
- getScheduler().start();
- }
+ CronTrigger trigger = new CronTrigger( name,
+ group,
+ name,
+ group,
+ cronSpec );
- /**
- * Stop the scheduler.
- *
- * @throws Exception If an error occurs while attempting to stop.
- */
- public void stop()
- throws Exception
- {
- getLogger().info("stopping scheduler");
- getScheduler().shutdown();
+ scheduleJob( jobDetail, trigger );
}
}