[jboss-user] [Management, JMX/JBoss] - Receiving notification from other MBeans

joshua883 do-not-reply at jboss.com
Mon Jun 1 09:17:21 EDT 2009


Hi all!
I'm trying to receive notifications from a simple MBean component. The MBean (taken from wikis) simply dumps a Message when the operation printMessage is invoked:

public class StartupService extends ServiceMBeanSupport implements StartupServiceMBean
  | {
  |    // Our message attribute
  |    private String message = "Sorry no message today";
  | 
  |    // Getters and Setters
  |    public String getMessage()
  |    {
  |       return message;
  |    }
  |    public void setMessage(String message)
  |    {
  |       this.message = message;
  |    }
  | 
  |    // The printMessage operation
  |    public void printMessage()
  |    {
  |       log.info(message);
  |    }
  | 
  |    // The lifecycle
  |    protected void startService() throws Exception
  |    {
  |       log.info("Starting with message=" + message);
  |    }
  |    protected void stopService() throws Exception
  |    {
  |       log.info("Stopping with message=" + message);
  |    }
  | }
  | 

The notification Listener (also taken from wikis) extends ListenerServiceMBeanSupport 

public class NotificationListener 
  |    extends ListenerServiceMBeanSupport 
  |    implements NotificationListenerMBean 
  | { 
  |    // Constructors -------------------------------------------------- 
  |    /** 
  |     * CTOR 
  |    **/ 
  |    public NotificationListener() 
  |    { 
  |       // empty 
  |    } 
  | 
  |    // NotificationListenerMBean implementation ---------------------- 
  |    // No attributes or operations in this example to implement! 
  | 
  |    // Lifecycle control (ServiceMBeanSupport) ----------------------- 
  |    /** 
  |     * Start 
  |    **/ 
  |    public void startService() 
  |       throws Exception 
  |    { 
  |       // subscribe for notification, true=dynamic 
  |       super.subscribe(true); // listener is me! 
  |    } 
  | 
  |    /** 
  |     * Stop 
  |    **/ 
  |    public void stopService() 
  |       throws Exception 
  |    { 
  |       // unsubscribe for notifications 
  |       super.unsubscribe(); 
  |    } 
  | 
  |    // ListenerServiceMBeanSupport override ------------------------
  |    /** 
  |     * Overriden to add handling! 
  |    **/ 
  |    public void handleNotification2(Notification notification, Object handback) 
  |    { 
  |       log.info("Got notification: " + notification + ", handback: " + handback); 
  |    }
  | 
  |  
  | } 

Then I've tried to adapt the service xml file so that it receives notifications from the domain com.sample.jmx:


 <mbean code="com.sample.jmx.StartupService" name="com.packtpub.jmx:service=StartupClass">
  |     <attribute name="Message">Hello World</attribute>
  |   </mbean>
  | 
  |     <server>
  |     <mbean code="jboss.example.NotificationListener"
  |            name="jboss.example:name=NotificationListener">
  | 
  |       <attribute name="SubscriptionList">      
  |         <subscription-list>
  |           <mbean name="*:service=invoker,*" handback="anObject"></mbean>
  |           <mbean name="com.sample.jmx:*"></mbean>
  |       
  |              <notification type="JBOSS_MONITOR_NOTIFICATION"></notification>
  |           <mbean name="JMImplementation:type=MBeanServerDelegate">
  |             <notification type="JMX.mbean.registered"></notification>
  |           </mbean>
  |         </subscription-list>
  |       </attribute>
  |     </mbean>
  |   </server>

Unfortunately I don't receive any notification when the method printMessage is invoked....have you got any idea what's wrong?
JBoss release used 5.0.0 GA with JDK 1.6
Thanks a lot
John

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4234459#4234459

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4234459



More information about the jboss-user mailing list