Java Dynamic Management Kit 3.2 Programming Guide | ||||
---|---|---|---|---|
![]() | ![]() | Chapter 4. Operations on M-Beans | ![]() | ![]() |
The Java Dynamic Management Kit provides services for getting or setting properties of m-beans through the framework. The prerequisites for using these services are:
The Java Dynamic Management agent must provide a metadata service (see Metadata Service in Chapter 10).
The m-bean must provide getter and setter methods for properties. They must be implemented as described in Properties in Chapter 3.
To use these services, invoke the getValue() or setValue() method of the framework and specify:
The full object name of the m-bean that contains a given property
The name of the property whose value you want to retrieve or set
These methods will raise an exception if the object name is not registered in the repository or if the object does not have a property with the given name.
Example 4-9 shows how to get the value of a specific property for an m-bean identified by its full object name. In this example, the object name is bankHost:account.id=123456,owner=smith and the property to be obtained is balance.
Example 4-9. Getting a Property Within an M-Bean
Object val = cmf.getValue( new ObjectName ("bankHost:account.id=123456,owner=smith"), "balance" ); |
Example 4-10 shows how to set the value of a specific property for an m-bean identified by its full object name. In this example, the object name is also bankHost:account.id=123456,owner=smith, and the property balance is to be set to the value 0.0.
Example 4-10. Setting a Property Within an M-Bean
cmf.setValue( new ObjectName ("bankHost:account.id=123456,owner=smith"), "balance", 0.0, null ); |
You can also use an operator to compute a value that will be used to set the property. An operator implements the com.sun.jaw.reference.agent.services.OperatorSrvIf Java interface. The operator is responsible for setting the property using a default value provided by the caller and any algorithm the operator implements.
In Example 4-11, the object name is again bankHost:account.id=123456,owner=smith, and the property balance is to be set to the value computed by the addInterest.perform( ..., 0.037, ...) method.
Example 4-11. Using an Operator to set a Property
cmf.setValue( new ObjectName ("bankHost:account.id=123456,owner=smith"), "balance", 0.037, "addInterest"); |
![]() | ![]() | ![]() |
Retrieving M-Beans | ![]() | Invoking M-Bean Actions |