Java Dynamic Management Kit 3.2 Programming Guide
[ Previous ][ Fast Back ]Chapter 4. Operations on M-Beans[ Fast Forward ][ Next ]

Getting and Setting Properties

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:

To use these services, invoke the getValue() or setValue() method of the framework and specify:

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.

Getting a Property

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" );

Setting a Property

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 );

Using an Operator to Set a Property

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");


[ Previous ][ Home ][ Next ]
Retrieving M-Beans[ Up ]Invoking M-Bean Actions