1 10 11 package org.mule.management.stats; 12 13 import org.mule.management.stats.printers.SimplePrinter; 14 import org.mule.umo.endpoint.UMOEndpoint; 15 import org.mule.umo.endpoint.UMOImmutableEndpoint; 16 17 import java.io.PrintWriter ; 18 import java.util.ArrayList ; 19 import java.util.Collection ; 20 import java.util.HashMap ; 21 import java.util.List ; 22 import java.util.Map ; 23 24 30 public class RouterStatistics implements Statistics 31 { 32 33 36 private static final long serialVersionUID = 4540482357430845065L; 37 38 public static final int TYPE_INBOUND = 1; 39 public static final int TYPE_OUTBOUND = 2; 40 public static final int TYPE_RESPONSE = 3; 41 42 private boolean enabled; 43 private long notRouted; 44 private long caughtInCatchAll; 45 private long totalRouted; 46 private long totalReceived; 47 private Map routed; 48 private int type; 49 50 53 public synchronized void clear() 54 { 55 notRouted = 0; 56 totalRouted = 0; 57 totalReceived = 0; 58 caughtInCatchAll = 0; 59 routed.clear(); 60 } 61 62 65 public boolean isEnabled() 66 { 67 return enabled; 68 } 69 70 public void logSummary() 71 { 72 logSummary(new SimplePrinter(System.out)); 73 } 74 75 public void logSummary(PrintWriter printer) 76 { 77 printer.print(this); 78 } 79 80 83 public synchronized void setEnabled(boolean b) 84 { 85 enabled = b; 86 } 87 88 91 public RouterStatistics(int type) 92 { 93 super(); 94 this.type = type; 95 routed = new HashMap (); 96 } 97 98 103 public void incrementRoutedMessage(Collection endpoints) 104 { 105 if (endpoints == null || endpoints.isEmpty()) 106 { 107 return; 108 } 109 List list = new ArrayList (endpoints); 110 synchronized (list) 111 { 112 for (int i = 0; i < list.size(); i++) 113 { 114 incrementRoutedMessage((UMOEndpoint)list.get(i)); 115 } 116 } 117 } 118 119 124 public synchronized void incrementRoutedMessage(UMOImmutableEndpoint endpoint) 125 { 126 if (endpoint == null) 127 { 128 return; 129 } 130 131 String name = endpoint.getName(); 132 133 Long cpt = (Long )routed.get(name); 134 long count = 0; 135 136 if (cpt != null) 137 { 138 count = cpt.longValue(); 139 } 140 141 routed.put(name, new Long (++count)); 144 145 totalRouted++; 146 totalReceived++; 147 } 148 149 152 public synchronized void incrementNoRoutedMessage() 153 { 154 notRouted++; 155 totalReceived++; 156 } 157 158 161 public synchronized void incrementCaughtMessage() 162 { 163 caughtInCatchAll++; 164 } 165 166 169 public final long getCaughtMessages() 170 { 171 return caughtInCatchAll; 172 } 173 174 177 public final long getNotRouted() 178 { 179 return notRouted; 180 } 181 182 185 public final long getTotalReceived() 186 { 187 return totalReceived; 188 } 189 190 193 public final long getTotalRouted() 194 { 195 return totalRouted; 196 } 197 198 201 public final long getRouted(String endpointName) 202 { 203 Long l = (Long )routed.get(endpointName); 204 205 if (l == null) 206 { 207 return 0; 208 } 209 else 210 { 211 return l.longValue(); 212 } 213 } 214 215 public boolean isInbound() 216 { 217 return type == TYPE_INBOUND; 218 } 219 220 public Map getRouted() 221 { 222 return routed; 223 } 224 } 225 | Popular Tags |