An object name consists of the following parts:
Search Key
The search key enables unique names to be assigned to instances of the same class. A search key consists of one or more attribute-value pairs. An attribute in a search key does not have to correspond to a property within the m-bean. For example, if you use the attribute serialno in a search key, the m-bean does not have to contain a property named serialno. You can specify any number of attribute-value pairs in a search key. Syntax of an Object Name
The variable parts of this syntax are:
domainPart:classPart[.attribute=value[,attribute=value]*]
For example, an object representing a specific bank account could be named:
Note - If the object name does not contain at least one equals sign (=), the entire string after the colon is considered the class part of the object name. In this case, the class is a singleton.
|
TheBank:account.id=123456,owner=smith
|
Registering an M-Bean
To enable an m-bean to be managed by a Java Dynamic Management agent, register it in the repository. Registering an m-bean does not require modification of code within the m-bean itself. All that is required is to add to the agent or its manager new code for registering the m-bean. The Java Dynamic Management Kit enables you to register an existing m-bean instance and to instantiate and register an m-bean in a single operation. Registering an m-bean causes an object name to be assigned to it.
Registering an Existing M-Bean
To register an m-bean, invoke one of the following methods of the Framework class:
CODE EXAMPLE 4-2 shows how to add persistent information to the repository.
| CODE EXAMPLE 4-2 Registering a Persistent M-Bean |
Instantiating and Registering an M-Bean in a Single Operation
To instantiate and register an m-bean in a single operation, invoke one of the following methods of the Framework class:
The framework uses a class loader (see Chapter 12) to locate the Java class of the m-bean to be instantiated. It then creates an instance of the class. Once the m-bean has been instantiated, it must be registered with the framework. It is possible to register an m-bean by using:
Note - The Java class of the m-bean to be instantiated must contain a public constructor that does not take any arguments. If it does not, an exception is thrown when the newObject or newDBObject is invoked.
The services provided under com.sun.jaw.impl.agent.services contain an implementation of the initCmf method.
Using the Framework
If you do not define an initCmf method in an m-bean, the framework registers the m-bean by invoking one of these methods:
Example
CODE EXAMPLE 4-3 shows how to add an m-bean, in this example the metadata service, to the framework.
| CODE EXAMPLE 4-3 Instantiating an M-Bean |
Assignment of Object Names
Registering an m-bean causes an object name to be assigned to it. To specify the object name explicitly, use the format defined in "Object Name" on page 41. If you do not specify the object name explicitly, the framework assigns a default object name to the m-bean. The format of a default object name is:
|
frameworkDomain:Class
|
The variable parts of this format are:
Note - A default object name does not contain a search key. Therefore, any m-bean assigned a default name by the framework, will be a singleton m-bean.
The repository that provides persistent storage is represented by the com.sun.jaw.impl.agent.services.persistent.PersistentRepSrv Java class.
The com.sun.jaw.impl.agent.services.light.RepositorySrv repository provides both volatile and persistent storage.
| CODE EXAMPLE 4-4 Retrieving a Specific M-Bean |
CODE EXAMPLE 4-5 shows how to retrieve all the m-beans in a given domain with the same class part in their object names.
| CODE EXAMPLE 4-5 Retrieving All M-Beans of the Same Class |
CODE EXAMPLE 4-6 shows how to retrieve all the m-beans in a given domain.
| CODE EXAMPLE 4-6 Retrieving all the M-Beans in a Domain |
CODE EXAMPLE 4-7 shows how to retrieve all the m-beans in all domains.
| CODE EXAMPLE 4-7 Retrieving all M-Beans Registered with an Agent |
Retrieving M-Beans Using Filters
Using filters enables you to retrieve m-beans according to Java properties and their values within m-beans. The repository evaluates filters if it is able to do so. Otherwise, the framework evaluates filters itself. The supplied repository service is able to evaluate filters. To determine whether a repository is able to evaluate filters, the framework invokes the isQuerySrv method defined by the MoRepSrvIf interface.
| CODE EXAMPLE 4-8 Building a Query |
After a filter is built, it can be used for retrieving objects in conjunction with retrieval based on object names.
Getting and Setting Properties
The Java Dynamic Management Kit provides services for getting or setting properties of m-beans. The prerequisites for using these services are:
| CODE EXAMPLE 4-9 Getting a Property Within an M-Bean |
Setting a Property
When setting a property, the value can be set directly by the caller, as illustrated by CODE EXAMPLE 4-10. In this example, the object name is sky:account.name=smith, and the property bank is to be set to the value Acme.
| CODE EXAMPLE 4-10 Setting a Property Within an M-Bean |
Using an Operator to Set a Property
You can also use an operator to set a property. An operator implements the com.sun.jaw.reference.agent.services.OperatorSrvIf Java interface. The operator is responsible for setting the value using a default value provided by the caller and any algorithm the operator implements.
| CODE EXAMPLE 4-11 Using an Operator to set a Property |