Apache commons modeler 2.0.1 src

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 
Modeler
License:Apache License
URL:http://commons.apache.org/modeler/
Description:Mechanisms to create Model MBeans compatible with JMX specification.
Package NameComment
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.

org.apache.commons.modeler.ant Package Documentation for org.apache.commons.modeler.ant Package Ant Tasks for Commons Modeler Integration.

The commons-modeler package includes a set of custom tasks for the Ant build tool, which lets you use Ant to automate the loading of MBean descriptor information, dynamic creation of JMX MBeans, and calling operations and attribute setters on those MBeans. If your application can assemble itself based JMX Mbean operations, this means that you can now use Ant scripts to manage the lifecycle of your application's components, without having to write Java code for this purpose.

To use these tasks, you must copy commons-modeler.jar into the lib subdirectory of your Ant installation, or make sure that it is on the CLASSPATH being used to execute Ant.


mbean / MLET


jmx-attribute

Description

Locates the JMX MBean identified by the objectName attribute, and calls its setAttribute() operation, passing in the attribute name specified by attribute and the value specified by value, after converting the value to the type specified by type.

Parameters

Attribute Description Required
attribute

Name of the attribute for which the setAttribute() method will be called.

Yes
objectName The JMX ObjectName that identifies the MBean whose setAttribute() method will be called. Yes
type

The data type of the attribute value to be set. If not specified, will be assumed to be a String. Otherwise, must be one of ObjectName, boolean, or int.

No
value

String representation of the value to which this attribute will be set. Either value or valueRef must be specified.

No
valueRef

Indirect pointer to a project reference containing the value to which this attribute will be set. Either value or valueRef must be specified.

No

jmx-operation


mbeans-descriptors


org.apache.commons.modeler.demo
org.apache.commons.modeler.mbeans
org.apache.commons.modeler.modules org.apache.commons.modeler.modules

Implementation classes - should not be used directly. The API is not stable but eventually the code will be refactored as a collection of mbeans that will be useable ( more or less ) indepedently.

The MbeanDescriptors* classes are used to extract metadata from different sources. They are result of few stages of refactoring - now they look very similar with ant tasks and are close to normal mbeans, with an execute() method. DOM, SER, Introspection and Dynamic mbean will load metadata from the corresponding sources.

MbeansSource will load an extended MLET file, similar with jboss. It is not completely implemented - only modeler mbeans and dynamic mbeans are loaded. The important characteristic is that all declared mbeans will be registered in the mbean server as model mbeans. For regular java classes, the description will be used to construct the model mbean. DynamicMbeans metadata will be converted to model mbean and the model mbean wrapper will be loaded.

The goal of MbeansSource is to implement a simple persistence mechanism. Since all components are model mbeans, we can detect all changes. The source will be loaded as DOM and modifications will be made to the tree. The save() method will save the DOM tree - preserving all comments and having only the changes that are needed.

There are few remaining issues. First, we need to use the persistence metadata to avoid saving transient fields ( we save an attribute when we detect a change - but we don't know if this attribute should be saved ). The solution is to use the persistence fields in the spec - with some reasonable defaults or patterns for introspection or backward compat.

Another problem is implementing adding and removing components. In catalina, a factory is used to create the components, and save will operate on all mbeans. For creation we need to also use a factory - using the "Type" as a parameter. This will also work very well with Ant1.6 where we can use the component factory to do a "natural" mapping ( i.e. mbeans can be treated as tasks, with attributes as task attributes ). The second part can be solve by either using a parameter on the factory method ( saveTo ? ), or by having a single mbeans source per domain.

org.apache.commons.modeler.util
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.