org.apache.commons.modeler

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache commons modeler 2.0.1 src » org.apache.commons.modeler 
org.apache.commons.modeler
Package Documentation for COMMONS-MODELER

The Modeler component of the Jakarta Commons subproject offers convenient support for configuring and instantiating Model MBeans (management beans), as described in the JMX Specification. It is typically used within a server-based application that wants to expose management features via JMX. See the JMX Specification (Version 1.1) for more information about Model MBeans and other JMX concepts.

Model MBeans are very powerful - and the JMX specification includes a mechanism to use a standard JMX-provided base class to satisfy many of the requirements, without having to create custom Model MBean implementation classes yourself. However, one of the requirements in creating such a Model MBean is to create the corresponding metadata information (i.e. an implementation of the javax.management.modelmbean.ModelMBeanInfo interface and its corresponding subordinate interfaces). Creating this information can be tedious and error prone. The Modeler package makes the process much simpler, because the required information is constructed dynamically from an easy-to-understand XML description of the metadata. Once you have the metadata defined, and registered at runtime in the provided Registry, Modeler also supports convenient factory methods to instantiate new Model MBean instances for you.

The steps required to use Modeler in your server-based application are described in detail below. You can find some simple usage code in the unit tests that come with Modeler (in the src/test subdirectory of the source distribution), and much more complex usage code in Tomcat 4.1 (in the org.apache.catalina.mbeans package).

. More advanced uses can be found in Tomcat 5 and jakarta-tomcat-connectors.

1. Acquire a JMX Implementation

Modeler has been tested with different JMX implementations:

After unpacking the release, you will need to ensure that the appropriate JAR file (jmxri.jar or mx4j.jar) is included on your compilation classpath, and in the classpath of your server application when it is executed.

2. Create a Modeler Configuration File

Modeler requires that you construct a configuration file that describes the metadata ultimately need to construct the javax.management.modelmbean.ModelMBeanInfo structure that is required by JMX. Your XML file must conform to the mbeans-descriptors.dtd DTD that defines the acceptable structure.

Fundamentally, you will be constructing an <mbean> element for each type of Model MBean that a registry will know how to create. Nested within this element will be other elements describing the constructors, attributes, operations, and notifications associated with this MBean. See the comments in the DTD for detailed information about the valid attributes and their meanings.

A simple example configuration file might include the following components (abstracted from the real definitions found in Tomcat 4.1's use of Modeler):


  <?xml version="1.0"?>
  <!DOCTYPE mbeans-descriptors PUBLIC
   "-//Apache Software Foundation//DTD Model MBeans Configuration File"
   "http://jakarta.apache.org/commons/dtds/mbeans-descriptors.dtd">

  <mbeans-descriptors>

    <!-- ... other MBean definitions ... -->

    <mbean         name="Group"
              className="org.apache.catalina.mbeans.GroupMBean"
            description="Group from a user database"
                 domain="Users"
                  group="Group"
                   type="org.apache.catalina.Group">

      <attribute   name="description"
            description="Description of this group"
                   type="java.lang.String"/>

      <attribute   name="groupname"
            description="Group name of this group"
                   type="java.lang.String"/>

      <attribute   name="roles"
            description="MBean Names of roles for this group"
                   type="java.lang.String[]"
              writeable="false"/>

      <attribute   name="users"
            description="MBean Names of user members of this group"
                   type="java.lang.String[]"
              writeable="false"/>

      <operation   name="addRole"
            description="Add a new authorized role for this group"
                 impact="ACTION"
             returnType="void">
        <parameter name="role"
            description="Role to be added"
                   type="java.lang.String"/>
      </operation>

      <operation   name="removeRole"
            description="Remove an old authorized role for this group"
                 impact="ACTION"
             returnType="void">
        <parameter name="role"
            description="Role to be removed"
                   type="java.lang.String"/>
      </operation>

      <operation   name="removeRoles"
            description="Remove all authorized roles for this group"
                 impact="ACTION"
             returnType="void">
      </operation>

    </mbean>

    <!-- ... other MBean definitions ... -->

  </mbeans-descriptors>

This MBean represents an instance of org.apache.catalina.Group, which is an entity representing a group of users (with a shared set of security roles that all users in the group inherit) in a user database. This MBean advertises support for four attributes (description, groupname, roles, and users) that roughly correspond to JavaBean properties. By default, attributes are assumed to have read/write access. For this particular MBean, the roles and users attributes are read-only (writeable="false"). Finally, this MBean supports three operations (addRole, removeRole, and removeRoles) that roughly correspond to JavaBean methods on the underlying component.

In general, Modeler provides a standard ModelMBean implementation that simply passes on JMX calls on attributes and operations directly through to the managed component that the ModelMBean is associated with. For special case requirements, you can define a subclass of BaseModelMBean that provides override methods for one or more of these attributes (i.e. the property getter and/or setter methods) and operations (i.e. direct method calls).

For this particular MBean, a custom BaseModelMBean implementation subclass is described (org.apache.catalina.mbeans.GroupMBean) is configured. It was necessary in this particular case because several of the underlying Catalina component's methods deal with internal objects or arrays of objects, rather than just the Strings and primitives that are supported by all JMX clients. Thus, the following method on the Group interface:

    public void addRole(Role role);

is represented, in the MBean, by an addRole method that takes a String argument representing the role name of the required role. The MBean's implementation class acts as an adapter, and looks up the required Role object (by name) before calling the addRole method on the underlying Group instance within the Server.

3. Create Modeler Registry at Startup Time

The metadata information, and the corresponding Model MBean factory, is represented at runtime in an instance of Registry whose contents are initialized from the configuration file prepared as was described above. Typically, such a file will be included in the JAR file containing the MBean implementation classes themselves, and loaded as follows:

    URL url= this.getClass().getResource
      ("/com/mycompany/mypackage/mbeans-descriptors.xml");
    Registry registry = Registry.getRegistry();
    registry.loadMetadata(url);

Besides using the configuration file, it is possible to configure the registry metadata by hand, using the addManagedBean() and removeManagedBean() methods. However, most users will find the standard support for loading a configuration file to be convenient and sufficient.

Modeler will also look for a mbeans-descriptors.xml in the same package with the class beeing registered and in its parent. If no metadata is found, modeler will use a number of simple patterns, similar with the ones used by ant, to determine a reasonable metadata

In a future version we should also support xdoclet-based generation of the descriptors

4. Instantiate Model MBeans As Needed

When your server application needs to instantiate a new MBean and register it with the corresponding MBeanServer, it can execute code like this:

  Group group = ... managed component instance ...;

  MBeanServer mserver = registry.getMBeanServer();

  String oname="myDomain:type=Group,name=myGroup";

  registry.registerComponent( group, oname, "Group" );

After the Model MBean has been created and registered, it is accessible to JMX clients through the standard JMX client APIs.

Java Source File NameTypeComment
AttributeInfo.javaClass

Internal configuration information for an Attribute descriptor.


author:
   Craig R.
BaseAttributeFilter.javaClass

Implementation of NotificationFilter for attribute change notifications.

BaseModelMBean.javaClass

Basic implementation of the ModelMBean interface, which supports the minimal requirements of the interface contract.

This can be used directly to wrap an existing java bean, or inside an mlet or anywhere an MBean would be used.

BaseNotification.javaClass Base JMX Notification.
BaseNotificationBroadcaster.javaClass

Implementation of NotificationBroadcaster for attribute change notifications.

ConstructorInfo.javaClass

Internal configuration information for a Constructor descriptor.


author:
   Craig R.
FeatureInfo.javaClass

Convenience base class for AttributeInfo, ConstructorInfo, and OperationInfo classes that will be used to collect configuration information for the ModelMBean beans exposed for management.


author:
   Craig R.
FieldInfo.javaClass

Simple JavaBean representing the contents of a <field> element in an MBeans descriptor file.

FixedNotificationFilter.javaClass Special NotificationFilter that allows modeler to optimize its notifications. This class is immutable - after you construct it it'll filter based on a fixed set of notification names. The JMX specification requires the filters to be called before the notifications are sent.
JndiJmx.javaClass Link between JNDI and JMX.
Main.javaClass Small main that loads mbeans.
ManagedBean.javaClass

Internal configuration information for a managed bean (MBean) descriptor.


author:
   Craig R.
NotificationInfo.javaClass

Internal configuration information for a Notification descriptor.


author:
   Craig R.
OperationInfo.javaClass

Internal configuration information for an Operation descriptor.


author:
   Craig R.
ParameterInfo.javaClass

Internal configuration information for a Parameter descriptor.


author:
   Craig R.
Registry.javaClass Registry for modeler MBeans.
RegistryMBean.javaInterface Interface for modeler MBeans. This is the main entry point into modeler.
RegistryTestCase.javaClass

Test Case for the Registry class.


author:
   Craig R.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.