KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > diagnostics > collect > WindowsSystemInfoCollector


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.diagnostics.collect;
24
25 import com.sun.logging.LogDomains;
26 import com.sun.enterprise.diagnostics.Data;
27 import com.sun.enterprise.diagnostics.Defaults;
28
29
30 import java.util.logging.Logger JavaDoc;
31 import java.util.logging.Level JavaDoc;
32 import java.io.File JavaDoc;
33
34 /**
35  * Class to collect System Information for Windows OS
36  */

37 public class WindowsSystemInfoCollector implements Collector{
38
39     private static Logger JavaDoc logger =
40             LogDomains.getLogger(LogDomains.ADMIN_LOGGER);
41
42     /* Command for properties */
43     private static final String JavaDoc MEMORY_INFO_CMD = "mem";
44     private static final String JavaDoc IP_ADDRESS_INFO_CMD = "ipconfig";
45     private static final String JavaDoc HOST_NAME_CMD = "hostname";
46     private static final String JavaDoc OS_INFO_CMD = "ver";
47
48     private String JavaDoc destFolder = null;
49
50
51     public WindowsSystemInfoCollector(String JavaDoc destFolder){
52         this.destFolder = destFolder;
53     }
54
55     /**
56      * To capture the system information for Windows OS
57      * @return Data representing System Information
58      */

59     public Data capture(){
60
61         FileData data = null;
62
63         String JavaDoc outputFileName = destFolder + File.separator + Defaults.SYSTEM_INFO_FILE;
64
65         final String JavaDoc ALL_CMDS =
66
67                 "(echo HOSTNAME & "+HOST_NAME_CMD+" & " +
68                         "echo OS INFO & "+ OS_INFO_CMD +" & " +
69                         "echo MEMORY INFO & " + MEMORY_INFO_CMD + " & " +
70         "echo IP ADDRESS & " + IP_ADDRESS_INFO_CMD + ") >> " + outputFileName ;
71
72
73         String JavaDoc[] cmd = {"cmd.exe", "/C", ALL_CMDS};
74
75         ProcessExecutor executor = new ProcessExecutor(cmd, 0);
76         try{
77         executor.execute();
78
79         File JavaDoc outputFile = new File JavaDoc(outputFileName);
80
81         data = new FileData(outputFile.getName(),DataType.SYSTEM_INFO);
82
83         }
84         catch(ProcessExecutorException pee){
85             logger.log(Level.WARNING, "Exception while capturing system info" +
86                      " : " + pee.getMessage());
87         }
88         
89         return data;
90     }
91 }
92
Popular Tags