KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > util > system > WindowsNT


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.excalibur.util.system;
18
19 import java.io.BufferedReader JavaDoc;
20 import java.io.InputStreamReader JavaDoc;
21
22 import org.apache.excalibur.util.CPUParser;
23
24 /**
25  * Parses the Windows 2000 environment--the same class should work for other
26  * Windows versions, but I only have one to test.
27  *
28  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
29  * @version CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:29 $
30  */

31 public final class WindowsNT implements CPUParser
32 {
33     private final int m_processors;
34     private final String JavaDoc m_cpuInfo;
35
36     public WindowsNT()
37     {
38         int procs = 1;
39         String JavaDoc info = "";
40
41         try
42         {
43             Runtime JavaDoc rt = Runtime.getRuntime();
44             Process JavaDoc proc = rt.exec( "cmd.exe /C echo %NUMBER_OF_PROCESSORS%" );
45             BufferedReader JavaDoc reader = new BufferedReader JavaDoc( new InputStreamReader JavaDoc(
46                 proc.getInputStream() ) );
47             String JavaDoc numProcs = reader.readLine();
48
49             proc = rt.exec( "cmd.exe /C echo %PROCESSOR_IDENTIFIER%" );
50             reader = new BufferedReader JavaDoc( new InputStreamReader JavaDoc( proc.getInputStream() ) );
51             info = reader.readLine();
52
53             procs = Integer.parseInt( numProcs );
54         }
55         catch( Exception JavaDoc e )
56         {
57         }
58
59         m_processors = procs;
60         m_cpuInfo = info;
61     }
62
63     /**
64      * Return the number of processors available on the machine
65      */

66     public int numProcessors()
67     {
68         return m_processors;
69     }
70
71     /**
72      * Return the cpu info for the processors (assuming symetric multiprocessing
73      * which means that all CPUs are identical). The format is:
74      *
75      * ${arch} family ${family} Model ${model} Stepping ${stepping}, ${identifier}
76      */

77     public String JavaDoc cpuInfo()
78     {
79         return m_cpuInfo;
80     }
81 }
82
83
Popular Tags