Converting an mbean service (-service.xml) to a MC Bean (-beans.xml)
TODO: cover all -service.xml elements
Basic conversion rules:
The mbean element translates to bean element
The code attribute translates to a class attribute
The name attribute remains, but its just a string name in the MC. You can use a string that looks like a JMX name, but its still just a string.
The depends element remains, but the name is the bean name, not a JMX name. You can depend on a legacy JMX mbean by using its JMX name however.
The depends element with the optional-attribute-name attribute needs to be replaced with a property element that injects the dependent bean or one of its properties.
The attribute element translates to a property element.
The name of the attribute changes slightly to be consistent with java bean naming conventions. An attribute named "Attr1" becomes a property named "attr1".
Here is a basic example:
<server> <!-- Load all jars from the JBOSS_DIST/server/<config>/lib directory. This can be restricted to specific jars by specifying them in the archives attribute. --> <classpath codebase="${jboss.server.lib.url:lib}" archives="*"></classpath> <mbean code="org.jboss.deployment.scanner.URLDeploymentScanner" name="jboss.deployment:type=DeploymentScanner,flavor=URL"> <depends optional-attribute-name="Deployer">jboss.system:service=MainDeployer</depends> <attribute name="URLComparator">org.jboss.deployment.DeploymentSorter</attribute> <attribute name="FilterInstance" attributeClass="org.jboss.deployment.scanner.DeploymentFilter" serialDataType="javaBean"> <!-- Files starting with theses strings are ignored --> <property name="prefixes">#,%,\,,.,_$</property> <!-- Files ending with theses strings are ignored --> <property name="suffixes">#,$,%,~,\,v,.BAK,.bak,.old,.orig,.tmp,.rej,.sh</property> <property name="matches">.make.state,.nse_depinfo,CVS,CVS.admin,RCS,RCSLOG,SCCS,TAGS,core,tags</property> </attribute> <!-- Frequency in milliseconds to rescan the URLs for changes --> <attribute name="ScanPeriod">5000</attribute> <attribute name="ScanEnabled">true</attribute> <attribute name="URLs"> deploy/ </attribute> <attribute name="RecursiveSearch">True</attribute> </mbean> </server>
converts to the following.
<deployment xmlns="urn:jboss:bean-deployer:2.0"> <!-- All beans use the bootstrap classloader --> <classloader><inject bean="BootstrapClassLoader"></inject></classloader> <bean name="BootstrapClassLoader" class="org.jboss.system.NoAnnotationURLClassLoader"> <classloader><null></null></classloader> <constructor factoryClass="org.jboss.system.NoAnnotationURLClassLoader" factoryMethod="createClassLoader"> <parameter> <array elementClass="java.net.URL"> <!-- VFS --> <value>${jboss.server.lib.url:lib}/*</value> </array> </parameter> </constructor> </bean> <bean class="org.jboss.deployment.scanner.URLDeploymentScanner" name="DeploymentScanner,flavor=URL"> <!-- The mbean Deployer property would have to be converted to the MainDeployer interface, or one would have to inject a property from the MainDeployer. --> <property name="deployer"><inject bean="jboss.system:service=MainDeployer ></inject></property> <property name="URLComparator">org.jboss.deployment.DeploymentSorter</attribute> <property name="filterInstance"><inject bean="DefaultFilter" ></inject></property> <property name="scanPeriod">5000</property> <property name="scanEnabled">true</property> <property name="URLs"> deploy/ </property> <property name="recursiveSearch">True</property> </bean> <bean name="DefaultFilter" class="org.jboss.deployment.scanner.DeploymentFilter"> <!-- Files starting with theses strings are ignored --> <property name="prefixes">#,%,\,,.,_$</property> <!-- Files ending with theses strings are ignored --> <property name="suffixes">#,$,%,~,\,v,.BAK,.bak,.old,.orig,.tmp,.rej,.sh</property> <property name="matches">.make.state,.nse_depinfo,CVS,CVS.admin,RCS,RCSLOG,SCCS,TAGS,core,tags</property> </bean> </beans>
Note that MCBeans can also be exposed with an MBean facade so that they remain available via JMX for other services. To enable this, you use the @JMX annotation:
jboss.deployment:type=DeploymentScanner,flavor=URL
<bean class="org.jboss.deployment.scanner.URLDeploymentScanner"
name="DeploymentScanner,flavor=URL">
<!-- Expose an MBean facade for the URLDeploymentScanner MCBean under the original
MBean ObjectName
-->
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.deployment:type=DeploymentScanner,flavor=URL")</annotation>
<!-- The mbean Deployer property would have to be converted to the
MainDeployer interface, or one would have to inject a property from
the MainDeployer.
-->
<property name="deployer"><inject bean="jboss.system:service=MainDeployer ></inject></property>
<property name="URLComparator">org.jboss.deployment.DeploymentSorter</attribute>
<property name="filterInstance"><inject bean="DefaultFilter" ></inject></property>
<property name="scanPeriod">5000</property>
<property name="scanEnabled">true</property>
<property name="URLs">
deploy/
</property>
<property name="recursiveSearch">True</property>
</bean>
Referenced by:
Comments