1 22 package org.jboss.test.jmx.invoker; 23 24 import java.util.Timer ; 25 import java.util.TimerTask ; 26 import javax.management.ListenerNotFoundException ; 27 import javax.management.NotificationListener ; 28 import javax.management.NotificationFilter ; 29 import javax.management.Notification ; 30 import org.jboss.logging.Logger; 31 import org.jboss.mx.notification.AsynchNotificationBroadcasterSupport; 32 import org.jboss.mx.notification.NotificationFilterProxy; 33 import org.jboss.util.threadpool.BasicThreadPool; 34 import org.jboss.util.threadpool.BlockingMode; 35 import org.w3c.dom.Element ; 36 37 45 public class InvokerTest 46 extends AsynchNotificationBroadcasterSupport 47 implements InvokerTestMBean 48 { 49 static Logger log = Logger.getLogger(InvokerTest.class); 50 51 private CustomClass custom = new CustomClass("InitialValue"); 52 private NonserializableClass custom2 = new NonserializableClass(); 53 private Element xml; 54 55 public InvokerTest() 56 { 57 BasicThreadPool pool = new BasicThreadPool(); 58 pool.setBlockingMode(BlockingMode.RUN); 59 pool.setMaximumQueueSize(20); 60 pool.setMaximumPoolSize(1); 61 super.setThreadPool(pool); 62 66 super.setNotificationTimeout(1000); 67 } 68 69 72 public String getSomething() 73 { 74 return "something"; 75 } 76 77 public void addNotificationListener(NotificationListener listener, 78 NotificationFilter filter, Object handback) 79 { 80 log.info("addNotificationListener, listener: "+listener+", handback: "+handback); 81 super.addNotificationListener(listener, filter, handback); 82 if( "runTimer".equals(handback) ) 83 { 84 Timer t = new Timer (); 85 Send10Notifies task = new Send10Notifies(); 86 t.scheduleAtFixedRate(task, 0, 1000); 87 } 88 94 if(filter instanceof NotificationFilterProxy) 95 { 96 NotificationFilter delegateFilter = ((NotificationFilterProxy)filter).getFilter(); 97 if(delegateFilter instanceof RunTimerFilter) 98 { 99 Timer t = new Timer (); 100 Send10Notifies task = new Send10Notifies(); 101 t.scheduleAtFixedRate(task, 0, 1000); 102 } 103 } 104 105 } 106 107 public void removeNotificationListener(NotificationListener listener) 108 throws ListenerNotFoundException 109 { 110 log.info("removeNotificationListener, listener: "+listener); 111 super.removeNotificationListener(listener); 112 } 113 114 117 public CustomClass getCustom() 118 { 119 return custom; 120 } 121 122 125 public void setCustom(CustomClass custom) 126 { 127 this.custom = custom; 128 } 129 130 133 public NonserializableClass getNonserializableClass() 134 { 135 return custom2; 136 } 137 140 public void setNonserializableClass(NonserializableClass custom) 141 { 142 this.custom2 = custom; 143 } 144 145 148 public Element getXml() 149 { 150 return xml; 151 } 152 155 public void setXml(Element xml) 156 { 157 this.xml = xml; 158 } 159 160 163 public CustomClass doSomething(CustomClass custom) 164 { 165 return new CustomClass(custom.getValue()); 166 } 167 170 public CustomClass doSomething() 171 { 172 return new CustomClass(custom.getValue()); 173 } 174 175 178 public void stop() 179 { 180 stopThreadPool(true); 181 } 182 183 private class Send10Notifies extends TimerTask 184 { 185 int count; 186 189 public void run() 190 { 191 log.info("Sending notification on timer, count="+count); 192 Notification notify = new Notification ("InvokerTest.timer", 193 InvokerTest.this, count); 194 InvokerTest.super.sendNotification(notify); 195 count ++; 196 if( count == 10 ) 197 { 198 super.cancel(); 199 log.info("Cancelled timer"); 200 } 201 } 202 } 203 } 204 | Popular Tags |