Browse Source

Update to use new ExecutionFrame construct.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269152 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 24 years ago
parent
commit
20f90e4e0c
2 changed files with 44 additions and 35 deletions
  1. +11
    -9
      proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/AspectAwareExecutor.java
  2. +33
    -26
      proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/DefaultExecutor.java

+ 11
- 9
proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/AspectAwareExecutor.java View File

@@ -14,6 +14,7 @@ import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.configuration.DefaultConfiguration; import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.log.Logger;
import org.apache.myrmidon.api.Task; import org.apache.myrmidon.api.Task;
import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.api.TaskContext;
import org.apache.myrmidon.api.TaskException; import org.apache.myrmidon.api.TaskException;
@@ -48,12 +49,12 @@ public class AspectAwareExecutor
m_aspectManager = (AspectManager)componentManager.lookup( AspectManager.ROLE ); m_aspectManager = (AspectManager)componentManager.lookup( AspectManager.ROLE );
} }


public void execute( final Configuration taskModel, final TaskContext context )
public void execute( final Configuration taskModel, final ExecutionFrame frame )
throws TaskException throws TaskException
{ {
try try
{ {
executeTask( taskModel, context );
executeTask( taskModel, frame );
} }
catch( final TaskException te ) catch( final TaskException te )
{ {
@@ -64,29 +65,30 @@ public class AspectAwareExecutor
} }
} }


private void executeTask( Configuration taskModel, final TaskContext context )
private void executeTask( Configuration taskModel, final ExecutionFrame frame )
throws TaskException throws TaskException
{ {
taskModel = getAspectManager().preCreate( taskModel ); taskModel = getAspectManager().preCreate( taskModel );
taskModel = prepareAspects( taskModel ); taskModel = prepareAspects( taskModel );


getLogger().debug( "Pre-Create" ); getLogger().debug( "Pre-Create" );
final Task task = createTask( taskModel.getName() );
final Task task = createTask( taskModel.getName(), frame );
getAspectManager().postCreate( task ); getAspectManager().postCreate( task );


getLogger().debug( "Pre-Loggable" ); getLogger().debug( "Pre-Loggable" );
getAspectManager().preLoggable( getLogger() );
setupLogger( task );
final Logger logger = frame.getLogger();
getAspectManager().preLoggable( logger );
doLoggable( task, taskModel, logger );


getLogger().debug( "Contextualizing" ); getLogger().debug( "Contextualizing" );
doContextualize( task, taskModel, context );
doContextualize( task, taskModel, frame.getContext() );


getLogger().debug( "Composing" ); getLogger().debug( "Composing" );
doCompose( task, taskModel );
doCompose( task, taskModel, frame.getComponentManager() );


getLogger().debug( "Configuring" ); getLogger().debug( "Configuring" );
getAspectManager().preConfigure( taskModel ); getAspectManager().preConfigure( taskModel );
doConfigure( task, taskModel, context );
doConfigure( task, taskModel, frame.getContext() );


getLogger().debug( "Initializing" ); getLogger().debug( "Initializing" );
doInitialize( task, taskModel ); doInitialize( task, taskModel );


+ 33
- 26
proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/DefaultExecutor.java View File

@@ -35,9 +35,6 @@ public class DefaultExecutor
implements Executor, Composable implements Executor, Composable
{ {
private Configurer m_configurer; private Configurer m_configurer;
private TypeFactory m_factory;

private ComponentManager m_componentManager;


/** /**
* Retrieve relevent services needed to deploy. * Retrieve relevent services needed to deploy.
@@ -48,34 +45,24 @@ public class DefaultExecutor
public void compose( final ComponentManager componentManager ) public void compose( final ComponentManager componentManager )
throws ComponentException throws ComponentException
{ {
//cache CM so it can be used while executing tasks
m_componentManager = componentManager;

m_configurer = (Configurer)componentManager.lookup( Configurer.ROLE ); m_configurer = (Configurer)componentManager.lookup( Configurer.ROLE );

final TypeManager typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE );
try { m_factory = typeManager.getFactory( Task.ROLE ); }
catch( final TypeException te )
{
throw new ComponentException( "Unable to retrieve factory from TypeManager", te );
}
} }


public void execute( final Configuration taskModel, final TaskContext context )
public void execute( final Configuration taskModel, final ExecutionFrame frame )
throws TaskException throws TaskException
{ {
getLogger().debug( "Creating" ); getLogger().debug( "Creating" );
final Task task = createTask( taskModel.getName() );
setupLogger( task );
final Task task = createTask( taskModel.getName(), frame );
doLoggable( task, taskModel, frame.getLogger() );


getLogger().debug( "Contextualizing" ); getLogger().debug( "Contextualizing" );
doContextualize( task, taskModel, context );
doContextualize( task, taskModel, frame.getContext() );


getLogger().debug( "Composing" ); getLogger().debug( "Composing" );
doCompose( task, taskModel );
doCompose( task, taskModel, frame.getComponentManager() );


getLogger().debug( "Configuring" ); getLogger().debug( "Configuring" );
doConfigure( task, taskModel, context );
doConfigure( task, taskModel, frame.getContext() );


getLogger().debug( "Initializing" ); getLogger().debug( "Initializing" );
doInitialize( task, taskModel ); doInitialize( task, taskModel );
@@ -88,12 +75,13 @@ public class DefaultExecutor
doDispose( task, taskModel ); doDispose( task, taskModel );
} }


protected final Task createTask( final String name )
protected final Task createTask( final String name, final ExecutionFrame frame )
throws TaskException throws TaskException
{ {
try try
{ {
return (Task)m_factory.create( name );
final TypeFactory factory = frame.getTypeManager().getFactory( Task.ROLE );
return (Task)factory.create( name );
} }
catch( final TypeException te ) catch( final TypeException te )
{ {
@@ -111,16 +99,18 @@ public class DefaultExecutor
{ {
throw new TaskException( "Error configuring task " + taskModel.getName() + " at " + throw new TaskException( "Error configuring task " + taskModel.getName() + " at " +
taskModel.getLocation() + "(Reason: " + taskModel.getLocation() + "(Reason: " +
throwable.getMessage() + ")" );
throwable.getMessage() + ")", throwable );
} }
} }


protected final void doCompose( final Task task, final Configuration taskModel )
protected final void doCompose( final Task task,
final Configuration taskModel,
final ComponentManager componentManager )
throws TaskException throws TaskException
{ {
if( task instanceof Composable ) if( task instanceof Composable )
{ {
try { ((Composable)task).compose( m_componentManager ); }
try { ((Composable)task).compose( componentManager ); }
catch( final Throwable throwable ) catch( final Throwable throwable )
{ {
throw new TaskException( "Error composing task " + taskModel.getName() + " at " + throw new TaskException( "Error composing task " + taskModel.getName() + " at " +
@@ -131,8 +121,8 @@ public class DefaultExecutor
} }


protected final void doContextualize( final Task task, protected final void doContextualize( final Task task,
final Configuration taskModel,
final TaskContext context )
final Configuration taskModel,
final TaskContext context )
throws TaskException throws TaskException
{ {
try try
@@ -165,6 +155,23 @@ public class DefaultExecutor
} }
} }


protected final void doLoggable( final Task task,
final Configuration taskModel,
final Logger logger )
throws TaskException
{
if( task instanceof Loggable )
{
try { ((Loggable)task).setLogger( logger ); }
catch( final Throwable throwable )
{
throw new TaskException( "Error setting logger for task " + taskModel.getName() +
" at " + taskModel.getLocation() + "(Reason: " +
throwable.getMessage() + ")", throwable );
}
}
}

protected final void doInitialize( final Task task, final Configuration taskModel ) protected final void doInitialize( final Task task, final Configuration taskModel )
throws TaskException throws TaskException
{ {


Loading…
Cancel
Save