Java Dynamic Management Kit 3.2 Programming Guide | ||||
---|---|---|---|---|
![]() | ![]() | Chapter 4. Operations on M-Beans | ![]() | ![]() |
The framework provides services for retrieving registered m-beans from the repository. The getObject(ObjectName, QueryExp) method of the framework enables you to retrieve sets of m-beans by:
Matching the components of their object names
Applying filters to the Java properties they contain
Both matching object names and filtering properties
This method returns a Vector object that contains the full object names and object references of the selected m-beans.
By matching the domain, class name and key components the object name of m-beans, it is possible to retrieve:
A specific m-bean using its full object name and search key
A set of m-beans of the same Java class
A set of m-beans sharing the same domain name
All the m-beans contained in a Java Dynamic Management agent
Example 4-4 shows how to retrieve a specific m-bean using its full object name, including the search key. As the framework relies on the repository for matching, the implementation of the repository determines how the elements of the object name are compared. One limitation of the default repository (com.sun.jaw.impl.agent.services.light.RepositorySrv) used by the framework is that attributes of the search key cannot be matched individually.
In this implementation, the string containing all attribute-value pairs will only match in its entirety. Therefore, to retrieve a specific m-bean, you must specify the full object name, identical to the one used to register the object, including all attributes in the same order. You cannot search for only one attribute-value pair in all registered names with the default implementation. Since the full object name must be unique in the repository, you will always retrieve zero or one m-beans when using a search key.
Example 4-4. Retrieving a Specific M-Bean
Vector SmithsAccount = cmf.getObject( new ObjectName ("bankHost:account.id=123456,owner=smith"), null ); |
Example 4-5 shows how to retrieve all the m-beans in a given domain which are instances of the same Java class. The example also shows how to retrieve all m-beans of the same class, regardless of the domain. This can be useful if you have defined more than one domain name in your agent's repository.
Example 4-5. Retrieving All M-Beans of the Same Class
// for m-beans in the same domain Vector listOfAccounts1 = cmf.getObject( new ObjectName ("bankHost:account"), null ); // for m-beans across all domains Vector listOfAccounts2 = cmf.getObject( new ObjectName (":account"), null ); // Note: if "bankHost" is the only domain, the // resulting vectors will be identical |
Example 4-6 shows how to retrieve all the m-beans in a given domain.
Example 4-6. Retrieving all the M-Beans in a Domain
Vector listOfMOs = cmf.getObject( new ObjectName ("bankHost:"), null ); |
Example 4-7 shows how to retrieve all the m-beans in all domains.
Example 4-7. Retrieving all M-Beans Registered with an Agent
Vector listOfMOs = cmf.getObject( null, null ); // or Vector listOfMOs = cmf.getObject( new Objectname(":"), null ); |
Using filters enables you to retrieve m-beans according to the current value of their properties. Filters are based on m-bean properties, not the attributes in the search key of their registered object name. The repository evaluates query expressions and returns a filtered list of objects if it is able to do so. Otherwise, the framework relies on the filtering service to filter the list of objects found in the repository.
To determine whether a repository is able to apply filters, the framework invokes the isQuerySrv() method defined by the MoRepSrvIf interface. The supplied repository services are not able to evaluate filters, which is why a default framework must have a registered filtering service.
The filter expressed in Example 4-8 retrieves all the m-beans for which the property age is greater than 5 and the property name starts with G and ends with ling.
After a query expression is built, it is used to filter objects as they are retrieved by the repository. The list of objects returned will satisfy both the object name criteria and the query expression.
// build the query expression using the static methods // of the com.sun.jaw.reference.query.Query class // QueryExp exp = Query.and( Query.gt(Query.attr("age"), Query.value(5)), Query.match(Query.attr("name"), Query.value("G*ling"))) // now get the objects satisfying this query from the framework // // 1. among all domains and classes: Vector queryResult1 = cmf.getObject( null, exp ); // 2. from a specific domain Vector queryResult2 = cmf.getObject( new ObjectName ("bankHost:"), exp ); |
![]() | ![]() | ![]() |
Framework Events | ![]() | Getting and Setting Properties |