avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/event/src/xdocs cpuparser-howto.xml
Date Thu, 26 Sep 2002 18:34:55 GMT
bloritsch    2002/09/26 11:34:55

  Added:       event/src/xdocs cpuparser-howto.xml
  Log:
  oops, now I am committing the CPUParser-howto docs.
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/event/src/xdocs/cpuparser-howto.xml
  
  Index: cpuparser-howto.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <document>
    <header>
      <title>Excalibur Event - How To Extend System Util</title>
      <authors>
        <person name="Berin Loritsch" email="bloritsch@apache.org"/>
      </authors>
    </header>
    <body>
      <s1 title="System Util Design">
        <p>
          SystemUtil determins which CPUParser it needs by examining
          the results from <code>System.getProperty( "os.name" )</code>.
          It strips all the whitespace from the name, and appends it
          to the <code>org.apache.excalibur.util.system</code> package.
          For example, if the "os.name" property returns "Windows XP",
          then the full class name needs to be
          <code>org.apache.excalibur.util.system.WindowsXP</code>.
        </p>
      </s1>
      <s1 title="Writing a CPUParser">
        <p>
          Writing a CPUParser is not hard.  You only need to know
          how to name your implementation, and then write the relevant
          logic.  All CPUParser implementations must be in the
          <code>org.apache.excalibur.util.system</code> package and
          implement the CPUParser interface.  The example below is
          taken from the WindowsXP CPUParser included in this project.
        </p>
        <source>
  <![CDATA[
  package org.apache.excalibur.util.system;
  
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import org.apache.excalibur.util.CPUParser;
  
  /**
   * Parses the Windows XP environment
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/09/26 18:34:55 $
   */
  public final class WindowsXP implements CPUParser
  {
      private final int m_processors;
      private final String m_cpuInfo;
  
      /**
       * Create this instance of CPUParser and gather information from
       * the Windows XP system.
       */
      public WindowsXP()
      {
          int procs = 1;
          String info = "";
  
          try
          {
              Runtime rt = Runtime.getRuntime();
              Process proc = rt.exec( "cmd.exe /C echo %NUMBER_OF_PROCESSORS%" );
              BufferedReader reader = new BufferedReader( new InputStreamReader(
                  proc.getInputStream() ) );
              String numProcs = reader.readLine();
  
              proc = rt.exec( "cmd.exe /C echo %PROCESSOR_IDENTIFIER%" );
              reader = new BufferedReader( new InputStreamReader( proc.getInputStream() )
);
              info = reader.readLine();
  
              procs = Integer.parseInt( numProcs );
          }
          catch( Exception e )
          {
          }
  
          m_processors = procs;
          m_cpuInfo = info;
      }
  
      /**
       * Return the number of processors available on the machine
       */
      public int numProcessors()
      {
          return m_processors;
      }
  
      /**
       * Return the cpu info for the processors (assuming symetric multiprocessing
       * which means that all CPUs are identical).  The format is:
       *
       * ${arch} family ${family} Model ${model} Stepping ${stepping}, ${identifier}
       */
      public String cpuInfo()
      {
          return m_cpuInfo;
      }
  }
  
  ]]>
        </source>
      </s1>
    </body>
    <footer>
      <legal>
        Copyright (c) @year@ The Jakarta Apache Project All rights reserved.
        $Revision: 1.1 $ $Date: 2002/09/26 18:34:55 $
      </legal>
    </footer>
  </document>
  
  
  

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