3 Replies Latest reply on Mar 7, 2013 2:52 PM by jaysensharma

    Problem deploying MBean

    niteshmehta

      Hi,

       

      I have created a MBean and have deployed in Jboss 7.1.1 final.

      The problem I am facing is, when I try to invoke methods of MBean, for some of methods is says NoSuchMethodException when I see it in JConsole, some of the methods have been converted into attributed.

      Am I doing something wrong here?

       

      //MBean
      package com.testmbean;
      
      
      public interface TestServiceMBean {
      
      
                public String getServiceId();
                public Long currentTime();
                public void setId(String id);
                public void logMsg(String message);
      }
      
      //Impl
      package com.testmbean;
      
      
      public class TestService implements TestServiceMBean {
      
      
                public TestService() {}
          public void start() throws Exception
          {
          
          }
      
      
         public void stop() throws Exception
          {
                   
          }
      @Override
      public String getServiceId() {
                return "MY_SERVICE_ID";
      }
      @Override
      public Long currentTime() {
                return System.currentTimeMillis();
      }
      @Override
      public void setId(String id) {
                System.out.println( id);
        
      }
      @Override
      public void logMsg(String message) {
                System.out.println(message);
        
      }
      
      
      }
      

       

      jboss-service.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <server xmlns="urn:jboss:service:7.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="urn:jboss:service:7.0 jboss-service_7_0.xsd">
      
      
          <mbean code="com.testmbean.TestService" name="service.server.testmbean:service=TestService">
          </mbean>
      
      
      </server>
      

       

      JConsole View

      mbeanError.png

        • 1. Re: Problem deploying MBean
          jaysensharma

          Hi,

           

               If you will provide a Setter method like "setId"   then "Id" will be treated as an Attribute of your MBean.

           

              Same way is you provide a Getter like "getServiceId"  then   "ServiceId" will be considered as an Attribute to your MBean.       So  if you just want to provide methods (operations)  inside your MBean then do not prefix any method with "set" or "get"  keywords.

           

           

          Thanks

          Jay SenSharma

          • 2. Re: Problem deploying MBean
            niteshmehta

            Thanks for reply, but I think It was working with jboss 5.x. and is it as per specifications?

            • 3. Re: Problem deploying MBean
              jaysensharma

              http://docs.oracle.com/javase/7/docs/technotes/guides/jmx/JMX_1_4_specification.pdf

              2.1 Definition   

              (Page-39)

               

              The Java class of a standard MBean exposes the resource to be managed directly

              through its attributes and operations. Attributes are internal entities that are exposed

              through getter and setter methods. Operations are the other methods of the class

              that are available to managers. All these methods are defined statically in the MBean

              interface and are visible to an agent through introspection. This is the most

              straightforward way of making a new resource manageable.