You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2002/09/25 16:52:28 UTC
cvs commit: jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/util/system Linux.java Windows2000.java Windows95.java Windows98.java WindowsNT.java WindowsXP.java
bloritsch 2002/09/25 07:52:28
Added: event/src/java/org/apache/excalibur/util CPUParser.java
SystemUtil.java
event/src/java/org/apache/excalibur/util/system Linux.java
Windows2000.java Windows95.java Windows98.java
WindowsNT.java WindowsXP.java
Log:
move util stuff here
Revision Changes Path
1.1 jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/util/CPUParser.java
Index: CPUParser.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.excalibur.util;
/**
* This interface is for CPUParser objects that are automagically loaded, and
* perform architecture dependant processing for determining the number of CPUs,
* and the generic infomation about them.
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/09/25 14:52:28 $
*/
public interface CPUParser
{
/**
* Return the number of processors available on the machine
*/
int numProcessors();
/**
* 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}, ${vendor_id}
*/
String cpuInfo();
}
1.1 jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/util/SystemUtil.java
Index: SystemUtil.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.excalibur.util;
/**
* A set of utility operations that provide necessary information about the
* architecture of the machine that the system is running on. The values
* provided are automatically determined at JVM startup. The SystemUtils uses
* a plugin architecture so that it can be extended for more than just Linux/
* Windows support.
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/09/25 14:52:28 $
*/
public final class SystemUtil
{
private static final int m_processors;
private static final String m_cpuInfo;
private static final String m_architecture;
private static final String m_osName;
private static final String m_osVersion;
static
{
m_architecture = System.getProperty( "os.arch" );
m_osName = System.getProperty( "os.name" );
m_osVersion = System.getProperty( "os.version" );
int procs = 0;
String info = "";
try
{
String name = "org.apache.excalibur.util.system." +
StringUtil.stripWhitespace( m_osName );
Class klass = Class.forName( name );
CPUParser parser = (CPUParser)klass.newInstance();
procs = parser.numProcessors();
info = parser.cpuInfo();
}
catch( Exception e )
{
String proc = System.getProperty( "os.arch.cpus", "1" );
info = System.getProperty(
"os.arch.info",
m_architecture +
" Family n, Model n, Stepping n, Undeterminable"
);
procs = Integer.parseInt( proc );
}
m_processors = procs;
m_cpuInfo = info;
}
/** keep utility from being instantiated */
private SystemUtil()
{
}
/**
* Return the number of processors available on this machine. This is useful
* in classes like Thread/Processor thread pool models.
*/
public static final int numProcessors()
{
return m_processors;
}
public static final String cpuInfo()
{
return m_cpuInfo;
}
/**
* Return the architecture name
*/
public static final String architecture()
{
return m_architecture;
}
/**
* Return the Operating System name
*/
public static final String operatingSystem()
{
return m_osName;
}
/**
* Return the Operating System version
*/
public static final String osVersion()
{
return m_osVersion;
}
}
1.1 jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/util/system/Linux.java
Index: Linux.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.excalibur.util.system;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Properties;
import org.apache.excalibur.util.CPUParser;
import org.apache.excalibur.util.StringUtil;
/**
* Parses the Linux environment--Uses the proc filesystem to determine all the
* CPU information.
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/09/25 14:52:28 $
*/
public final class Linux implements CPUParser
{
private final int m_processors;
private final String m_cpuInfo;
public Linux()
{
int procs = 1;
String info = "";
try
{
BufferedReader reader = new BufferedReader( new FileReader( "/proc/cpuinfo" ) );
procs = 0;
Properties props = new Properties();
String line = null;
while( ( line = reader.readLine() ) != null )
{
String[] args = StringUtil.split( line, ":\t" );
if( args.length > 1 )
{
props.setProperty( args[ 0 ].trim(), args[ 1 ].trim() );
if( args[ 0 ].trim().equals( "processor" ) )
{
procs++;
}
}
}
StringBuffer buf = new StringBuffer();
buf.append( props.getProperty( "model name" ) );
buf.append( " Family " );
buf.append( props.getProperty( "cpu family" ) );
buf.append( " Model " );
buf.append( props.getProperty( "model" ) );
buf.append( " Stepping " );
buf.append( props.getProperty( "stepping" ) );
buf.append( ", " );
buf.append( props.getProperty( "vendor_id" ) );
info = buf.toString();
}
catch( Exception e )
{
procs = 1;
e.printStackTrace();
}
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;
}
}
1.1 jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/util/system/Windows2000.java
Index: Windows2000.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.excalibur.util.system;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.apache.excalibur.util.CPUParser;
/**
* Parses the Windows 2000 environment--the same class should work for other
* Windows versions, but I only have one to test.
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/09/25 14:52:28 $
*/
public final class Windows2000 implements CPUParser
{
private final int m_processors;
private final String m_cpuInfo;
public Windows2000()
{
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;
}
}
1.1 jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/util/system/Windows95.java
Index: Windows95.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.excalibur.util.system;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.apache.excalibur.util.CPUParser;
/**
* Parses the Windows 95 environment--the same class should work for other
* Windows versions, but I only have one to test. Windows 9x environments
* can only use one processor--even if there are more installed in the system.
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/09/25 14:52:28 $
*/
public final class Windows95 implements CPUParser
{
private final int m_processors = 1;
private final String m_cpuInfo;
public Windows95()
{
String info = "";
try
{
// This is not the propper environment variable for Win 9x
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec( "command.com /C echo %PROCESSOR_IDENTIFIER%" );
BufferedReader reader = new BufferedReader( new InputStreamReader( proc.getInputStream() ) );
info = reader.readLine();
}
catch( Exception e )
{
}
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;
}
}
1.1 jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/util/system/Windows98.java
Index: Windows98.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.excalibur.util.system;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.apache.excalibur.util.CPUParser;
/**
* Parses the Windows 98 environment--the same class should work for other
* Windows versions, but I only have one to test. Windows 9x environments
* can only use one processor--even if there are more installed in the system.
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/09/25 14:52:28 $
*/
public final class Windows98 implements CPUParser
{
private final int m_processors = 1;
private final String m_cpuInfo;
public Windows98()
{
String info = "";
try
{
// This is not the propper environment variable for Win 9x
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec( "command.com /C echo %PROCESSOR_IDENTIFIER%" );
BufferedReader reader = new BufferedReader( new InputStreamReader( proc.getInputStream() ) );
info = reader.readLine();
}
catch( Exception e )
{
}
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;
}
}
1.1 jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/util/system/WindowsNT.java
Index: WindowsNT.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.excalibur.util.system;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.apache.excalibur.util.CPUParser;
/**
* Parses the Windows 2000 environment--the same class should work for other
* Windows versions, but I only have one to test.
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/09/25 14:52:28 $
*/
public final class WindowsNT implements CPUParser
{
private final int m_processors;
private final String m_cpuInfo;
public WindowsNT()
{
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;
}
}
1.1 jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/util/system/WindowsXP.java
Index: WindowsXP.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.excalibur.util.system;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.apache.excalibur.util.CPUParser;
/**
* Parses the Windows 2000 environment--the same class should work for other
* Windows versions, but I only have one to test.
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/09/25 14:52:28 $
*/
public final class WindowsXP implements CPUParser
{
private final int m_processors;
private final String m_cpuInfo;
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;
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>