1 17 package org.apache.jmeter.visualizers; 18 19 import java.io.Serializable ; 20 21 import org.apache.jmeter.samplers.Clearable; 22 23 import java.text.SimpleDateFormat ; 24 import java.util.Date ; 25 import java.util.LinkedList ; 26 import java.util.List ; 27 28 public class MonitorModel implements Clearable, Serializable , Cloneable 29 { 30 31 private List listeners; 33 private MonitorStats current = 34 new MonitorStats(0,0,0,0,0,"","","",System.currentTimeMillis()); 35 36 39 public MonitorModel() 40 { 41 super(); 42 listeners = new LinkedList (); 43 } 44 45 public MonitorModel(MonitorStats stat){ 46 this.current = stat; 47 } 48 public void setName(String name){ 49 } 51 52 public String getName(){ 53 return this.getURL(); 54 } 55 56 public int getHealth(){ 57 return this.current.health; 58 } 59 60 public int getLoad(){ 61 return this.current.load; 62 } 63 64 public int getCpuload(){ 65 return this.current.cpuload; 66 } 67 68 public int getMemload(){ 69 return this.current.memload; 70 } 71 72 public int getThreadload(){ 73 return this.current.threadload; 74 } 75 76 public String getHost(){ 77 return this.current.host; 78 } 79 80 public String getPort(){ 81 return this.current.port; 82 } 83 84 public String getProtocol(){ 85 return this.current.protocol; 86 } 87 88 public long getTimestamp(){ 89 return this.current.timestamp; 90 } 91 92 public String getURL(){ 93 return this.current.getURL(); 94 } 95 96 101 public String getTimestampString(){ 102 Date date = new Date (this.current.timestamp); 103 SimpleDateFormat ft = new SimpleDateFormat (); 104 return ft.format(date); 105 } 106 107 111 public String toString(){ 112 return getURL(); 113 } 114 115 118 public void clear() 119 { 120 current = 121 new MonitorStats(0,0,0,0,0,"","","",System.currentTimeMillis()); 122 } 123 124 128 public void notifyListeners(MonitorModel model) 129 { 130 for (int idx=0; idx < listeners.size(); idx++){ 131 MonitorListener ml = (MonitorListener)listeners.get(idx); 132 ml.addSample(model); 133 } 134 } 135 136 public void addListener(MonitorListener listener){ 137 listeners.add(listener); 138 } 139 140 144 public Object clone(){ 145 MonitorStats newstats = 146 new MonitorStats(current.health, 147 current.load, 148 current.cpuload, 149 current.memload, 150 current.threadload, 151 current.host, 152 current.port, 153 current.protocol, 154 current.timestamp); 155 return new MonitorModel(newstats); 156 } 157 } 158 | Popular Tags |