SystemUtil determines which CPUParser it needs by examining
the results from
System.getProperty( "os.name" )
.
It strips all the whitespace from the name, and appends it
to the
org.apache.excalibur.util.system
package.
For example, if the "os.name" property returns "Windows XP",
then the full class name needs to be
org.apache.excalibur.util.system.WindowsXP
.
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
org.apache.excalibur.util.system
package and
implement the CPUParser interface. The example below is
taken from the WindowsXP CPUParser included in this project.
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: 2004/04/04 16:26:18 $ */ 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; } }