bloritsch 2002/10/24 14:39:37
Modified: infomover/src/java/org/apache/infomover/jobmanager/impl
JobImpl.java JobManagerImpl.java
infomover/src/java/org/apache/infomover/transaction
Transaction.java
Log:
More work
Revision Changes Path
1.5 +1 -1
jakarta-avalon-apps/infomover/src/java/org/apache/infomover/jobmanager/impl/JobImpl.java
Index: JobImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-apps/infomover/src/java/org/apache/infomover/jobmanager/impl/JobImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JobImpl.java 30 Sep 2002 15:59:25 -0000 1.4
+++ JobImpl.java 24 Oct 2002 21:39:37 -0000 1.5
@@ -194,7 +194,7 @@
public void initialize()
throws Exception
{
- m_isScheduled = m_config.getChild( "schedule" ) != null;
+ m_isScheduled = m_config.getChild( "schedule", false ) != null;
Configuration inputConfig = m_config.getChild( "input" );
Configuration[] manipulatorConfigs = m_config.getChildren( "manipulator" );
Configuration outputConfig = m_config.getChild( "output" );
1.8 +205 -12
jakarta-avalon-apps/infomover/src/java/org/apache/infomover/jobmanager/impl/JobManagerImpl.java
Index: JobManagerImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-apps/infomover/src/java/org/apache/infomover/jobmanager/impl/JobManagerImpl.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- JobManagerImpl.java 16 Oct 2002 12:46:07 -0000 1.7
+++ JobManagerImpl.java 24 Oct 2002 21:39:37 -0000 1.8
@@ -54,7 +54,15 @@
import org.apache.avalon.framework.configuration.*;
import org.apache.avalon.framework.service.*;
import org.apache.avalon.framework.logger.*;
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.context.DefaultContext;
import org.apache.avalon.cornerstone.services.scheduler.TimeScheduler;
+import org.apache.avalon.cornerstone.services.scheduler.TimeTriggerFactory;
+import org.apache.avalon.cornerstone.services.scheduler.Target;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collections;
/**
* The <code>JobManager</code> interface exposes how we control the JobManager
@@ -69,10 +77,19 @@
*/
public class JobManagerImpl
extends AbstractLogEnabled
-implements JobManager, JobManagerMBean, Serviceable
+implements JobManager, JobManagerMBean, Serviceable, Target
{
- private TimeScheduler m_scheduler = null;
- private ConnectionManager m_connections = null;
+ private TimeTriggerFactory m_triggerFactory = null;
+ private TimeScheduler m_scheduler = null;
+ private ConnectionManager m_connections = null;
+ private Map m_jobs = null;
+ private ServiceManager m_manager = null;
+
+ public void JobManagerImpl()
+ {
+ m_jobs = Collections.synchronizedMap( new HashMap() );
+ m_triggerFactory = new TimeTriggerFactory();
+ }
/**
*
@@ -83,11 +100,12 @@
public void service( final ServiceManager serviceManager )
throws ServiceException
{
+ m_manager = serviceManager;
getLogger().debug( "Getting required services..." );
- m_scheduler = (TimeScheduler)serviceManager.lookup( TimeScheduler.ROLE );
+ m_scheduler = (TimeScheduler)m_manager.lookup( TimeScheduler.ROLE );
getLogger().debug( "... got TimeScheduler ..." );
- m_connections = (ConnectionManager)serviceManager.lookup(
ConnectionManager.ROLE );
+ m_connections = (ConnectionManager)m_manager.lookup( ConnectionManager.ROLE
);
getLogger().debug( "... got ConnectionManager ... done." );
}
@@ -106,7 +124,33 @@
*/
public String addJob( Configuration config ) throws JobException
{
- throw new UnsupportedOperationException();
+ Job job = createJob( config );
+ String jobName = null;
+
+ Configuration schedule = config.getChild( "schedule", false );
+ if ( null != schedule )
+ {
+ try
+ {
+ jobName = config.getAttribute("name");
+ m_scheduler.addTrigger( jobName,
+ m_triggerFactory.createTimeTrigger(
schedule ),
+ this );
+ }
+ catch ( ConfigurationException ce )
+ {
+ destroyJob( job );
+ throw new JobException( "Could not schedule the job \"" + jobName +
"\", removing it" );
+ }
+ }
+ else
+ {
+ // connection handling
+ }
+
+ m_jobs.put( jobName, job );
+
+ return jobName;
}
/**
@@ -120,7 +164,22 @@
*/
public void removeJob( String name )
{
- throw new UnsupportedOperationException();
+ Job job = (Job) m_jobs.get( name );
+
+ if ( null != job )
+ {
+ // verifyNoDependencies( job );
+ m_jobs.remove( name );
+
+ try
+ {
+ destroyJob( job );
+ }
+ catch( Exception e )
+ {
+ getLogger().error( "There was a problem destroying the removed
job.", e );
+ }
+ }
}
/**
@@ -131,12 +190,16 @@
*
* @param name The name of the job we want to remove.
*
- * @throws JobException if there is no job by the name or there is a problem
- * running the job.
+ * @throws JobException if there is no job by the name.
*/
public void cancelJob( String name ) throws JobException
{
- throw new UnsupportedOperationException();
+ Job job = lookupJob( name );
+
+ if ( job.isRunning() )
+ {
+ job.cancel();
+ }
}
/**
@@ -153,7 +216,23 @@
*/
public void executeJob( String name ) throws JobException
{
- throw new UnsupportedOperationException();
+ Job job = lookupJob( name );
+
+ if ( ! job.isRunning() )
+ {
+ try
+ {
+ job.start();
+ }
+ catch ( JobException je )
+ {
+ throw je;
+ }
+ catch ( Exception e )
+ {
+ throw new JobException( e.getMessage() );
+ }
+ }
}
/**
@@ -170,7 +249,36 @@
*/
public void executeOneOff( Configuration config ) throws JobException
{
- throw new UnsupportedOperationException();
+ Job job = createJob( config );
+
+ try
+ {
+ job.start();
+ }
+ catch ( JobException je )
+ {
+ throw je;
+ }
+ catch ( Exception e )
+ {
+ getLogger().error( "Could not run job", e );
+ throw new JobException( e.getMessage() );
+ }
+
+ while( job.isRunning() )
+ {
+ try
+ {
+ wait( 1000 );
+ }
+ catch ( InterruptedException ie )
+ {
+ getLogger().debug("Job interrupted while waiting for it to finnish,
cancelling the one-off job");
+ job.cancel();
+ }
+ }
+
+ destroyJob( job );
}
/**
@@ -185,5 +293,90 @@
public JobDescriptor[] availableJobs()
{
throw new UnsupportedOperationException();
+ }
+
+ public void targetTriggered( String name )
+ {
+ if ( "JobManager".equals( name ) )
+ {
+ checkDirectory();
+ }
+ else
+ {
+ Job job = (Job) m_jobs.get( name );
+
+ if ( null == job )
+ {
+ getLogger().error( "The scheduled job \"" + name + "\" does not
exist. I am removing it from the scheduler");
+ m_scheduler.removeTrigger( name );
+ }
+
+ try
+ {
+ executeJob( name );
+ }
+ catch ( JobException je )
+ {
+ getLogger().error( "Job \"" + name + "\" could not be executed",
je);
+ }
+ }
+ }
+
+ private void checkDirectory()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ private Job createJob( Configuration config )
+ throws JobException
+ {
+ Job job = new JobImpl();
+
+ try
+ {
+ String jobName = config.getAttribute( "name" );
+ ContainerUtil.enableLogging( job, getLogger().getChildLogger( jobName )
);
+ ContainerUtil.contextualize( job, new DefaultContext() );
+ ContainerUtil.configure( job, config );
+ ContainerUtil.service( job, m_manager );
+ ContainerUtil.initialize( job );
+ }
+ catch ( Exception e )
+ {
+ getLogger().warn( "Could not instantiate the job", e );
+ throw new JobException( e.getMessage() );
+ }
+
+ return job;
+ }
+
+ private void destroyJob( Job job )
+ throws JobException
+ {
+ try
+ {
+ ContainerUtil.shutdown( job );
+ }
+ catch ( JobException je )
+ {
+ throw je;
+ }
+ catch ( Exception e )
+ {
+ getLogger().error( "Error destroying job", e );
+ throw new JobException( e.getMessage() );
+ }
+ }
+
+ private Job lookupJob( String name )
+ throws JobException
+ {
+ Job job = (Job) m_jobs.get( name );
+ if ( null == job )
+ {
+ throw new JobException( "There is no job matching the name \"" + name +
"\"" );
+ }
+
+ return job;
}
}
1.6 +8 -0
jakarta-avalon-apps/infomover/src/java/org/apache/infomover/transaction/Transaction.java
Index: Transaction.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-apps/infomover/src/java/org/apache/infomover/transaction/Transaction.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Transaction.java 4 Sep 2002 15:26:06 -0000 1.5
+++ Transaction.java 24 Oct 2002 21:39:37 -0000 1.6
@@ -110,6 +110,14 @@
}
/**
+ * Remove a Record from the list of Records.
+ */
+ public Record removeRecord( Record rec )
+ {
+ return removeRecord( m_records.indexOf( rec ) );
+ }
+
+ /**
* Return the specified Record
*/
public Record getRecord( int position )
--
To unsubscribe, e-mail: <mailto:avalon-cvs-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@;jakarta.apache.org>