1 | 0 | |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
package pt.digitalis.dif.utils.system; |
7 | |
|
8 | |
import java.io.InputStream; |
9 | |
import java.lang.management.ManagementFactory; |
10 | |
import java.net.InetAddress; |
11 | |
import java.net.URL; |
12 | |
import java.net.UnknownHostException; |
13 | |
import java.util.Enumeration; |
14 | |
import java.util.Map; |
15 | |
import java.util.jar.Attributes; |
16 | |
import java.util.jar.JarFile; |
17 | |
import java.util.jar.Manifest; |
18 | |
|
19 | |
import pt.digitalis.utils.common.collections.IndexedHashMap; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | 0 | public class SystemUtils { |
28 | |
|
29 | |
|
30 | |
static private String jbossTagCache; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public static String getJBossVersion() |
38 | |
{ |
39 | 0 | if (jbossTagCache == null) |
40 | |
{ |
41 | 0 | Manifest manifest = null; |
42 | |
Enumeration<URL> resEnum; |
43 | |
try |
44 | |
{ |
45 | 0 | resEnum = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME); |
46 | 0 | while (resEnum.hasMoreElements()) |
47 | |
{ |
48 | 0 | URL url = resEnum.nextElement(); |
49 | 0 | InputStream is = url.openStream(); |
50 | 0 | if (is != null) |
51 | |
{ |
52 | 0 | Manifest manifestTemp = new Manifest(is); |
53 | 0 | Attributes mainAttribs = manifestTemp.getMainAttributes(); |
54 | 0 | String title = mainAttribs.getValue(Attributes.Name.IMPLEMENTATION_TITLE); |
55 | 0 | if (title != null && title.toUpperCase().contains("JBOSS")) |
56 | |
{ |
57 | 0 | manifest = manifestTemp; |
58 | 0 | break; |
59 | |
} |
60 | |
} |
61 | |
} |
62 | |
} |
63 | 0 | catch (Exception e) |
64 | |
{ |
65 | |
|
66 | |
} |
67 | |
|
68 | 0 | if (manifest == null) |
69 | 0 | jbossTagCache = "Unknown"; |
70 | |
else |
71 | |
{ |
72 | 0 | jbossTagCache = manifest.getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_TITLE) + " v." |
73 | 0 | + manifest.getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION); |
74 | |
} |
75 | |
} |
76 | |
|
77 | 0 | return jbossTagCache; |
78 | |
} |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
public static Map<String, Object> getSystemProperties() |
86 | |
{ |
87 | 0 | Map<String, Object> props = new IndexedHashMap<String, Object>(); |
88 | |
try |
89 | |
{ |
90 | 0 | props.put("COMPUTERNAME", InetAddress.getLocalHost().getHostName()); |
91 | |
} |
92 | 0 | catch (UnknownHostException e) |
93 | |
{ |
94 | 0 | props.put("COMPUTERNAME", System.getenv().get("COMPUTERNAME")); |
95 | |
} |
96 | |
|
97 | 0 | String OS = System.getenv().get("OS"); |
98 | 0 | if (OS == null || "".equals(OS)) |
99 | |
{ |
100 | 0 | OS = System.getProperty("os.name") + " " + System.getProperty("os.version") + "," |
101 | 0 | + System.getProperty("os.arch"); |
102 | |
} |
103 | |
|
104 | 0 | props.put("OS", OS); |
105 | 0 | props.put("USERDOMAIN", System.getenv().get("USERDOMAIN")); |
106 | 0 | props.put("USERNAME", System.getenv().get("USERNAME")); |
107 | |
|
108 | 0 | if (System.getenv().get("PROCESSOR_ARCHITECTURE") != null) |
109 | |
{ |
110 | 0 | props.put("PROCESSOR_ARCHITECTURE", System.getenv().get("PROCESSOR_ARCHITECTURE")); |
111 | |
} |
112 | |
else |
113 | |
{ |
114 | 0 | props.put("PROCESSOR_ARCHITECTURE", ManagementFactory.getOperatingSystemMXBean().getArch()); |
115 | |
|
116 | |
} |
117 | |
|
118 | 0 | props.put("PROCESSOR_IDENTIFIER", System.getenv().get("PROCESSOR_IDENTIFIER")); |
119 | |
|
120 | 0 | props.put("javaVersion", System.getProperty("java.vendor") + " (v." + System.getProperty("java.version") + ")" |
121 | 0 | + " - VM: " + System.getProperty("java.vm.name") + " " + System.getProperty("java.vm.version") + "," |
122 | 0 | + System.getProperty("java.vm.vendor")); |
123 | 0 | props.put("jBossVersion", getJBossVersion()); |
124 | |
|
125 | 0 | props.put("totalMemory", Runtime.getRuntime().totalMemory() / 1024 / 1024 + " Mb"); |
126 | 0 | props.put("maxMemory", Runtime.getRuntime().maxMemory() / 1024 / 1024 + " Mb"); |
127 | 0 | props.put("freeMemory", Runtime.getRuntime().freeMemory() / 1024 / 1024 + " Mb"); |
128 | 0 | props.put("processorNumber", Runtime.getRuntime().availableProcessors()); |
129 | |
|
130 | 0 | return props; |
131 | |
} |
132 | |
} |