You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2002/11/07 06:11:51 UTC

cvs commit: jakarta-avalon-excalibur/component/examples/instrument-manager/src/java/org/apache/avalon/excalibur/component/example_im DefaultExampleInstrumentable.java Main.java

donaldp     2002/11/06 21:11:51

  Modified:    component/examples/instrument-manager/src/java/org/apache/avalon/excalibur/component/example_im
                        DefaultExampleInstrumentable.java Main.java
  Log:
  Optimize imports
  
  Revision  Changes    Path
  1.3       +26 -27    jakarta-avalon-excalibur/component/examples/instrument-manager/src/java/org/apache/avalon/excalibur/component/example_im/DefaultExampleInstrumentable.java
  
  Index: DefaultExampleInstrumentable.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/component/examples/instrument-manager/src/java/org/apache/avalon/excalibur/component/example_im/DefaultExampleInstrumentable.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultExampleInstrumentable.java	16 Aug 2002 03:44:14 -0000	1.2
  +++ DefaultExampleInstrumentable.java	7 Nov 2002 05:11:51 -0000	1.3
  @@ -7,14 +7,13 @@
    */
   package org.apache.avalon.excalibur.component.example_im;
   
  +import org.apache.avalon.framework.activity.Startable;
  +import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.excalibur.instrument.CounterInstrument;
  -import org.apache.excalibur.instrument.Instrumentable;
   import org.apache.excalibur.instrument.Instrument;
  +import org.apache.excalibur.instrument.Instrumentable;
   import org.apache.excalibur.instrument.ValueInstrument;
   
  -import org.apache.avalon.framework.activity.Startable;
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -
   /**
    * This example application creates a component which registers several
    *  Instruments for the example.
  @@ -29,13 +28,13 @@
       extends AbstractLogEnabled
       implements ExampleInstrumentable, Startable, Runnable, Instrumentable
   {
  -    public static final String INSTRUMENT_RANDOM_QUICK_NAME   = "random-quick";
  -    public static final String INSTRUMENT_RANDOM_SLOW_NAME    = "random-slow";
  -    public static final String INSTRUMENT_RANDOM_RANDOM_NAME  = "random-random";
  -    public static final String INSTRUMENT_COUNTER_QUICK_NAME  = "counter-quick";
  -    public static final String INSTRUMENT_COUNTER_SLOW_NAME   = "counter-slow";
  +    public static final String INSTRUMENT_RANDOM_QUICK_NAME = "random-quick";
  +    public static final String INSTRUMENT_RANDOM_SLOW_NAME = "random-slow";
  +    public static final String INSTRUMENT_RANDOM_RANDOM_NAME = "random-random";
  +    public static final String INSTRUMENT_COUNTER_QUICK_NAME = "counter-quick";
  +    public static final String INSTRUMENT_COUNTER_SLOW_NAME = "counter-slow";
       public static final String INSTRUMENT_COUNTER_RANDOM_NAME = "counter-random";
  -    public static final String INSTRUMENT_DOACTION_NAME       = "doaction-counter";
  +    public static final String INSTRUMENT_DOACTION_NAME = "doaction-counter";
   
       /** Instrumentable Name assigned to this Instrumentable */
       private String m_instrumentableName;
  @@ -70,13 +69,13 @@
       public DefaultExampleInstrumentable()
       {
           // Initialize the Instrumentable elements.
  -        m_randomQuickInstrument   = new ValueInstrument( INSTRUMENT_RANDOM_QUICK_NAME );
  -        m_randomSlowInstrument    = new ValueInstrument( INSTRUMENT_RANDOM_SLOW_NAME );
  -        m_randomRandomInstrument  = new ValueInstrument( INSTRUMENT_RANDOM_RANDOM_NAME );
  -        m_counterQuickInstrument  = new CounterInstrument( INSTRUMENT_COUNTER_QUICK_NAME );
  -        m_counterSlowInstrument   = new CounterInstrument( INSTRUMENT_COUNTER_SLOW_NAME );
  +        m_randomQuickInstrument = new ValueInstrument( INSTRUMENT_RANDOM_QUICK_NAME );
  +        m_randomSlowInstrument = new ValueInstrument( INSTRUMENT_RANDOM_SLOW_NAME );
  +        m_randomRandomInstrument = new ValueInstrument( INSTRUMENT_RANDOM_RANDOM_NAME );
  +        m_counterQuickInstrument = new CounterInstrument( INSTRUMENT_COUNTER_QUICK_NAME );
  +        m_counterSlowInstrument = new CounterInstrument( INSTRUMENT_COUNTER_SLOW_NAME );
           m_counterRandomInstrument = new CounterInstrument( INSTRUMENT_COUNTER_RANDOM_NAME );
  -        m_doActionInstrument      = new CounterInstrument( INSTRUMENT_DOACTION_NAME );
  +        m_doActionInstrument = new CounterInstrument( INSTRUMENT_DOACTION_NAME );
       }
   
       /*---------------------------------------------------------------
  @@ -101,7 +100,7 @@
        */
       public void start()
       {
  -        if ( m_runner == null )
  +        if( m_runner == null )
           {
               m_runner = new Thread( this, "ExampleInstrumentableRunner" );
               m_runner.start();
  @@ -113,7 +112,7 @@
        */
       public void stop()
       {
  -        if ( m_runner != null )
  +        if( m_runner != null )
           {
               m_runner.interrupt();
               m_runner = null;
  @@ -130,38 +129,38 @@
       public void run()
       {
           int counter = 0;
  -        while ( m_runner != null )
  +        while( m_runner != null )
           {
               // Add some delay to the loop.
               try
               {
                   Thread.sleep( 100 );
               }
  -            catch ( InterruptedException e )
  +            catch( InterruptedException e )
               {
  -                if ( m_runner == null )
  +                if( m_runner == null )
                   {
                       return;
                   }
               }
   
               // Handle the quick Profile Points
  -            m_randomQuickInstrument.setValue( (int)(Math.random() * 100) );
  +            m_randomQuickInstrument.setValue( (int)( Math.random() * 100 ) );
               m_counterQuickInstrument.increment();
   
               // Handle the slow Profile Points
               counter++;
  -            if ( counter >= 20 )
  +            if( counter >= 20 )
               {
  -                m_randomSlowInstrument.setValue( (int)(Math.random() * 100) );
  +                m_randomSlowInstrument.setValue( (int)( Math.random() * 100 ) );
                   m_counterSlowInstrument.increment();
                   counter = 0;
               }
   
               // Handle the random Profile Points.  Fire 10% of the time.
  -            if ( 100 * Math.random() < 10 )
  +            if( 100 * Math.random() < 10 )
               {
  -                m_randomRandomInstrument.setValue( (int)(Math.random() * 100) );
  +                m_randomRandomInstrument.setValue( (int)( Math.random() * 100 ) );
                   m_counterRandomInstrument.increment();
               }
           }
  
  
  
  1.3       +32 -25    jakarta-avalon-excalibur/component/examples/instrument-manager/src/java/org/apache/avalon/excalibur/component/example_im/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/component/examples/instrument-manager/src/java/org/apache/avalon/excalibur/component/example_im/Main.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Main.java	16 Aug 2002 03:44:14 -0000	1.2
  +++ Main.java	7 Nov 2002 05:11:51 -0000	1.3
  @@ -10,13 +10,10 @@
   import java.io.BufferedReader;
   import java.io.File;
   import java.io.InputStreamReader;
  -
  -//import org.apache.avalon.excalibur.component.DefaultRoleManager;
   import org.apache.avalon.excalibur.component.ExcaliburComponentManagerCreator;
  -//import org.apache.avalon.excalibur.logger.LogKitLoggerManager;
   import org.apache.avalon.excalibur.concurrent.ThreadBarrier;
  -
   import org.apache.avalon.framework.component.ComponentManager;
  +
   //import org.apache.avalon.framework.configuration.Configuration;
   //import org.apache.avalon.framework.configuration.ConfigurationException;
   //import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  @@ -43,12 +40,14 @@
    */
   public class Main
   {
  -    private static ExcaliburComponentManagerCreator     m_componentManagerCreator;
  +    private static ExcaliburComponentManagerCreator m_componentManagerCreator;
   
       /*---------------------------------------------------------------
        * Constructors
        *-------------------------------------------------------------*/
  -    private Main() {}
  +    private Main()
  +    {
  +    }
   
       /*---------------------------------------------------------------
        * Main method
  @@ -65,9 +64,9 @@
           //  utility class.  See the contents of that class if you wish to do the
           //  initialization yourself.
           m_componentManagerCreator = new ExcaliburComponentManagerCreator( null,
  -            new File( "../conf/logkit.xml" ), new File( "../conf/roles.xml" ),
  -            new File( "../conf/components.xml"), new File( "../conf/instrument.xml" ) );
  -        
  +                                                                          new File( "../conf/logkit.xml" ), new File( "../conf/roles.xml" ),
  +                                                                          new File( "../conf/components.xml" ), new File( "../conf/instrument.xml" ) );
  +
           // Get a reference to the component manager
           ComponentManager componentManager = m_componentManagerCreator.getComponentManager();
   
  @@ -77,20 +76,20 @@
           try
           {
               boolean quit = false;
  -            while ( !quit )
  +            while( !quit )
               {
                   System.out.println( "Enter the number of times that exampleAction should be "
  -                    + "called, or 'q' to quit." );
  +                                    + "called, or 'q' to quit." );
                   BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) );
                   System.out.print( " : " );
                   String cntStr = in.readLine();
   
                   // Can get a null if CTRL-C is hit.
  -                if ( ( cntStr == null ) || ( cntStr.equalsIgnoreCase( "q" ) ) )
  +                if( ( cntStr == null ) || ( cntStr.equalsIgnoreCase( "q" ) ) )
                   {
                       quit = true;
                   }
  -                else if ( ( cntStr.equalsIgnoreCase( "gc" ) ) )
  +                else if( ( cntStr.equalsIgnoreCase( "gc" ) ) )
                   {
                       System.gc();
                   }
  @@ -101,27 +100,29 @@
                           int concurrent = 100;
                           ThreadBarrier barrier = new ThreadBarrier( concurrent );
                           int cnt = Integer.parseInt( cntStr );
  -                        int average = Math.max(cnt / concurrent, 1);
  +                        int average = Math.max( cnt / concurrent, 1 );
   
  -                        while (cnt > 0)
  +                        while( cnt > 0 )
                           {
                               Thread t = new Thread( new ActionRunner( instrumentable,
  -                                                          Math.min(average, cnt),
  -                                                          barrier) );
  +                                                                     Math.min( average, cnt ),
  +                                                                     barrier ) );
                               t.start();
   
  -                            if (cnt > 0)
  +                            if( cnt > 0 )
                               {
                                   cnt -= average;
                               }
   
  -                            if (cnt < 0)
  +                            if( cnt < 0 )
                               {
                                   cnt = 0;
                               }
                           }
                       }
  -                    catch ( NumberFormatException e ) {}
  +                    catch( NumberFormatException e )
  +                    {
  +                    }
                   }
               }
           }
  @@ -130,7 +131,7 @@
               // Release the component
               componentManager.release( instrumentable );
               instrumentable = null;
  -            
  +
               // Dispose of the ComponentManagerCreator.  It will dispose all
               //  of its own components, including the ComponentManager
               m_componentManagerCreator.dispose();
  @@ -138,7 +139,7 @@
   
           System.out.println();
           System.out.println( "Exiting..." );
  -        System.exit(0);
  +        System.exit( 0 );
       }
   
       private static final class ActionRunner implements Runnable
  @@ -156,7 +157,7 @@
   
           public void run()
           {
  -            for ( int i = 0; i < m_numIterations; i++ )
  +            for( int i = 0; i < m_numIterations; i++ )
               {
                   m_instrumentable.doAction();
               }
  @@ -165,8 +166,14 @@
               {
                   m_barrier.barrierSynchronize();
               }
  -            catch (Exception e) {}
  +            catch( Exception e )
  +            {
  +            }
           }
  +    }
  +}
  +
  +     }
       }
   }
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>