01: package com.bostechcorp.cbesb.console.server.test;
02:
03: import java.util.concurrent.ConcurrentHashMap;
04: import java.util.concurrent.TimeUnit;
05:
06: import javax.management.MBeanServerConnection;
07: import javax.management.MBeanServerInvocationHandler;
08: import javax.management.Notification;
09: import javax.management.ObjectName;
10:
11: import junit.framework.TestCase;
12:
13: import com.bostechcorp.cbesb.common.util.runtimedb.vo.EndpointStatVO;
14: import com.bostechcorp.cbesb.console.jmxclient.BaseJmxClient;
15: import com.bostechcorp.cbesb.console.jmxclient.ClientListener;
16: import com.bostechcorp.cbesb.console.jmxclient.JmxClient;
17: import com.bostechcorp.cbesb.console.jmxclient.JmxClientFactory;
18: import com.bostechcorp.cbesb.console.jmxclient.ServicemixJmxClient;
19: import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.LifeCycleExtensionMBean;
20: import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.notification.StatisticChangeNotification;
21:
22: public class TestStatistics extends TestCase {
23: public void testStat() {
24: try {
25: JmxClient jmxClient = JmxClientFactory.getDefaultClient();
26: if (jmxClient instanceof ServicemixJmxClient) {
27: ServicemixJmxClient servicemixJmxClient = (ServicemixJmxClient) jmxClient;
28: MBeanServerConnection mbsc = servicemixJmxClient
29: .getServerConnection();
30: ClientListener listener = new ClientListener();
31: ObjectName name = servicemixJmxClient
32: .getLifeCycleExtensionMbeanName(BaseJmxClient.BOOTSTRAP_COMP);
33: System.out.println(name);
34: Object o = MBeanServerInvocationHandler
35: .newProxyInstance(mbsc, name,
36: LifeCycleExtensionMBean.class, true);
37: if (o == null) {
38: System.out.println("invalid name");
39: }
40: mbsc
41: .addNotificationListener(name, listener, null,
42: null);
43:
44: do {
45: Notification notification = (Notification) listener
46: .getStatisticNotificationQueue().poll(
47: 70000, TimeUnit.MILLISECONDS);
48: if (notification != null) {
49: ConcurrentHashMap<String, EndpointStatVO> result = ((StatisticChangeNotification) notification)
50: .getStatMap();
51:
52: System.out.println(result.size());
53: for (EndpointStatVO stat : result.values()) {
54: System.out.println(stat.getEndpointName());
55: System.out.println(stat.getMessagesCount());
56: System.out.println(stat
57: .getMessagesPerSecond());
58: System.out.println(stat.getLatency());
59:
60: }
61: }
62: } while (true);
63: }
64: } catch (Exception e) {
65: // TODO Auto-generated catch block
66: e.printStackTrace();
67: }
68: }
69: }
|