avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-avalon-cornerstone/apps/overlord/src/java/org/apache/avalon/overlord CollectorTarget.java Overlord.java
Date Wed, 28 Nov 2001 07:43:42 GMT
colus       01/11/27 23:43:42

  Modified:    apps/overlord/src/java/org/apache/avalon/overlord
                        CollectorTarget.java Overlord.java
  Log:
  Refactored.
  
  Revision  Changes    Path
  1.2       +12 -6     jakarta-avalon-cornerstone/apps/overlord/src/java/org/apache/avalon/overlord/CollectorTarget.java
  
  Index: CollectorTarget.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/overlord/src/java/org/apache/avalon/overlord/CollectorTarget.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CollectorTarget.java	2001/11/25 07:34:01	1.1
  +++ CollectorTarget.java	2001/11/28 07:43:42	1.2
  @@ -24,27 +24,33 @@
       private static final Resources REZ =
           ResourceManager.getPackageResources( CollectorTarget.class );
   
  -    private Collector   m_collector;
  +    private GatheringServer     m_server;
  +    private String              m_taskName;
  +    private String              m_collectorName;
   
  -    public CollectorTarget( final Collector collector )
  +    public CollectorTarget( final GatheringServer server,
  +                            final String taskName,
  +                            final String collectorName )
       {
  -        m_collector = collector;
  +        m_server = server;
  +        m_taskName = taskName;
  +        m_collectorName = collectorName;
       }
   
       public void targetTriggered( final String triggerName )
       {
           try
           {
  -            m_collector.execute();
  +            m_server.collect( m_collectorName );
   
               final String message = REZ.getString( "target.notice.execute",
  -                                                  triggerName  );
  +                                                  m_taskName  );
               getLogger().info( message );
           }
           catch ( final Exception e )
           {
               final String message = REZ.getString( "target.error.execute",
  -                                                  triggerName );
  +                                                  m_taskName );
               getLogger().error( message, e );
           }
       }
  
  
  
  1.3       +74 -39    jakarta-avalon-cornerstone/apps/overlord/src/java/org/apache/avalon/overlord/Overlord.java
  
  Index: Overlord.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/overlord/src/java/org/apache/avalon/overlord/Overlord.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Overlord.java	2001/11/27 13:21:42	1.2
  +++ Overlord.java	2001/11/28 07:43:42	1.3
  @@ -42,7 +42,7 @@
    */
   public class Overlord
       extends AbstractLogEnabled
  -    implements GatheringServer, Block, Contextualizable, Composable, Configurable, Initializable,
Disposable
  +    implements Contextualizable, Composable, Configurable, Initializable, Disposable, Block,
GatheringServer
   {
       private static final Resources REZ = 
           ResourceManager.getPackageResources( Overlord.class );
  @@ -51,8 +51,9 @@
       private ComponentManager            m_componentManager;
       private Configuration               m_configuration;
       private TimeScheduler               m_scheduler;
  +    private TimeTriggerFactory          m_triggerFactory;
       private Map                         m_collectors;
  -    private List                        m_tasks;
  +    private List                        m_taskNames;
   
       public void contextualize( final Context context )
       {
  @@ -77,6 +78,8 @@
       private void initializeCollectors( final Configuration configuration )
           throws Exception
       {
  +        final Logger logger = getLogger().getChildLogger( "collectors" );
  +
           m_collectors = new HashMap();
   
           final Configuration[] confs = configuration.getChildren( "collector" );
  @@ -89,10 +92,10 @@
               final Collector collector =
                   (Collector)Class.forName( clazz ).newInstance();
               setupComponent( collector,
  -                            getLogger().getChildLogger( name ),
  +                            logger.getChildLogger( name ),
                               m_context, m_componentManager, conf );
   
  -            m_collectors.put( name, collector );
  +            addCollector( name, collector );
   
               getLogger().info( REZ.getString( "overlord.notice.collector.add", name, clazz
) );
           }
  @@ -101,7 +104,7 @@
       private void initializeTasks( final Configuration configuration )
           throws Exception
       {
  -        m_tasks = new ArrayList();
  +        m_taskNames = new ArrayList();
   
           final Configuration[] taskConfs = configuration.getChildren( "task" );
           for ( int i = 0; i < taskConfs.length; i++ )
  @@ -109,9 +112,8 @@
               final Configuration conf = taskConfs[ i ];
               final String name = conf.getAttribute( "name" );
   
  -            final TimeTriggerFactory triggerFactory = new TimeTriggerFactory();
               final Configuration triggerConf = conf.getChild( "trigger" );
  -            final TimeTrigger trigger = triggerFactory.create( triggerConf );
  +            final TimeTrigger trigger = m_triggerFactory.create( triggerConf );
   
               final String targetName = conf.getChild( "target" ).getValue();
   
  @@ -122,6 +124,8 @@
       public void initialize()
           throws Exception
       {
  +        m_triggerFactory = new TimeTriggerFactory();
  +
           initializeCollectors( m_configuration.getChild( "collectors" ) );
           initializeTasks( m_configuration.getChild( "tasks" ) );
   
  @@ -136,13 +140,13 @@
   
       private void disposeTasks()
       {
  -        final Iterator taskNames = m_tasks.iterator();
  +        final Iterator taskNames = m_taskNames.iterator();
           while ( taskNames.hasNext() )
           {
               removeTask( (String)taskNames.next() );
           }
  -        m_tasks.clear();
  -        m_tasks = null;
  +        m_taskNames.clear();
  +        m_taskNames = null;
       }
   
       private void disposeCollectors()
  @@ -158,6 +162,28 @@
           m_collectors = null;
       }
   
  +    private void addCollector( final String name, final Collector collector )
  +    {
  +        if ( null == name || name.length() == 0 )
  +        {
  +            final String message = "Invalid collector name";
  +            throw new IllegalArgumentException( message );
  +        }
  +
  +        if ( m_collectors.containsKey( name ) )
  +        {
  +            final String message = "Collector named " + name + " already exists";
  +            throw new IllegalArgumentException( message );
  +        }
  +
  +        m_collectors.put( name, collector );
  +    }
  +
  +    private void removeCollector( final String name )
  +    {
  +        m_collectors.remove( name );
  +    }
  +
       /**
        * Add task.
        *
  @@ -168,7 +194,7 @@
       private void addTask( final String taskName, final TimeTrigger trigger,
                             final String collectorName )
       {
  -        if ( m_tasks.contains( taskName ) )
  +        if ( m_taskNames.contains( taskName ) )
           {
               final String msg = REZ.getString( "overlord.error.task.exists",
                                                 taskName );
  @@ -183,13 +209,15 @@
               throw new IllegalArgumentException( message );
           }
   
  -        final CollectorTarget target = new CollectorTarget( collector );
  -        setupLogger( target );
  +        final CollectorTarget target = new CollectorTarget( this, taskName, collectorName
);
  +        setupLogger( target, "targets" );
   
           m_scheduler.addTrigger( this + taskName, trigger, target );
  -        m_tasks.add( taskName );
  +        m_taskNames.add( taskName );
   
  -        getLogger().info( REZ.getString( "overlord.notice.task.add", taskName ) );
  +        final String message =
  +            REZ.getString( "overlord.notice.task.add", taskName );
  +        getLogger().info( message );
       }
   
       /**
  @@ -200,9 +228,38 @@
       private void removeTask( final String taskName )
       {
           m_scheduler.removeTrigger( this + taskName );
  -        m_tasks.remove( taskName );
  +        m_taskNames.remove( taskName );
  +
  +        final String message =
  +            REZ.getString( "overlord.notice.task.remove", taskName );
  +        getLogger().info( message );
  +    }
  +
  +    public void collect( final String name )
  +        throws Exception
  +    {
  +        //lookup
  +        final Collector collector = (Collector)m_collectors.get( name );
  +        if ( null == collector )
  +        {
  +            final String message =
  +                REZ.getString( "overlord.error.collector.find", name );
  +            getLogger().error( message );
  +            throw new ComponentException( message );
  +        }
   
  -        getLogger().info( REZ.getString( "overlord.notice.task.remove", taskName ) );
  +        //execute
  +        try
  +        {
  +            collector.execute();
  +        }
  +        catch ( final Exception e )
  +        {
  +            final String message =
  +                REZ.getString( "overlord.error.collector.execute", name );
  +            getLogger().error( message, e );
  +            throw e;
  +        }
       }
   
       private void setupComponent( final Component component,
  @@ -243,28 +300,6 @@
           if ( component instanceof Disposable )
           {
               ((Disposable)component).dispose();
  -        }
  -    }
  -
  -    public void collect( final String name )
  -        throws Exception
  -    {
  -        final Collector collector = (Collector)m_collectors.get( name );
  -        if ( null == collector )
  -        {
  -            final String message = "Unable to find collector named " + name;
  -            throw new ComponentException( message );
  -        }
  -
  -        try
  -        {
  -            collector.execute();
  -        }
  -        catch ( final Exception e )
  -        {
  -            final String message = "Fail to execute collector " + name;
  -            getLogger().error( message, e );
  -            throw e;
           }
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message