Sun GlassFish Enterprise Server v2.1.1 Developer's Guide

The MBean Life Cycle

The MBean life cycle proceeds as follows:

  1. The MBean's class files are installed in the Enterprise Server. See MBean Class Loading.

  2. The MBean is deployed using the asadmin create-mbean command or the Admin Console. See Creating, Deleting, and Listing MBeans.

  3. The MBean class is loaded. This also results in loading of other classes. The delegation model is used. See the class loader diagram in The Class Loader Hierarchy.

  4. The MBean is instantiated. Its default constructor is invoked reflectively. This is why the MBean class must have a default constructor.

  5. The MBean's ObjectName is determined according to the following algorithm.

    • If you specify the ObjectName, it is used as is. The domain must be user:. The property name server is reserved and cannot be used.

      The Enterprise Server automatically appends server=target to the ObjectName when the MBean is registered, where the target is the name of the server instance or cluster to which the MBean is deployed.

    • If the MBean implements the MBeanRegistration interface, it must provide an ObjectName in its preregister() method that follows the same rules.

    • If the ObjectName is not specified directly or through the MBeanRegistration interface, the default is user:type=impl-class-name.

  6. All attributes are set using setAttribute calls in the order in which the attributes are specified. Attempting to specify a read-only attribute results in an error.

    If attribute values are set during MBean deployment, these values are passed in as String objects. Therefore, attribute types must be Java classes having constructors that accept String objects. If you specify an attribute that does not have such a constructor, an error is reported.

    Attribute values specified during MBean deployment are persisted to the Enterprise Server configuration. Changes to attributes after registration through a JMX connector such as JConsole do not affect the Enterprise Server configuration. To change an attribute value in the Enterprise Server configuration, use the asadmin set command. See Handling MBean Attributes.

  7. If the MBean is enabled, the MBeanServer.registerMBean(Object, ObjectName) method is used to register the MBean in the MBeanServer. This is the only method called by the Enterprise Server runtime. See The MBeanServer in the Enterprise Server.

    MBeans are enabled by default. Disabling an MBean deregisters it. See Enabling and Disabling MBeans.

  8. The MBean is automatically loaded, instantiated, and registered upon each server restart.

  9. When the MBean is deleted using the asadmin delete-mbean command or the Admin Console, the MBean is first deregistered if it is enabled, then the MBean definition is deleted from the configuration. The class files are not deleted, however.