1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.jour.rt.swingmonitor;
22
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.HashMap;
26 import java.util.Iterator;
27
28 import net.sf.jour.filter.MatchFilter;
29 import net.sf.jour.rt.agent.JVMInfoEvent;
30 import net.sf.jour.rt.view.ViewFilterItem;
31 import net.sf.jour.statistic.TimeBaseAccumulationList;
32
33 import org.apache.log4j.Logger;
34
35
36 /***
37 * TODO Add docs
38 *
39 * Created on 15.12.2004
40 * Contributing Author(s):
41 *
42 * Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
43 * Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
44 *
45 * @author vlads
46 * @version $Revision: 1.1 $ ($Author: vlads $) $Date: 2004/12/16 05:35:51 $
47 */
48 public class JMVRuntimeStatistics {
49
50 protected static final Logger log = Logger.getLogger(JMVRuntimeStatistics.class);
51
52 private HashMap hostJVMs = new HashMap();
53
54 public static final String ATTRIBUTE_HOST_NAME = "JMVRuntimeHost.NAME";
55
56 public JMVRuntimeStatistics() {
57
58 }
59
60 protected TimeBaseAccumulationList getByHost(JVMInfoEvent event, MatchFilter filter) {
61 if (event.getSystemInfo() == null) {
62 log.warn("No host info in JVMInfoEvent");
63 return null;
64 }
65 String hostName = event.getSystemInfo().getHostID();
66 TimeBaseAccumulationList memoryUsage = (TimeBaseAccumulationList)hostJVMs.get(hostName);
67
68 if (memoryUsage == null) {
69 memoryUsage = new TimeBaseAccumulationList();
70 memoryUsage.setAttribute(ATTRIBUTE_HOST_NAME, hostName);
71 synchronized (this) {
72 hostJVMs.put(hostName, memoryUsage);
73 }
74 }
75
76 return memoryUsage;
77 }
78
79 public boolean processEvent(JVMInfoEvent event, MatchFilter filter) {
80
81 TimeBaseAccumulationList memoryUsage = getByHost(event, filter);
82 if (memoryUsage == null) {
83 return false;
84 }
85
86 double usedMem = event.getTotalMemory() - event.getFreeMemory();
87
88 if ((memoryUsage.getCount() == 0) && (filter != null) && (filter instanceof ViewFilterItem)) {
89 memoryUsage.setTimeFrame(((ViewFilterItem)filter).getTimeFrame());
90 }
91 memoryUsage.add(event.getTimestamp(), new Double(usedMem));
92
93 return true;
94 }
95
96 public synchronized Collection getHostsJVM() {
97 return Collections.unmodifiableCollection(hostJVMs.values());
98 }
99
100 public synchronized void reset() {
101 Iterator iter = hostJVMs.values().iterator();
102 while (iter.hasNext()) {
103 TimeBaseAccumulationList j = (TimeBaseAccumulationList) iter.next();
104 j.reset();
105 }
106 }
107 }