Using the m-let services involves:
|
|
|
<MLET
|
|
CODE=class | OBJECT=serfile
|
|
ARCHIVE="archivelist"
|
|
[CODEBASE=codebaseURL]
|
|
[NAME=mbeanname]
|
|
[PERSISTENT=true|false]
|
|
[VERSION=version]
|
|
>
|
|
[paramlist]
|
|
</MLET>
|
ARCHIVE attribute. Either CODE or OBJECT must be present.
OBJECT=serfile
ARCHIVE attribute. If the .jar file contains a directory hierarchy, specify the path of the file within this hierarchy. Otherwise a match will not be found. Either CODE or OBJECT must be present.
ARCHIVE="archivelist"
CODE or OBJECT attribute. If archivelist contains more than one file:
CODEBASE=codebaseURL
ARCHIVE attribute. Specify this attribute only if the .jar files are not in the same directory as the m-let text file. If this attribute is not specified, the base URL of the m-let text file is used.
Note - Multiple MLET tags with the same code base URL share the same instance of the MLetClassLoader class.
NAME=mbeanname
VERSION=version
<PARAM NAME=propertyName VALUE=value>
| CODE EXAMPLE 13-1 Example MLET Tag |
Adding the M-Let Service
Before using the m-let service, you must add it to an agent. To add the m-let service, create an instance of one of these classes:
CODE EXAMPLE 13-2 shows how to add the m-let service without version control to an agent. For an example of how to add the m-let service with version control, refer to CODE EXAMPLE 13-8.
|
domain:com.sun.jaw.impl.agent.services.mlet.MletSrvMO.secure=false
|
|
domain:com.sun.jaw.impl.agent.services.mlet.MletSrvMO.secure=true
|
Loading an M-Let Text File
To load an m-let text file, an agent or manager application must invoke a load URL method of an instance of the m-let service. When the m-let text file is loaded, an instance of the m-bean specified in each MLET tag is created. By repeatedly invoking the load URL method, it is possible to populate a Java Dynamic Management agent while it is running. The m-let service provides methods for loading an m-let text file with or without error checking. Loading and Error Checking an M-Let Text File
The m-let service provides different methods for loading a URL, depending on whether the method is to be invoked by an agent or a manager. Each of these methods has a different return value. To load an m-let text file with error checking, invoke one of these methods, depending on the type of application you are writing:
|
Application |
Method |
Returns |
|
Agent |
performLocalLoadURL |
A vector of object references to the m-beans instantiated. |
|
Manager |
performRemoteLoadURL |
A vector of m-let tags that define the m-beans instantiated. |
By parsing the vector returned, it is possible to perform error checking when an m-let text file is loaded.
| CODE EXAMPLE 13-3 Loading an M-Let Text File |
Parsing the Vector Returned in an Agent
When the performLocalLoadURL method is invoked by an agent, it returns a vector containing one entry per MLET tag in the m-let text file loaded. Each entry specifies either the reference of the m-bean instantiated, or a throwable object (that is, an error or an exception) if the m-bean cannot be instantiated. Parsing the vector returned by the performLocalLoadURL method enables you to:
| CODE EXAMPLE 13-4 Parsing the Vector Returned in an Agent |
Parsing the Vector Returned in a Manager
When the performRemoteLoadURL method is invoked by a manager, it returns a vector containing one entry per MLET tag in the m-let text file loaded. Each entry specifies either an m-let tag that defines the m-bean instantiated, or a throwable object (that is, an error or an exception) if the m-bean could not be instantiated. Parsing the vector returned by the performLocalLoadURL method enables you to verify whether each m-bean was instantiated as requested.
| CODE EXAMPLE 13-5 Parsing the Vector Returned in a Manager |
Loading an M-Let Text File Without Performing Error Checks
To load an m-let text file without performing any error checking, invoke the performLoadURL method of the m-let service. This method does not return, so no error checking is possible. It is allowed in the code of an agent or a manager. Therefore, use this method if you want to write code that can be used both for an agent and a manager. An example showing code for loading an m-let text file without performing any error checking is shown in CODE EXAMPLE 13-6.
| CODE EXAMPLE 13-6 Loading an M-Let Text File Without Performing Any Error Checking |
Exception Handling
A load URL method throws an exception if any of the following are true:
|
defaultDomain:JavaClass.codebase=baseURL
|
ServiceName.MLETLOADER.
CODEBASE attribute specified in the MLET tag.
NAME attribute of the MLET tag
NAME attribute of the MLET tag
NAME attribute of the MLET tag if an initCmf method is defined for the m-bean and you want the NAME attribute to be passed as the object name parameter. You can also use the NAME attribute of the MLET tag for an m-bean that does not have an initCmf method if you want the m-bean instance to be registered with the repository by the m-let service.You can omit the
NAME attribute of the MLET tag if an object name is specified in the initCmf method. If an object name is specified in the initCmf method, the m-bean will register with the repository using that object name. You can also omit the NAME attribute of the MLET tag for an m-bean that does not have an initCmf method if you do not want the m-bean instance to register with the repository.
NAME Attribute of the MLET Tag
NAME attribute of the MLET tag to specify the object name of the m-bean instance, the instance is registered with this name. The method invoked to register the instance depends on how the m-bean is implemented:
PERSISTENT attribute in the MLET tag.
NAME Attribute of the MLET Tag
NAME attribute of the MLET tag, the method invoked to register the instance and the supplier of the object name depends on the implementation of the m-bean:
| CODE EXAMPLE 13-7 Instantiating an M-Bean From Another M-Bean |
Instantiating and Running an M-Bean
If you want an m-bean which has been instantiated using the m-let service, to start automatically as soon as it is instantiated, ensure that the m-bean implements the java.lang.Runnable interface. When the m-let service instantiates the m-bean, it creates a new thread and invokes the run method of the m-bean. Caching and Version Control
Applying version control to an m-bean enables the m-let service to reduce network traffic by not loading .jar files from a server unless it is necessary. When you apply version control, .jar files are stored locally in the cache. Unless the m-let text file specifies that new versions must be loaded from the server, .jar files are loaded from the cache. For more information, see "Version Control Mechanism" on page 173. If you do not apply version control to an m-bean, the .jar files are always loaded from the server when an m-let text file is loaded.
Applying Version Control
Applying version control to an m-bean loaded by the m-let service involves:
VERSION attribute of the MLET tag
|
Operating Environment |
Directory |
|
Solaris |
/var/opt/SUNWconn/jaw/mletcache |
|
Windows NT |
C:\Program Files\SUNWconn\jaw\var\mletcache |
To change the default cache directory, invoke the setCacheDirectory method of the m-let service instance. The setCacheDirectory method does not create the directory that you specify, the directory must already exist. CODE EXAMPLE 13-8 shows how to add the m-let service with version control and change the cache directory.
| CODE EXAMPLE 13-8 M-Let Service with Version Control |
|
domain:com.sun.jaw.impl.agent.services.mlet.MLetCacheVersionSrvMO.secure=false
|
|
domain:com.sun.jaw.impl.agent.services.mlet.MLetCacheVersionSrvMO.secure=true
|
Version Control Mechanism
When the m-let text file is loaded, the m-let service compares the version number specified in the MLET tag with the current version number of the m-bean, which is stored locally. If the version number specified in the MLET tag is greater than the current version number, the .jar files are loaded from the server to replace those stored locally in the cache. The current version number is updated to the value specified in the MLET tag. If the version number specified in the MLET tag is less than or equal to the current version number, the .jar files in the cache are used. Implementing Your Own Version Control Mechanism
To implement your own version control mechanism, create a Java class that extends the com.sun.jaw.impl.agent.services.mlet.MLetCacheVersionSrv class. In your Java class, override the check method of the com.sun.jaw.impl.agent.services.mlet.MLetCacheVersionSrv class.
Bootstrap Service
The bootstrap service simplifies the distribution of new releases of an application (namely an agent or a manager) from a central server. It is a standalone Java program that enables you to load an application from a remote .jar file. To obtain a new version of an application, all you have to do is run the bootstrap service on the system that requires the application to be loaded and run. Information on the application is contained in an m-let text file. You specify the URL of the m-let text file when you run the bootstrap service. Use of the MLET Tag in the Bootstrap Service
When you use the MLET tag with the bootstrap service, only a limited set of parameters is permitted, as shown in the following syntax statement:
|
|
|
<MLET
|
|
CODE=applicationClassfile
|
|
ARCHIVE="archivelist"
|
|
[CODEBASE=codebaseURL]
|
|
>
|
|
</MLET>
|
|
|
The attributes are:
CODE=applicationClassfile
ARCHIVE="archivelist"
CODEBASE=codebaseURL
If you are using the bootstrap service to load an agent that uses the supplied base agent, you have to modify the code of the supplied base agent so that it implements the java.lang.Runnable interface. The base agent provided with the Java Dynamic Management Kit does not implement the java.lang.Runnable interface.
Besides implementing the java.lang.Runnable interface, the application needs to set the framework class loader to the class loader that loaded the application.
CODE EXAMPLE 13-9 shows the code required by an agent, if it is to be loaded using the bootstrap service.
| CODE EXAMPLE 13-9 Loading an Agent by Using the Bootstrap Service |
CODE EXAMPLE 13-10 shows the code required by a client, if it is to be loaded using the bootstrap service.
| CODE EXAMPLE 13-10 Loading a Client Using the Bootstrap Service |
Using the Bootstrap Service to Load the Java Dynamic Management Kit
It is possible to load the classes provided in the Java Dynamic Management Kit, contained in a .jar file, at the same time that you load and run an application. To load Java Dynamic Management Kit in this way, specify the .jar file containing Java Dynamic Management Kit as one of the .jar files in the MLET tag.
|
% java com.sun.jaw.impl.agent.services.bootstrap.BootstrapSrv
secure applicURL [local-libdir]
|
Where secure is a flag that specifies whether the service is to be run in secure mode (true) or non-secure mode (false), applicURL specifies the URL location of the m-let text file containing the information for loading the application and local-libdir is an optional parameter that specifies the local directory for storing native libraries before they are loaded into memory.
Using the Library Loading Service
The m-let and bootstrap class loaders implement the LibraryLoaderIf interface to allow the loading of dynamic native libraries. The basic operation of the services is described in "Library Loaders" on page 142.
Default Temporary Library Directory
The m-let and bootstrap class loaders use a temporary directory to store the library files before they are loaded into memory. The default temporary library directory depends on the operating environment.
|
Operating Environment |
Default temporary library directory |
|
Solaris |
/tmp |
|
Windows NT |
C:\Program Files\SUNWconn\jaw\tmp |
Changing the Temporary Library Directory
If you want the m-let and bootstrap class loaders to use a temporary library directory other than the default, you can specify the new directory by invoking the setLibraryDirectory method.
| CODE EXAMPLE 13-11 Using setLibraryDirectory to Change the Temporary Library Directory |
Loading a Library From the Local File System
CODE EXAMPLE 13-12 shows an example hierarchy for the libraries on the agent host.
| CODE EXAMPLE 13-12 Library Hierarchy on the Agent Host |
Local libraries are loaded by invoking the LibLoader.loadLibrary method. The LibLoader.loadLibrary method is invoked by a class that was loaded through the m-let or bootstrap class loaders. The LibLoader.loadLibrary method is described in "Including Native Code in an M-Bean" on page 143. CODE EXAMPLE 13-13 shows two methods of loading the same library.
| CODE EXAMPLE 13-13 Loading a Library From the Local File System |
Loading a Library From a .jar File
CODE EXAMPLE 13-14 shows an example hierarchy for the libraries in a .jar file.
| CODE EXAMPLE 13-14 Library Hierarchy in a .jar File |
Libraries are loaded from .jar files using the LibLoader.loadLibrary method. CODE EXAMPLE 13-15 shows code for loading two instances of the same library using the basename to differentiate between the two. CODE EXAMPLE 13-15 also shows code for loading libraries into two different operating environments.
| CODE EXAMPLE 13-15 Loading a Library From a .jar File |
Security Manager
The security manager supplied with the Java Dynamic Management Kit is programmed to accept incoming libraries. For further information, refer to "Security Manager" on page 145.
When running the m-let and bootstrap services in non-secure mode, you must use the security manager provided with the Java Dynamic Management Kit to be able to load native libraries.
Code Signing
The m-let and bootstrap services support signed .jar files, enabling them to ensure that only classes from a trusted source are downloaded over a network. This involves:
By sharing a single base agent among all the Java Dynamic Management applications that run on a single machine, conflicts over port allocations are avoided. This is because only one process is responsible for port allocations.
Using the launcher service involves:
CODE EXAMPLE 13-16 shows how to add the launcher service to an agent and register it with the repository.
| CODE EXAMPLE 13-16 Adding the Launcher Service |
Adding Code for Starting the Launcher Service
To start the launcher service, an agent must invoke the performLaunch method of an instance of the launcher service, as shown in CODE EXAMPLE 13-17.
| CODE EXAMPLE 13-17 Starting the Launcher Service |
Search Paths for MLET Text Files
Put the m-let text files used by the launcher service in the directory it searches when it is started. The launcher service requests the m-let service to load all the files it finds into the agent. A default search path is preset for the launcher service. If you want the launcher service to search in directories other than the defaults, you can specify the search path explicitly. Default Search Path
The default search path depends on the operating environment:
|
Operating Environment |
Directory |
|
Solaris |
/etc/opt/SUNWconn/jaw/launch |
|
Windows NT |
C:\Program Files\SUNWconn\jaw\etc\launch |
Changing the Search Path
If you want the launcher service to search in directories other than the defaults, you can specify the search path by:
path property in the object name you give to the service
| CODE EXAMPLE 13-18 Using setPath to Change the Launcher Service Search Path |
To specify a path containing several directories, use the path separator for the operating environment in which your agent is running. To obtain the path separator, check the
path.separator property. Loading a Single M-Let Text File
To use the launcher service to load a single m-let text file, use the mletload command. To do this, type the command for your operating environment:
|
prompt% /opt/SUNWconn/bin/mletload mletfileURL
|
|
C:\>"C:\Program Files\SUNWconn\jaw\bin\mletload" mletfileURL
|
|
Application |
Code Base URL |
JAR Files |
|
A.class |
http://www.bar.com/jars/A |
A1.jar, A2.jar |
|
B.class |
http://www.bar.com/jars/B |
B1.jar, B2.jar |
The m-let text files A.txt and B.txt are contained in the /etc/opt/SUNWconn/jaw/launch directory. They define the code to be obtained for each application when the launcher service is started. Their content is shown in CODE EXAMPLE 13-19 and CODE EXAMPLE 13-20.
| CODE EXAMPLE 13-19 Content of the A.txt M-Let Text File |
| CODE EXAMPLE 13-20 Content of the B.txt M-Let Text File |