1 7 package test.compliance.core.notification; 8 9 import java.util.Timer ; 10 import java.util.TimerTask ; 11 import javax.management.ListenerNotFoundException ; 12 import javax.management.Notification ; 13 import javax.management.NotificationFilter ; 14 import javax.management.NotificationListener ; 15 import org.jboss.logging.Logger; 16 import org.jboss.mx.notification.AsynchNotificationBroadcasterSupport; 17 import org.jboss.mx.notification.NotificationFilterProxy; 18 import org.jboss.util.threadpool.BasicThreadPool; 19 import org.jboss.util.threadpool.BlockingMode; 20 import org.w3c.dom.Element ; 21 22 29 public class InvokerTest 30 extends AsynchNotificationBroadcasterSupport 31 implements InvokerTestMBean 32 { 33 static Logger log = Logger.getLogger(InvokerTest.class); 34 35 private CustomClass custom = new CustomClass("InitialValue"); 36 private NonserializableClass custom2 = new NonserializableClass(); 37 private Element xml; 38 39 public InvokerTest() 40 { 41 BasicThreadPool pool = new BasicThreadPool(); 42 pool.setBlockingMode(BlockingMode.RUN); 43 pool.setMaximumQueueSize(20); 44 pool.setMaximumPoolSize(1); 45 super.setThreadPool(pool); 46 50 super.setNotificationTimeout(1000); 51 } 52 53 56 public String getSomething() 57 { 58 return "something"; 59 } 60 61 public void addNotificationListener(NotificationListener listener, 62 NotificationFilter filter, Object handback) 63 { 64 log.info("addNotificationListener, listener: " + listener + ", handback: " + handback); 65 super.addNotificationListener(listener, filter, handback); 66 if(filter instanceof NotificationFilterProxy) 67 { 68 NotificationFilter delegateFilter = ((NotificationFilterProxy)filter).getFilter(); 69 if(delegateFilter instanceof RunTimerFilter) 70 { 71 Timer t = new Timer (); 72 Send10Notifies task = new Send10Notifies(); 73 t.scheduleAtFixedRate(task, 0, 1000); 74 } 75 } 76 } 77 78 public void removeNotificationListener(NotificationListener listener) 79 throws ListenerNotFoundException 80 { 81 log.info("removeNotificationListener, listener: " + listener); 82 super.removeNotificationListener(listener); 83 } 84 85 88 public CustomClass getCustom() 89 { 90 return custom; 91 } 92 93 96 public void setCustom(CustomClass custom) 97 { 98 this.custom = custom; 99 } 100 101 104 public NonserializableClass getNonserializableClass() 105 { 106 return custom2; 107 } 108 109 112 public void setNonserializableClass(NonserializableClass custom) 113 { 114 this.custom2 = custom; 115 } 116 117 120 public Element getXml() 121 { 122 return xml; 123 } 124 125 128 public void setXml(Element xml) 129 { 130 this.xml = xml; 131 } 132 133 136 public CustomClass doSomething(CustomClass custom) 137 { 138 return new CustomClass(custom.getValue()); 139 } 140 141 144 public CustomClass doSomething() 145 { 146 return new CustomClass(custom.getValue()); 147 } 148 149 152 public void stop() 153 { 154 stopThreadPool(true); 155 } 156 157 private class Send10Notifies extends TimerTask 158 { 159 int count; 160 161 164 public void run() 165 { 166 log.info("Sending notification on timer, count=" + count); 167 System.out.println("Sending notification on timer, count = " + count); 168 Notification notify = new Notification ("InvokerTest.timer", 169 InvokerTest.this, count); 170 InvokerTest.super.sendNotification(notify); 171 count++; 172 if(count == 10) 173 { 174 super.cancel(); 175 log.info("Cancelled timer"); 176 } 177 } 178 } 179 } 180 | Popular Tags |