Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Tomcat Wiki" for change 
notification.

The "HowTo" page has been changed by KonstantinKolinko:
http://wiki.apache.org/tomcat/HowTo?action=diff&rev1=132&rev2=133

Comment:
Correct markup

  
  First of all, you can read [[http://oss.wxnet.org/mbeans.html|this great 
tutorial]] from Christopher Blunck ( ch...@wxnet.org ). I will just add my 
comments and improvements.
  
- 1. Start your Tomcat and check that you have access to 
http://localhost:8080/manager/jmxproxy/. It means that JMX is enabled on your 
Tomcat configuration (if not, check if the following line is in your 
/conf/server.xml file :   ''<Listener 
className="org.apache.catalina.mbeans.ServerLifecycleListener" />''. Otherwise, 
check the Tomcat documentation to activate it). Let this page opened to check 
further if your custom Mbean is detected by Tomcat.<<BR>>
+ 1. Start your Tomcat and check that you have access to 
http://localhost:8080/manager/jmxproxy/. It means that JMX is enabled on your 
Tomcat configuration (if not, check if the following line is in your 
/conf/server.xml file :   `<Listener 
className="org.apache.catalina.mbeans.ServerLifecycleListener" />`. Otherwise, 
check the Tomcat documentation to activate it). Let this page opened to check 
further if your custom Mbean is detected by Tomcat.<<BR>>
  
  2. Build your custom MBean by following the Christopher Blunck's example : 
<<BR>> '''ServerMBean.java''' :
  
@@ -984, +984 @@

          return mbserver;
      }
  }}}
- Here is a capture of the println() : 
https://picasaweb.google.com/lh/photo/jzVX9-NBGwF57A0m8qqv2Q?feat=directlink. 
Tomcat seems to register 2 Mbean server but when I try to fetch mine from its 
AgentId (here "myMBServer"), nothing is found. In my opinion, Tomcat might 
re-implement the ''MBeanServerFactory'' java class to control the server 
creation. Then, it doesn't keep a reference to the newly created MBean server. 
Moreover, if Tomcat re-implement the MBeanFactory class, there is no method to 
directly add MBean (see the 
http://tomcat.apache.org/tomcat-6.0-doc/api/index.html).<<BR>>
+ Here is a capture of the println() : 
https://picasaweb.google.com/lh/photo/jzVX9-NBGwF57A0m8qqv2Q?feat=directlink. 
Tomcat seems to register 2nd Mbean server but when I try to fetch mine from its 
!AgentId (here "myMBServer"), nothing is found. In my opinion, Tomcat might 
re-implement the ''MBeanServerFactory'' java class to control the server 
creation. Then, it doesn't keep a reference to the newly created MBean server. 
Moreover, if Tomcat re-implement the MBeanFactory class, there is no method to 
directly add MBean (see the 
[[http://tomcat.apache.org/tomcat-6.0-doc/api/index.html]]).<<BR>>
  
  In my application architecture, I placed the 2 MBeans files (the interface 
and its implementation) in a particular package (I don't think its compulsary 
but definitely more aesthetic). Compile those one in a jar archive and place it 
in the Tomcat's library folder (/lib).<<BR>>
  
- 3. Build your '''ContextListener''' : According to the 
[[[[http://tomcat.apache.org/tomcat-6.0-doc/config/listeners.html|Tomcat's 
documentation]], a Listener is a ''a component that performs actions when 
specific events occur, usually Tomcat '''starting''' or Tomcat stopping.''. We 
need to instantiate and load our MBean at Tomcat's start. So we build a 
ContextListener.java file which is placed wherever you want in your project 
architecture :
+ 3. Build your '''!ContextListener''' : According to the 
[[http://tomcat.apache.org/tomcat-6.0-doc/config/listeners.html|Tomcat's 
documentation]], a Listener is a ''a component that performs actions when 
specific events occur, usually Tomcat '''starting''' or Tomcat stopping.''. We 
need to instantiate and load our MBean at Tomcat's start. So we build a 
!ContextListener.java file which is placed wherever you want in your project 
architecture :
  
  {{{
  package '''org.bonitasoft.context''';
@@ -1033, +1033 @@

    </listener>
  </web-app>
  }}}
- In his tutorial, Christopher Blunck suggests to compile the 
ContextListener.java file in a jar archive and then place it into our 
WEB-INF/lib folder. In my own experiments, I never found any difference without 
doing this.<<BR>>
+ In his tutorial, Christopher Blunck suggests to compile the 
!ContextListener.java file in a jar archive and then place it into our 
WEB-INF/lib folder. In my own experiments, I never found any difference without 
doing this.<<BR>>
  
  4. The '''''mbeans-descriptor.xml''''' file : The only entry in the Tomcat 
documentation about custom MBean is about this file. It says "''You may also 
add MBean descriptions for custom components in a mbeans-descriptor.xml file, 
located in the same package as the class files it describes.''". Unfortunately, 
instead of reading this file, Tomcat applied its own templates to replace my 
MBeans attributes and operations descriptions... I really didn't figure out 
what is the correct way of using and placing this file. So I don't use it.
  
  5. The configuration should be over. You should have done those operations :
  
-  a. Build your MBean,<<BR>> b. Compile it and place the .jar archive in the 
Tomcat's /lib folder,<<BR>> c. Build your ContextListener.java,<<BR>> d. Add a 
reference to your ContextListener inside your WEB-INF/web.xml file,<<BR>>
+  a. Build your MBean,<<BR>> b. Compile it and place the .jar archive in the 
Tomcat's /lib folder,<<BR>> c. Build your !ContextListener.java,<<BR>> d. Add a 
reference to your !ContextListener inside your WEB-INF/web.xml file,<<BR>>
  
  You can try to run your project. Open the 
http://localhost:8080/manager/jmxproxy page and find your custom MBean (with a 
simple ctrl+f). You can see its domain, name, type and its attributes and 
methods.<<BR>>You can now use this MBean in your application by getting a 
reference to the Tomcat's MBean server :
  
@@ -1047, +1047 @@

  MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
  //call operations with invoke(...) and attributes with getAttributes(...)
  }}}
+ 
- Do not hesitate to check the ManagementFactory class javadoc.
+ Do not hesitate to check the !ManagementFactory class javadoc.
  
  ----
  [[CategoryFAQ]]

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to