Working with MBeans


MBeans are the management interfaces to the services registered with the JBoss microkernel. Every service in JBoss is represented by an MBean, and you have the ability to jump in and interact with those services.

You've been using the JMX Console throughout the book to access MBeans. You've looked at datasource statistics, checked which classloader loaded a specific class, and even shut down the server through the JMX Console, so you should be feeling comfortable with general MBean operation. In this lab we'll look at MBeans through the eyes of the Web Console, which adds a few new twists to what you've seen so far.


Note: Only attributes whose type has a JavaBeans property editor defined can be edited through the Web Console. You can define new property editors using PropertyEditor-ManagerService.

How do I do that?

To get to the MBeans, expand the JMX MBeans node in the System section of the navigation panel. You should find the same MBeans you saw in the JMX Console, but the tree view presentation in the Web Console makes it a bit easier to navigate.

Let's find the jboss.system:type=ServerInfo MBean we used earlier in the book. Find the jboss.system domain and expand it. You should see the MBeans shown in Figure 8-3.

When you select jboss.system:type=ServerInfo, the MBean page from the JMX Console will show up in the details panel. There are two parts to the management interface displayed: attributes and operations.

Developer's Notebook 8-3. The MBeans in the jboss.system domain


Attributes typically represent the state or configuration of a service. Attributes are like fields on an object; they have a name, a type, and a value. They also have an access flag that specifies whether the attribute is readable or writable. Only writable attributes will show up as editable in the Web Console.

The ServerInfo MBean provides information about the state of the server, so all the attributes are read-only. Some of them are static, such as OS name and version. Others, such as the free memory and thread count values, will change regularly. You'll likely see those values change if you refresh the page.


Note: You'll see a nicer way to monitor a changing value shortly.

To see an editable attribute, go back to the navigation panel and find the jboss.system:service=Logging,type=log4j MBean you used in Chapter 6. You can adjust the RefreshPeriod attribute to ask JBoss to check the log4j.xml file for changes more frequently. To change the value, enter the new value in the input box and click Apply Changes. After JBoss changes the configuration of the underlying service, the page will refresh and you will see the new value reflected on the MBean.

MBeans also provide management operations. These are just like methods on a regular Java object. Some operations are intended to send messages to the service. An example of this would be asking a connection pool to flush its pool, or changing the log levels in the log4j service.


Note: If you are running Java 1.5, JBoss will provide a full stack trace for each thread too!

Other operations are purely informational. The ServerInfo MBean provides a listThreadDump operation that shows all the threads in the JVM. To invoke the operation, click the Invoke button next to the operation's name.

     Total Threads: 42     Total Thread Groups: 7             Thread Group: system : max priority:10, demon:false     Thread: Reference Handler : priority:10, demon:true     Thread: Finalizer : priority:8, demon:true     Thread: Signal Dispatcher : priority:10, demon:true     Thread: CompileThread0 : priority:10, demon:true     Thread: RMI TCP Accept-1098 : priority:5, demon:true     Thread: RMI Reaper : priority:5, demon:false     Thread: GC Daemon : priority:2, demon:true     Thread: RMI TCP Accept-4444 : priority:5, demon:true             Thread Group: main : max priority:10, demon:false     Thread: DestroyJavaVM : priority:5, demon:false             Thread Group: jboss : max priority:10, demon:false     Thread: Thread-0 : priority:5, demon:true     Thread: ScannerThread : priority:5, demon:true     Thread: Thread-2 : priority:5, demon:true     Thread: PooledInvokerAcceptor#0-4445 : priority:5, demon:false     Thread: ContainerBackgroundProcessor[StandardEngine[jboss.web]] : priority:5, demon:true     Thread: JBossMQ Cache Reference Softner : priority:5, demon:true     Thread: Thread-3 : priority:5, demon:true     Thread: HSQLDB Timer @4038e2 : priority:5, demon:true     Thread: Thread-5 : priority:5, demon:true     Thread: JCA PoolFiller : priority:5, demon:false     Thread: TimeoutFactory : priority:5, demon:true     Thread: Thread-6 : priority:5, demon:true     Thread: JBossLifeThread : priority:5, demon:false     Thread: http-0.0.0.0-8080 : priority:5, demon:true     Thread: http-0.0.0.0-8080-1 : priority:5, demon:true     Thread: TP-Processor1 : priority:5, demon:true     Thread: TP-Processor2 : priority:5, demon:true     Thread: TP-Processor3 : priority:5, demon:true     Thread: TP-Processor4 : priority:5, demon:true     Thread: TP-Monitor : priority:5, demon:true     Thread: http-0.0.0.0-8080-2 : priority:5, demon:true     Thread: http-0.0.0.0-8080-3 : priority:5, demon:true     Thread: http-0.0.0.0-8080-4 : priority:5, demon:true     Thread: http-0.0.0.0-8080-5 : priority:5, demon:true     Thread: http-0.0.0.0-8080-6 : priority:5, demon:true     Thread: http-0.0.0.0-8080-7 : priority:5, demon:true     Thread: http-0.0.0.0-8080-8 : priority:5, demon:true     Thread: http-0.0.0.0-8080-9 : priority:5, demon:true     Thread: http-0.0.0.0-8080-10 : priority:5, demon:true             Thread Group: JBoss Pooled Threads : max priority:10, demon:false     Thread: ClassLoadingPool(2)-1 : priority:5, demon:true     Thread: WorkManager(3)-1 : priority:5, demon:true             Thread Group: System Threads : max priority:10, demon:false     Thread: JBoss System Threads(1)-1 : priority:5, demon:true             Thread Group: JBossMQ Server Threads : max priority:10, demon:false     Thread: UILServerILService Accept Thread : priority:5, demon:false             Thread Group: RMI Runtime : max priority:10, demon:false 

Another good informational bean is the JNDIView MBean. Find the jboss:service=JNDIView MBean and invoke the list operation. You'll get a complete dump of the JNDI tree for the server, including the enterprise naming contexts for your EJBs. Here's the part of the output for todo.jar:

     Ejb Module: todo.jar             java:comp namespace of the Task bean:     +- env (class: org.jnp.interfaces.NamingContext)             java:comp namespace of the Comment bean:     +- env (class: org.jnp.interfaces.NamingContext)             java:comp namespace of the TaskMaster bean:     +- env (class: org.jnp.interfaces.NamingContext)       |   +- ejb (class: org.jnp.interfaces.NamingContext)       |   |   +- CommentLocal[link -> local/Comment@13898049]       |   |      (class: javax.naming.LinkRef)       |   |   +- TaskLocal[link -> local/Task@10155972]       |   |      (class: javax.naming.LinkRef) 

You can clearly see how the JNDI references were resolved. The JNDIView MBean is very useful when you are trying to find where an object is in the JNDI tree.

What just happened?

You saw how to interact with MBeans in the server through the Web Console. You can view and modify attributes and invoke management operations on any service in JBoss. There is very little you can't do through the MBean management interfaces.



JBoss. A Developer's Notebook
JBoss: A Developers Notebook
ISBN: 0596100078
EAN: 2147483647
Year: 2003
Pages: 106

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net