/*
 * $Log: ProcessMetrics.java,v $
 * Revision 1.2  2006-07-10 14:36:29  europe\L190409
 * added currentTime, separate function normalizedNotation()
 *
 * Revision 1.1  2004/07/20 13:27:29  Gerrit van Brakel <gerrit.van.brakel@ibissource.org>
 * first version
 *
 *  */
package nl.nn.adapterframework.util;

import java.util.Date;

/**
 * Utility class to report process parameters like memory usage as an xml-element.
 * 
 * @since 4.2
 */
public class ProcessMetrics {

	private final static long K_LIMIT=10*1024;
	private final static long M_LIMIT=K_LIMIT*1024;
	private final static long G_LIMIT=M_LIMIT*1024;
	private final static long T_LIMIT=G_LIMIT*1024;
	
	public static String normalizedNotation(long value) {
		String valueString;
		
		if (value < K_LIMIT) {
			valueString = Long.toString(value);
		} else {
			if (value < M_LIMIT) {
				valueString = Long.toString(value/1024)+"K";
			} else { 
				if (value < G_LIMIT) {
					valueString = Long.toString(value/(1024*1024))+"M";
				} else { 
					if (value < T_LIMIT) {
						valueString = Long.toString(value/(1024*1024*1024))+"G";
					} else { 
						valueString = Long.toString(value/(1024*1024*1024*1024))+"T";
					}
				}
			}
		}
		return valueString;
	}
	
	public static void addNumberProperty(XmlBuilder list, String name, long value) {
		addProperty(list,name,normalizedNotation(value));
	}
	
	public static void addProperty(XmlBuilder list, String name, String value) {
		XmlBuilder p=new XmlBuilder("property");
		p.addAttribute("name", name);
		p.setValue(value);
		list.addSubElement(p);
	}

	public static String toXml() {
		XmlBuilder xmlh=new XmlBuilder("processMetrics");
		XmlBuilder props=new XmlBuilder("properties");
		xmlh.addSubElement(props);
		
		long freeMem = Runtime.getRuntime().freeMemory();
		long totalMem = Runtime.getRuntime().totalMemory();
		
		addNumberProperty(props, "freeMemory", freeMem);
		addNumberProperty(props, "totalMemory", totalMem);
		addNumberProperty(props, "heapSize", totalMem-freeMem);
		Date d = new Date();
		addProperty(props, "currentTime", (Long.toString(d.getTime())));
		return xmlh.toXML();
	}


}

@@ -47,17 +47,17 @@
 n 1.
-2
+3
   2006-0
 7-10
@@ -56,21 +56,21 @@
 06-0
-7-10 14:36:29
+8-21 15:15:43
   eu
@@ -82,16 +82,146 @@
 L190409%0A
+ * correctly formatted current time%0A *%0A * Revision 1.2  2006/07/10 14:36:29  Gerrit van Brakel %3Cgerrit.van.brakel@ibissource.org%3E%0A
  * added
@@ -2135,31 +2135,8 @@
 m);%0A
-%09%09Date d = new Date();%0A
 %09%09ad
@@ -2171,35 +2171,65 @@
 e%22, 
-(Long.toString(d.getTime())
+DateUtils.format(new Date(),DateUtils.FORMAT_FULL_GENERIC
 ));%0A

correctly formatted current time