KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > myvietnam > mvncore > info > SystemInfo


1 /*
2  * $Header: /cvsroot/mvnforum/myvietnam/src/net/myvietnam/mvncore/info/SystemInfo.java,v 1.9 2006/04/15 02:59:19 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.9 $
5  * $Date: 2006/04/15 02:59:19 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding MyVietnam and MyVietnam CoreLib
12  * MUST remain intact in the scripts and source code.
13  *
14  * This library is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU Lesser General Public
16  * License as published by the Free Software Foundation; either
17  * version 2.1 of the License, or (at your option) any later version.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27  *
28  * Correspondence and Marketing Questions can be sent to:
29  * info at MyVietnam net
30  *
31  * @author: Minh Nguyen
32  * @author: Mai Nguyen
33  */

34 package net.myvietnam.mvncore.info;
35
36 public class SystemInfo {
37
38     private String JavaDoc vmName;
39     private String JavaDoc vmVendor;
40     private String JavaDoc vmVersion;
41     private String JavaDoc runtimeName;
42     private String JavaDoc runtimeVersion;
43     private String JavaDoc osName;
44     private String JavaDoc osVersion;
45     private String JavaDoc cpu;
46
47     long totalMemory = 0;
48     long freeMemory = 0;
49     long totalMemoryKB = 0;
50     long freeMemoryKB = 0;
51
52     public SystemInfo() {
53         vmName = getProperty("java.vm.name");
54         vmVendor = getProperty("java.vm.vendor");
55         vmVersion = getProperty("java.vm.version");
56         runtimeName = getProperty("java.runtime.name");
57         runtimeVersion = getProperty("java.runtime.version");
58         osName = getProperty("os.name");
59         osVersion = getProperty("os.version");
60         cpu = getProperty("sun.cpu.isalist");
61
62         Runtime JavaDoc runtime = Runtime.getRuntime();
63         totalMemory = runtime.totalMemory();
64         freeMemory = runtime.freeMemory();
65         totalMemoryKB = totalMemory/1024;
66         freeMemoryKB = freeMemory/1024;
67     }
68
69     public static String JavaDoc getProperty(String JavaDoc key) {
70         String JavaDoc retValue = null;
71         try {
72             retValue = System.getProperty(key, "");
73         } catch (Exception JavaDoc ex) {
74             retValue = "no access";
75         }
76         return retValue;
77     }
78
79     public String JavaDoc getCpu() {
80         return cpu;
81     }
82
83     public String JavaDoc getOsName() {
84         return osName;
85     }
86
87     public String JavaDoc getOsVersion() {
88         return osVersion;
89     }
90
91     public String JavaDoc getRuntimeName() {
92         return runtimeName;
93     }
94
95     public String JavaDoc getRuntimeVersion() {
96         return runtimeVersion;
97     }
98
99     public String JavaDoc getVmName() {
100         return vmName;
101     }
102
103     public String JavaDoc getVmVendor() {
104         return vmVendor;
105     }
106
107     public String JavaDoc getVmVersion() {
108         return vmVersion;
109     }
110
111     public long getFreeMemory() {
112         return freeMemory;
113     }
114
115     public long getFreeMemoryKB() {
116         return freeMemoryKB;
117     }
118
119     public long getTotalMemory() {
120         return totalMemory;
121     }
122
123     public long getTotalMemoryKB() {
124         return totalMemoryKB;
125     }
126 }
127
Popular Tags