avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/examples/altprofile/src/java/org/apache/avalon/examples/altprofile DefaultExampleProfilable.java ExampleProfilable.java Main.java
Date Mon, 04 Mar 2002 09:02:10 GMT
leif        02/03/04 01:02:10

  Modified:    examples build.xml
  Added:       examples/altprofile .cvsignore build.bat build.sh build.xml
               examples/altprofile/bin cpappend.bat run.bat
               examples/altprofile/conf components.xml logkit.xml
                        profiler.xml roles.xml
               examples/altprofile/src/java/org/apache/avalon/examples/altprofile
                        DefaultExampleProfilable.java
                        ExampleProfilable.java Main.java
  Log:
  Add AltProfile example.
  
  Revision  Changes    Path
  1.2       +4 -0      jakarta-avalon-excalibur/examples/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/examples/build.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- build.xml	7 Feb 2002 07:15:41 -0000	1.1
  +++ build.xml	4 Mar 2002 09:02:09 -0000	1.2
  @@ -160,6 +160,10 @@
           <!-- All example projects should be listed here -->
           
           <!-- jdbcdatasource example -->
  +        <ant antfile="build.xml" dir="${basedir}/altprofile" 
  +            target="${examples.target}" inheritall="false"/>  
  +        
  +        <!-- jdbcdatasource example -->
           <ant antfile="build.xml" dir="${basedir}/jdbcdatasource" 
               target="${examples.target}" inheritall="false"/>  
           
  
  
  
  1.1                  jakarta-avalon-excalibur/examples/altprofile/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  build
  lib
  sqldata
  
  
  
  1.1                  jakarta-avalon-excalibur/examples/altprofile/build.bat
  
  Index: build.bat
  ===================================================================
  @echo off
  
  if exist "..\..\..\jakarta-avalon\tools\bin\ant.bat" set LOCAL_AVALON_TOOLS=..\..\..\jakarta-avalon\tools
  if not "%AVALON_TOOLS%"=="" set LOCAL_AVALON_TOOLS=%AVALON_TOOLS%
  
  if not "%LOCAL_AVALON_TOOLS%"=="" goto runAnt
  
  echo "Unable to locate tools directory at "
  echo "../../../jakarta-avalon/tools/"
  echo "Aborting."
  goto end
  
  :runAnt
  set OLD_ANT_HOME=%ANT_HOME%
  set ANT_HOME=%LOCAL_AVALON_TOOLS%
  %LOCAL_AVALON_TOOLS%\bin\ant.bat -logger org.apache.tools.ant.NoBannerLogger -emacs -Dtools.dir=%LOCAL_AVALON_TOOLS%
%1 %2 %3 %4 %5 %6 %7 %8
  set ANT_HOME=%OLD_ANT_HOME%
  set OLD_ANT_HOME=
  
  :end
  set LOCAL_AVALON_TOOLS=
  
  
  
  1.1                  jakarta-avalon-excalibur/examples/altprofile/build.sh
  
  Index: build.sh
  ===================================================================
  #!/bin/sh
  
  LOCAL_AVALON_TOOLS=$AVALON_TOOLS
  
  if [ "$AVALON_TOOLS" = "" ] ; then
      if [ -d ../../../jakarta-avalon/tools ] ; then
          LOCAL_AVALON_TOOLS=../../../jakarta-avalon/tools
      else
          echo "Unable to locate tools directory at "
          echo "../../../jakarta-avalon/tools/"
          echo "Aborting."
          exit 1
      fi
  fi
  
  chmod u+x $LOCAL_AVALON_TOOLS/bin/antRun
  chmod u+x $LOCAL_AVALON_TOOLS/bin/ant
  
  $LOCAL_AVALON_TOOLS/bin/ant -logger org.apache.tools.ant.NoBannerLogger -emacs -Dtools.dir=$LOCAL_AVALON_TOOLS
$@
  
  
  
  1.1                  jakarta-avalon-excalibur/examples/altprofile/build.xml
  
  Index: build.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <!-- ======================================================================= -->
  <!-- JdbcDataSource Example build file!                                      -->
  <!-- ======================================================================= -->
  
  <project name="jdbcdatasource" default="main" basedir=".">
      
      <!-- ================================================================ -->
      <!-- Local user-defined build properties.                             -->
      <!-- ================================================================ -->
      <!-- The file below should exist on your system. On Windows machines, -->
      <!-- user.home is probably the root of the C drive, but you should    -->
      <!-- verify this. This file should be a normal Java properties file.  -->
      <property file="${user.home}/.ant.properties" />
      
      <property name="name" value="jdbcdatasource"/>
      <property name="Name" value="JdbcDataSource"/>
      
      <!-- Directories build by ant -->  
      <property name="build.dir"             value="${basedir}/build"/>
      <property name="build.classes.dir"     value="${build.dir}/classes"/>
      <property name="build.javadocs.dir"    value="${build.dir}/javadocs"/>
      <property name="lib.dir"               value="${basedir}/lib"/>
      <property name="sqldata.dir"           value="${basedir}/sqldata"/>
      
      <!-- Existing directories -->
      <property name="src.dir"               value="${basedir}/src"/>
      <property name="src.java.dir"          value="${src.dir}/java"/>
      <property name="commonlib.dir"         value="${basedir}/../commonlib"/>
      
      <!-- Define paths used by this project -->
      <path id="project.class.path">
          <fileset dir="${commonlib.dir}">
              <include name="**/*.jar"/>
          </fileset>
          <pathelement path="${build.classes.dir}" />
      </path>
      
      <!-- =================================================================== -->
      <!-- Help on usage                                                       -->
      <!-- =================================================================== -->
      <target name="usage">
          <echo message="Use the -projecthelp option instead"/>
      </target>
      <target name="help" depends="usage"/>
      
      <!-- =================================================================== -->
      <!-- Help on usage                                                       -->
      <!-- =================================================================== -->
      <target name="collect-jars">
          <ant antfile="build.xml" dir="${basedir}/.." target="collect-jars" inheritall="false"/>
 
      </target>
      
      <!-- =================================================================== -->
      <!-- Initialize custom tasks                                             -->
      <!-- =================================================================== -->
      <target name="init" depends="collect-jars">
      </target>
      
      <!-- =================================================================== -->
      <!-- Compiles the source code                                            -->
      <!-- =================================================================== -->
      <target name="compile" depends="init">
          <mkdir dir="${build.dir}"/>
          <mkdir dir="${build.classes.dir}"/>
          
          <!-- compile everything under src/java -->
          <javac srcdir="${src.java.dir}" destdir="${build.classes.dir}"
              deprecation="on"
              debug="on"
              optimize="off">
              <classpath refid="project.class.path" />
          </javac>
          
          <!-- copy image files to build directory -->
          <copy todir="${build.classes.dir}" > 
              <fileset dir="${src.java.dir}" > 
                  <include name="**/*.jpg" />
                  <include name="**/*.gif" />
              </fileset> 
          </copy>
      </target>
      
      <!-- =================================================================== -->
      <!-- Creates the jar archive                                             -->
      <!-- =================================================================== -->
      <target name="jar" depends="compile" description="Builds the jar archive.">
          <mkdir dir="${lib.dir}"/>
          
          <jar jarfile="${lib.dir}/${name}.jar"
              basedir="${build.classes.dir}"
              includes="**/*.class,**/*.properties,**/*.xml,**/*.jpg,**/*.gif,**/*.roles"
              />
      </target>
      
      <!-- =================================================================== -->
      <!-- Main target                                                         -->
      <!-- =================================================================== -->
      <target name="main" depends="jar" description="build the runnable application">
          <mkdir dir="${sqldata.dir}"/>
      </target>
      
      <!-- =================================================================== -->
      <!-- Creates the javadocs archive.                                       -->
      <!-- =================================================================== -->
      <target name="javadocs" description="Generates javadoc documentation">
          <mkdir dir="${build.javadocs.dir}"/>
          
          <javadoc packagenames="org.apache.*"
              sourcepath="${src.java.dir}"
              destdir="${build.javadocs.dir}">
              <classpath refid="project.class.path" />
              <doclet name="com.sun.tools.doclets.standard.Standard">
                  <param name="-author"/>
                  <param name="-version"/>
                  <param name="-doctitle" value="${Name}"/>
                  <param name="-windowtitle" value="${Name} API"/>
                  <param name="-bottom"
                      value="&quot;Copyright &#169; 2001 Apache Jakarta Project. All
Rights Reserved.&quot;"/>
              </doclet>
          </javadoc>
      </target>
      
      <!-- =================================================================== -->
      <!-- Builds everything.                                                  -->
      <!-- =================================================================== -->
      <target name="all" depends="main, javadocs" description="Build everything"/>
      
      <!-- =================================================================== -->
      <!-- Cleans up compiled classes and generated XMLC source.               -->
      <!-- =================================================================== -->
      <target name="clean" description="cleans up the directory">
          <delete dir="${build.dir}"/>
      </target>
  </project>
  
  
  
  
  1.1                  jakarta-avalon-excalibur/examples/altprofile/bin/cpappend.bat
  
  Index: cpappend.bat
  ===================================================================
  set _LIBJARS=%_LIBJARS%;%1
  
  
  
  1.1                  jakarta-avalon-excalibur/examples/altprofile/bin/run.bat
  
  Index: run.bat
  ===================================================================
  @echo off
  rem
  rem Example start script.
  rem
  rem Author: Leif Mortenson [leif@silveregg.co.jp]
  
  rem
  rem Determine if JAVA_HOME is set and if so then use it
  rem
  if not "%JAVA_HOME%"=="" goto found_java
  
  set EXAMPLE_JAVACMD=java
  goto file_locate
  
  :found_java
  set EXAMPLE_JAVACMD=%JAVA_HOME%\bin\java
  
  :file_locate
  
  rem
  rem Locate where the example is in filesystem
  rem
  if not "%OS%"=="Windows_NT" goto start
  
  rem %~dp0 is name of current script under NT
  set EXAMPLE_HOME=%~dp0
  
  rem : operator works similar to make : operator
  set EXAMPLE_HOME=%EXAMPLE_HOME:\bin\=%
  
  :start
  
  if not "%EXAMPLE_HOME%" == "" goto example_home
  
  echo.
  echo Warning: EXAMPLE_HOME environment variable is not set.
  echo   This needs to be set for Win9x as it's command prompt 
  echo   scripting bites
  echo.
  goto end
  
  :example_home
  rem
  rem build the runtime classpath
  rem
  set CP=%EXAMPLE_HOME%\lib\jdbcdatasource.jar
  
  
  set _LIBJARS=
  for %%i in (%EXAMPLE_HOME%\..\commonlib\*.jar) do call %EXAMPLE_HOME%\bin\cpappend.bat %%i
  if not "%_LIBJARS%" == "" goto run
  
  echo Unable to set CLASSPATH dynamically.
  goto end
  
  :run
  set CP=%CP%%_LIBJARS%
  
  rem Run the example application
  %EXAMPLE_JAVACMD% -Djava.compiler="NONE" -classpath "%CP%" org.apache.avalon.examples.altprofile.Main
%1 %2 %3 %4 %5 %6 %7 %8 %9
  
  :end
  
  
  
  1.1                  jakarta-avalon-excalibur/examples/altprofile/conf/components.xml
  
  Index: components.xml
  ===================================================================
  <components logger="cm">
      <!-- =============================================================== -->
      <!-- Application components.                                         -->
      <!-- =============================================================== -->
      <example-profilable logger="app" profilable="example-profilable"/>
  </components>
  
  
  1.1                  jakarta-avalon-excalibur/examples/altprofile/conf/logkit.xml
  
  Index: logkit.xml
  ===================================================================
  <logkit logger="lm" log-level="INFO">
      <factories>
          <factory type="stream" 
                   class="org.apache.avalon.excalibur.logger.factory.StreamTargetFactory"/>
          <factory type="file" 
                   class="org.apache.avalon.excalibur.logger.factory.FileTargetFactory"/>
          <factory type="priority-filter" 
                   class="org.apache.avalon.excalibur.logger.factory.PriorityFilterTargetFactory"/>
      </factories>
      <targets>
          <stream id="console">
              <stream>System.out</stream>
              <format type="avalon">
  %19.19{time:yyyy-MM-dd'T'HH:mm:ss.SSS} %5.5{priority} [%15.15{category}]: %{message}\n%{throwable}
              </format>
          </stream>
      </targets>
      <categories>
          <!-- Profiler Manager Logger -->
          <category name="pm" log-level="DEBUG">
              <log-target id-ref="console"/>
              
              <!-- The values child logger can dump out a lot of data. -->
              <category name="values" 
                        log-level="INFO">
                  <log-target id-ref="console"/>
              </category>
          </category>
          
          <!-- Role Manager Logger -->
          <category name="rm" log-level="DEBUG">
              <log-target id-ref="console"/>
          </category>
          
          <!-- Component Manager Logger -->
          <category name="cm" log-level="DEBUG">
              <log-target id-ref="console"/>
          </category>
          
          <!-- Application Loggers -->
          <category name="app" log-level="DEBUG">
              <log-target id-ref="console"/>
          </category>
      </categories>
  </logkit>
  
  
  
  1.1                  jakarta-avalon-excalibur/examples/altprofile/conf/profiler.xml
  
  Index: profiler.xml
  ===================================================================
  <profiler logger="pm">
      <profilables>
          <!-- The profiler Profilable is the ProfilerManager itself. -->
          <profilable name="profiler" description="Profiler">
              
              <profile-point name="total-memory" description="Total Memory">
                  <sample type="max" interval="1000" size="600" description="Maximum each
second."/>
              </profile-point>
              
              <profile-point name="free-memory" description="Free Memory">
                  <sample type="min" interval="1000" size="600" description="Minimum each
second."/>
              </profile-point>
              
              <profile-point name="memory" description="In-Use Memory">
                  <sample type="max" interval="1000" size="600" description="Maximum each
second."/>
              </profile-point>
          </profilable>
          
          <!-- ExampleProfilable. -->
          <profilable name="example-profilable" description="Example Profilable">
              <!-- Note that any number of samples are possible for each profile point.
-->
              <profile-point name="random-quick" description="Random Values at a quick
rate.">
                  <sample type="maximum" interval="1000" size="600" description="Maximum
each second."/>
                  <sample type="minimum" interval="1000" size="600" description="Minimum
each second."/>
                  <sample type="average" interval="1000" size="600" description="Average
each second."/>
              </profile-point>
              
              <profile-point name="random-slow" description="Random Values at a slow rate.">
                  <sample type="maximum" interval="1000" size="600" description="Maximum
each second."/>
                  <sample type="minimum" interval="1000" size="600" description="Minimum
each second."/>
                  <sample type="average" interval="1000" size="600" description="Average
each second."/>
              </profile-point>
              
              <profile-point name="random-random" description="Random Values at a random
rate.">
                  <sample type="maximum" interval="1000" size="600" description="Maximum
each second."/>
                  <sample type="minimum" interval="1000" size="600" description="Minimum
each second."/>
                  <sample type="average" interval="1000" size="600" description="Average
each second."/>
              </profile-point>
              
              <profile-point name="counter-quick" description="Count of actions at a quick
rate.">
                  <sample type="counter" interval="100" size="600" description="Count per
100ms."/>
                  <sample type="counter" interval="1000" size="600" description="Count
per second."/>
                  <sample type="counter" interval="60000" size="60" description="Count
per minute."/>
              </profile-point>
              
              <profile-point name="counter-slow" description="Count of actions at a slow
rate.">
                  <sample type="counter" interval="1000" size="600" description="Count
per second."/>
                  <sample type="counter" interval="60000" size="60" description="Count
per minute."/>
              </profile-point>
              
              <profile-point name="counter-random" description="Count of actions at a random
rate.">
                  <sample type="counter" interval="1000" size="600" description="Count
per second."/>
                  <sample type="counter" interval="60000" size="60" description="Count
per minute."/>
              </profile-point>
              
              <profile-point name="doaction-counter" description="Number of times doAction
is called.">
                  <sample type="counter" interval="1000" size="600" description="Count
per second."/>
                  <sample type="counter" interval="60000" size="60" description="Count
per minute."/>
              </profile-point>
          </profilable>
      </profilables>
  </profiler>
  
  
  1.1                  jakarta-avalon-excalibur/examples/altprofile/conf/roles.xml
  
  Index: roles.xml
  ===================================================================
  <role-list logger="rm">
      <!-- =================================================================== -->
      <!-- Application roles.                                                  -->
      <!-- =================================================================== -->
      <role name="org.apache.avalon.examples.altprofile.ExampleProfilable"
            shorthand="example-profilable"
            default-class="org.apache.avalon.examples.altprofile.DefaultExampleProfilable"/>
  </role-list>
  
  
  
  1.1                  jakarta-avalon-excalibur/examples/altprofile/src/java/org/apache/avalon/examples/altprofile/DefaultExampleProfilable.java
  
  Index: DefaultExampleProfilable.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.examples.altprofile;
  
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.sql.Timestamp;
  
  import org.apache.avalon.excalibur.altprofile.CounterProfilePoint;
  import org.apache.avalon.excalibur.altprofile.Profilable;
  import org.apache.avalon.excalibur.altprofile.ProfilePoint;
  import org.apache.avalon.excalibur.altprofile.ValueProfilePoint;
  
  import org.apache.avalon.framework.activity.Startable;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  
  /**
   * This example application creates a component which registers several
   *  ProfilePoints for the example.
   *
   * Note, this code ignores exceptions to keep the code simple.
   *
   * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/03/04 09:02:10 $
   * @since 4.1
   */
  public class DefaultExampleProfilable
      extends AbstractLogEnabled
      implements ExampleProfilable, Startable, Runnable, Profilable
  {
      public static final String PROFILE_POINT_RANDOM_QUICK_NAME   = "random-quick";
      public static final String PROFILE_POINT_RANDOM_SLOW_NAME    = "random-slow";
      public static final String PROFILE_POINT_RANDOM_RANDOM_NAME  = "random-random";
      public static final String PROFILE_POINT_COUNTER_QUICK_NAME  = "counter-quick";
      public static final String PROFILE_POINT_COUNTER_SLOW_NAME   = "counter-slow";
      public static final String PROFILE_POINT_COUNTER_RANDOM_NAME = "counter-random";
      public static final String PROFILE_POINT_DOACTION_NAME       = "doaction-counter";
      
      /** Profilable Name assigned to this Profilable */
      private String m_profilableName;
      
      /** ProfilePoint used to profile random values with lots of updates. */
      private ValueProfilePoint m_randomQuickProfilePoint;
      
      /** ProfilePoint used to profile random values with few of updates. */
      private ValueProfilePoint m_randomSlowProfilePoint;
      
      /** ProfilePoint used to profile random values with updates at a random rate. */
      private ValueProfilePoint m_randomRandomProfilePoint;
      
      /** ProfilePoint used to profile random actions with lots of updates. */
      private CounterProfilePoint m_counterQuickProfilePoint;
      
      /** ProfilePoint used to profile random actions with few of updates. */
      private CounterProfilePoint m_counterSlowProfilePoint;
      
      /** ProfilePoint used to profile random actions with updates at a random rate. */
      private CounterProfilePoint m_counterRandomProfilePoint;
      
      /** ProfilePoint used to count the number of times that doAction is called. */
      private CounterProfilePoint m_doActionProfilePoint;
      
      /** Thread which is used to send profile data to the random profile points. */
      private Thread m_runner;
      
      /*---------------------------------------------------------------
       * Constructors
       *-------------------------------------------------------------*/
      public DefaultExampleProfilable()
      {
          // Initialize the Profiler elements.
          m_randomQuickProfilePoint   = new ValueProfilePoint( PROFILE_POINT_RANDOM_QUICK_NAME
);
          m_randomSlowProfilePoint    = new ValueProfilePoint( PROFILE_POINT_RANDOM_SLOW_NAME
);
          m_randomRandomProfilePoint  = new ValueProfilePoint( PROFILE_POINT_RANDOM_RANDOM_NAME
);
          m_counterQuickProfilePoint  = new CounterProfilePoint( PROFILE_POINT_COUNTER_QUICK_NAME
);
          m_counterSlowProfilePoint   = new CounterProfilePoint( PROFILE_POINT_COUNTER_SLOW_NAME
);
          m_counterRandomProfilePoint = new CounterProfilePoint( PROFILE_POINT_COUNTER_RANDOM_NAME
);
          m_doActionProfilePoint      = new CounterProfilePoint( PROFILE_POINT_DOACTION_NAME
);
      }
      
      /*---------------------------------------------------------------
       * ExampleProfilable Methods
       *-------------------------------------------------------------*/
      /**
       * Example action method.
       */
      public void doAction()
      {
          getLogger().info( "ExampleProfilable.doAction() called." );
          
          // Notify the profiler.
          m_doActionProfilePoint.increment();
      }
      
      /*---------------------------------------------------------------
       * Startable Methods
       *-------------------------------------------------------------*/
      /**
       * Start the component.
       */
      public void start()
      {
          if ( m_runner == null )
          {
              m_runner = new Thread( this, "ExampleProfilableRunner" );
              m_runner.start();
          }
      }
      
      /**
       * Stop the component.
       */
      public void stop()
      {
          if ( m_runner != null )
          {
              m_runner.interrupt();
              m_runner = null;
          }
      }
      
      /*---------------------------------------------------------------
       * Runnable Methods
       *-------------------------------------------------------------*/
      /**
       * Runner thread which is responsible for sending data to the Profiler via
       *  the various random Profile Points.
       */
      public void run()
      {
          int counter = 0;
          while ( m_runner != null )
          {
              // Add some delay to the loop.
              try
              {
                  Thread.sleep( 100 );
              }
              catch ( InterruptedException e )
              {
                  if ( m_runner == null )
                  {
                      return;
                  }
              }
              
              // Handle the quick Profile Points
              m_randomQuickProfilePoint.setValue( (int)(Math.random() * 100) );
              m_counterQuickProfilePoint.increment();
              
              // Handle the slow Profile Points
              counter++;
              if ( counter >= 20 )
              {
                  m_randomSlowProfilePoint.setValue( (int)(Math.random() * 100) );
                  m_counterSlowProfilePoint.increment();
                  counter = 0;
              }
              
              // Handle the random Profile Points.  Fire 10% of the time.
              if ( 100 * Math.random() < 10 )
              {
                  m_randomRandomProfilePoint.setValue( (int)(Math.random() * 100) );
                  m_counterRandomProfilePoint.increment();
              }
          }
      }
      
      /*---------------------------------------------------------------
       * Profilable Methods
       *-------------------------------------------------------------*/
      /**
       * Sets the name for the Profilable.  The Profilable Name is used to
       *  uniquely identify the Profilable during the configuration of the
       *  Profiler and to gain access to a ProfilableDescriptor through a
       *  ProfilerManager.  The value should be a string which does not
       *  contain spaces or periods.
       * <p>
       * This value may be set by a parent Profilable, or by the ProfilerManager
       *  using the value of the 'profilable' attribute in the configuration
       *  of the component.
       *
       * @param name The name used to identify a Profilable.
       */
      public void setProfilableName( String name )
      {
          m_profilableName = name;
      }
      
      /**
       * Gets the name of the Profilable.  The Profilable Name is used to
       *  uniquely identify the Profilable during the configuration of the
       *  Profiler and to gain access to a ProfilableDescriptor through a
       *  ProfilerManager.  The value should be a string which does not 
       *  contain spaces or periods.
       *
       * @return The name used to identify a Profilable.
       */
      public String getProfilableName()
      {
          return m_profilableName;
      }
  
      /**
       * Obtain a reference to all the ProfilePoints that the Profilable
       * object wishes to expose.  All sampling is done directly through
       * the ProfilePoints as opposed to the Profilable interface.
       *
       * @return An array of the ProfilePoints available for profiling.
       *         Should never be null.  If there are no ProfilePoints, then
       *         EMPTY_PROFILE_POINT_ARRAY can be returned.  This should
       *         never be the case though unless there are child Profilables
       *         with ProfilePoints.
       */
      public ProfilePoint[] getProfilePoints()
      {
          return new ProfilePoint[]
          {
              m_randomQuickProfilePoint,
              m_randomSlowProfilePoint,
              m_randomRandomProfilePoint,
              m_counterQuickProfilePoint,
              m_counterSlowProfilePoint,
              m_counterRandomProfilePoint,
              m_doActionProfilePoint
          };
      }
  
      /**
       * Any Object which implements Profilable can also make use of other
       *  Profilable child objects.  This method is used to tell the Profiler
       *  about them.
       *
       * @return An array of child Profilables.  This method should never
       *         return null.  If there are no child Profilables, then
       *         EMPTY_PROFILABLE_ARRAY can be returned.
       */
      public Profilable[] getChildProfilables()
      {
          // This profilable does not have any children.
          return Profilable.EMPTY_PROFILABLE_ARRAY;
      }
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/examples/altprofile/src/java/org/apache/avalon/examples/altprofile/ExampleProfilable.java
  
  Index: ExampleProfilable.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.examples.altprofile;
  
  import org.apache.avalon.framework.component.Component;
  
  /**
   * This example application creates a component which registers several
   *  ProfilePoints for the example.
   *
   * Note, this code ignores exceptions to keep the code simple.
   *
   * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/03/04 09:02:10 $
   * @since 4.1
   */
  public interface ExampleProfilable
      extends Component
  {
      String ROLE = ExampleProfilable.class.getName();
      
      /**
       * Example action method.
       */
      void doAction();
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/examples/altprofile/src/java/org/apache/avalon/examples/altprofile/Main.java
  
  Index: Main.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.examples.altprofile;
  
  import java.io.BufferedReader;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.InputStreamReader;
  
  import org.apache.avalon.excalibur.altprofile.component.ProfilerComponentManager;
  import org.apache.avalon.excalibur.altprofile.profiler.DefaultProfilerManager;
  import org.apache.avalon.excalibur.altprofile.profiler.gui.ProfilerFrame;
  import org.apache.avalon.excalibur.component.DefaultRoleManager;
  import org.apache.avalon.excalibur.logger.DefaultLogKitManager;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  import org.apache.avalon.framework.context.DefaultContext;
  import org.apache.avalon.framework.logger.LogKitLogger;
  
  import org.apache.log.Hierarchy;
  import org.apache.log.Logger;
  import org.apache.log.Priority;
  
  /**
   * This example application loads a component in which publishs a series
   *  of ProfilePoints.  A ProfilerManager is created to collect and
   *  manage the Profiler data.  And a ProfilerFrame is created and shown
   *  to allow the profiler data to be browsed.
   * <p>
   * WARNING - Feel free to make use of the classes shown in this example.
   *  but be aware that the API and package name are likely to change as
   *  the package is still experimental.
   * <p>
   * Note, this code ignores exceptions to keep the code simple.
   *
   * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/03/04 09:02:10 $
   * @since 4.1
   */
  public class Main
  {
      private static ProfilerComponentManager m_componentManager;
      private static DefaultProfilerManager   m_profilerManager;
      private static ProfilerFrame            m_profilerFrame;
      
      /*---------------------------------------------------------------
       * Constructors
       *-------------------------------------------------------------*/
      private Main() {}
      
      /*---------------------------------------------------------------
       * Methods
       *-------------------------------------------------------------*/
      /**
       * Creates and initializes the component manager using config files.
       */
      private static void createComponentManager()
          throws Exception
      {
          // Create a context to use.
          DefaultContext context = new DefaultContext();
          // Add any context variables here.
          context.makeReadOnly();
          
          // Create a ConfigurationBuilder to parse the config files.
          DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
          
          // Load in the configuration files
          Configuration logKitConfig     = builder.build( "../conf/logkit.xml" );
          Configuration profilerConfig   = builder.build( "../conf/profiler.xml" );
          Configuration rolesConfig      = builder.build( "../conf/roles.xml" );
          Configuration componentsConfig = builder.build( "../conf/components.xml" );
          
          // Setup the LogKitManager
          DefaultLogKitManager logManager = new DefaultLogKitManager();
          Logger lmLogger = Hierarchy.getDefaultHierarchy().
              getLoggerFor( logKitConfig.getAttribute( "logger", "lm" ) );
          lmLogger.setPriority( 
              Priority.getPriorityForName( logKitConfig.getAttribute( "log-level", "INFO"
) ) );
          logManager.setLogger( lmLogger );
          logManager.configure( logKitConfig );
          
          // Set up the Profiler Manager
          m_profilerManager = new DefaultProfilerManager();
          m_profilerManager.enableLogging( new LogKitLogger( logManager.getLogger( "pm" )
) );
          m_profilerManager.configure( profilerConfig );
          m_profilerManager.initialize();
          
          // Setup the RoleManager
          DefaultRoleManager roleManager = new DefaultRoleManager();
          roleManager.setLogger( 
              logManager.getLogger( rolesConfig.getAttribute( "logger", "rm" ) ) );
          roleManager.configure( rolesConfig );
          
          // Set up the ComponentManager
          m_componentManager = new ProfilerComponentManager();
          m_componentManager.setLogger( 
              logManager.getLogger( componentsConfig.getAttribute( "logger", "cm" ) ) );
          m_componentManager.setLogKitManager( logManager );
          m_componentManager.contextualize( context );
          m_componentManager.setProfilerManager( m_profilerManager ); // <-- Set the profiler
manager.
          m_componentManager.setRoleManager( roleManager );
          m_componentManager.configure( componentsConfig );
          m_componentManager.initialize();
          
          // Set up the ProfilerFrame
          m_profilerFrame = new ProfilerFrame( m_profilerManager, "Example Profiler" );
          m_profilerFrame.setVisible( true );
      }
      
      /*---------------------------------------------------------------
       * Main method
       *-------------------------------------------------------------*/
      /**
       * All of the guts of this example exist in the main method.
       */
      public static void main( String[] args )
          throws Exception
      {
          System.out.println( "Running the AltProfile Example Application" );
          
          // Create the ComponentManager
          createComponentManager();
          
          // Get a reference to the example component.
          ExampleProfilable profilable =
              (ExampleProfilable)m_componentManager.lookup( ExampleProfilable.ROLE );
          try
          {
              boolean quit = false;
              while ( !quit )
              {
                  System.out.println( "Enter the number of times that exampleAction should
be 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" ) ) )
                  {
                      quit = true;
                  }
                  else
                  {
                      try
                      {
                          int cnt = Integer.parseInt( cntStr );
                          for ( int i = 0; i < cnt; i++ )
                          {
                              profilable.doAction();
                          }
                      }
                      catch ( NumberFormatException e ) {}
                  }
              }
          }
          finally
          {
              // Release the component
              m_componentManager.release( profilable );
              profilable = null;
              
              // Hide the frame
              m_profilerFrame.setVisible( false );
              m_profilerFrame.dispose();
              m_profilerFrame = null;
              
              // Dispose the ComponentManager
              m_componentManager.dispose();
              m_componentManager = null;
              
              // Dispose the ProfilerManager
              m_profilerManager.dispose();
              m_profilerManager = null;
          }
          
          System.out.println();
          System.out.println( "Exiting..." );
          System.exit(0);
      }
  }
  
  
  
  

--
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