1 22 23 package org.jboss.ha.jmx.examples; 24 25 import java.util.Collection ; 26 import java.util.LinkedList ; 27 28 import javax.management.Notification ; 29 import javax.management.NotificationListener ; 30 31 import org.jboss.ha.jmx.HAServiceMBeanSupport; 32 33 42 public class HANotificationBroadcasterExample 43 extends HAServiceMBeanSupport 44 implements HANotificationBroadcasterExampleMBean 45 { 46 47 52 protected void startService() throws Exception 53 { 54 super.startService(); 55 addNotificationListener(listener_, null, null); 56 } 57 58 63 protected void stopService() throws Exception 64 { 65 removeNotificationListener(listener_); 66 super.stopService(); 67 } 68 69 76 public void sendTextMessage(String message) 77 { 78 long now = System.currentTimeMillis(); 79 Notification notification = 80 new Notification ("hanotification.example.counter", super.getServiceName(), now, now, message); 81 sendNotification(notification); 82 } 83 84 87 public Collection getReceivedNotifications() 88 { 89 return messages_; 90 } 91 92 93 Collection messages_ = new LinkedList (); 94 95 NotificationListener listener_ = new NotificationListener () 96 { 97 public void handleNotification(Notification notification, 98 java.lang.Object handback) 99 { 100 messages_.add( notification.getMessage() ); 101 } 102 }; 103 104 } 105 | Popular Tags |