KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > ui > common > component > debug > UISystemProperties


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.ui.common.component.debug;
18
19 import java.util.Map JavaDoc;
20 import java.util.TreeMap JavaDoc;
21
22 /**
23  * Component which displays the system properties of the VM
24  *
25  * @author gavinc
26  */

27 public class UISystemProperties extends BaseDebugComponent
28 {
29    /**
30     * @see javax.faces.component.UIComponent#getFamily()
31     */

32    public String JavaDoc getFamily()
33    {
34       return "org.alfresco.faces.debug.SystemProperties";
35    }
36
37    /**
38     * @see org.alfresco.web.ui.common.component.debug.BaseDebugComponent#getDebugData()
39     */

40    @SuppressWarnings JavaDoc("unchecked")
41    public Map JavaDoc getDebugData()
42    {
43       // note: sort properties
44
Map JavaDoc properties = new TreeMap JavaDoc();
45       
46       // add the jvm system properties
47
Map JavaDoc systemProperties = System.getProperties();
48       properties.putAll(systemProperties);
49       
50       // add heap size properties
51
properties.put("heap.size", formatBytes(Runtime.getRuntime().totalMemory()));
52       properties.put("heap.maxsize", formatBytes(Runtime.getRuntime().maxMemory()));
53       properties.put("heap.free", formatBytes(Runtime.getRuntime().freeMemory()));
54       
55       return properties;
56    }
57    
58    /**
59     * Helper to format bytes for human output
60     *
61     * @param bytes bytes
62     * @return formatted string
63     */

64    private static String JavaDoc formatBytes(long bytes)
65    {
66        float f = bytes / 1024l;
67        f = f / 1024l;
68        return String.format("%.3fMB (%d bytes)", f, bytes);
69    }
70 }
71
Popular Tags