JBoss.org Community Documentation
To specify that an MBean service depends on other MBean services you need to declare the dependencies in the mbean element of the service descriptor. This is done using the depends
and depends-list
elements. One difference between the two elements relates to the optional-attribute-name
attribute usage. If you track the ObjectName
s of dependencies using single valued attributes you should use the depends element. If you track the ObjectName
s of dependencies using java.util.List
compatible attributes you would use the depends-list
element. If you only want to specify a dependency and don't care to have the associated service ObjectName
bound to an attribute of your MBean then use whatever element is easiest. The following listing shows example service descriptor fragments that illustrate the usage of the dependency related elements.
<mbean code="org.jboss.mq.server.jmx.Topic" name="jms.topic:service=Topic,name=testTopic"> <!-- Declare a dependency on the "jboss.mq:service=DestinationManager" and bind this name to the DestinationManager attribute --> <depends optional-attribute-name="DestinationManager"> jboss.mq:service=DestinationManager </depends> <!-- Declare a dependency on the "jboss.mq:service=SecurityManager" and bind this name to the SecurityManager attribute --> <depends optional-attribute-name="SecurityManager"> jboss.mq:service=SecurityManager </depends> <!-- ... --> <!-- Declare a dependency on the "jboss.mq:service=CacheManager" without any binding of the name to an attribute--> <depends>jboss.mq:service=CacheManager</depends> </mbean> <mbean code="org.jboss.mq.server.jmx.TopicMgr" name="jboss.mq.destination:service=TopicMgr"> <!-- Declare a dependency on the given topic destination mbeans and bind these names to the Topics attribute --> <depends-list optional-attribute-name="Topics"> <depends-list-element>jms.topic:service=Topic,name=A</depends-list-element> <depends-list-element>jms.topic:service=Topic,name=B</depends-list-element> <depends-list-element>jms.topic:service=Topic,name=C</depends-list-element> </depends-list> </mbean>
Another difference between the depends
and depends-list
elements is that the value of the depends element may be a complete MBean service configuration rather than just the ObjectName
of the service. Example 3.13, “An example of using the depends element to specify the complete configuration of a depended on service.” shows an example from the hsqldb-service.xml
descriptor. In this listing the org.jboss.resource.connectionmanager.RARDeployment
service configuration is defined using a nested mbean
element as the depends
element value. This indicates that the org.jboss.resource.connectionmanager.LocalTxConnectionManager
MBean depends on this service. The jboss.jca:service=LocalTxDS,name=hsqldbDS
ObjectName
will be bound to the ManagedConnectionFactoryName
attribute of the LocalTxConnectionManager
class.
<mbean code="org.jboss.resource.connectionmanager.LocalTxConnectionManager" name="jboss.jca:service=LocalTxCM,name=hsqldbDS"> <depends optional-attribute-name="ManagedConnectionFactoryName"> <!--embedded mbean--> <mbean code="org.jboss.resource.connectionmanager.RARDeployment" name="jboss.jca:service=LocalTxDS,name=hsqldbDS"> <attribute name="JndiName">DefaultDS</attribute> <attribute name="ManagedConnectionFactoryProperties"> <properties> <config-property name="ConnectionURL" type="java.lang.String"> jdbc:hsqldb:hsql://localhost:1476 </config-property> <config-property name="DriverClass" type="java.lang.String"> org.hsqldb.jdbcDriver </config-property> <config-property name="UserName" type="java.lang.String"> sa </config-property> <config-property name="Password" type="java.lang.String"/> </properties> </attribute> <!-- ... --> </mbean> </depends> <!-- ... --> </mbean>
Example 3.13. An example of using the depends element to specify the complete configuration of a depended on service.