The Solaris Bandwidth Manager plug-ins allow the policy agent to obtain m-beans from a remote .jar file. Using the Java APIs in this way means that your applications are fully integrated into the policy agent and modify the way it works. This section contains an overview of the way in which the policy agent acts when m-beans are started and stopped, as well as a summary of the tasks that the developer must carry out to ensure that new m-beans operate correctly with the policy agent.
The example code in this section is contained in the /opt/SUNWconn/ba/html/examples directory.
The Solaris Bandwidth Manager policy agent carries out a number of tasks automatically. They are described below.
When intializing and starting an m-bean, the policy agent:
Loads the m-let text files contained in the /opt/SUNWconn/ba/html/beans/*.html directory.
Initializes the m-beans
The policy agent does so by loading the BeanName.zip and BeanName.class files and calling the initCmf() method. This:
Loads and starts the Solaris Bandwidth Manager configuration
Starts the m-beans
This is done using the performStart() method, which is defined in the com.sun.jaw.reference.agent.services.ActivatableIf interface and is part of the Java Dynamic Management Kit.
To stop an m-bean, the policy agent:
Calls the performStop() method, which is defined in the com.sun.jaw.reference.agent.services.ActivatableIf interface and is part of the Java Dynamic Management Kit.
Stops the Solaris Bandwidth Manager configuration.
Calls the deleteCmf() method to delete m-bean instances.
When writing an m-bean, you must:
Create an m-let text file.
The information on each m-bean is specified in a single instance of a tag, called the MLET tag. When an m-let text file is loaded, an instance of each m-bean specified in the file is created. For example, the m-let text file for the QDatabaseAccounting m-bean is contained in the file QDatabaseAccounting.html and looks like this:
<MLET CODE=com.sun.ba.beans.QDatabaseAccounting ARCHIVE="qdatabaseaccounting.jar, dbaccess.jar > <PARAM NAME=jdbcDriverName VALUE=com.sun.jdbc.SimpleText.SimpleTextDriver> <PARAM NAME=jdbcURLName VALUE=jdbc:SimpleText:/var/opt/SUNWconn/ba> </MLET>The attributes used in this example are:
The full Java class name of the m-bean
The files containing m-beans and other resources used by the QDataBaseAccounting m-bean. In this case the file qdatabaseaccounting.jar contains the required classes and dbaccess.jar contains the database driver.
A list of the parameters required by the QDataBaseAccounting m-bean. These will be passed as a modification list to the initCmf() method.
Implement the initCmf() method. The prototype of the initCmf() method must look like this:
. . . public void initCmf(Framework cmf, ObjectName name, boolean db, ModificationList list) . . .The ModificationList parameter is required in order to contain the list of parameters defined in the MLET tag.
You can also provide the bean and class names of the m-bean(s) to initialize:
.
.
.
ObjectName statsName = new ObjectName(cmf.getDomain(), beanName);
stats = (className) cmf.retrieveObject(statsName);
.
.
.
The initCmf() method in the QDatabaseAccounting.java file looks like this:
.
.
.
public void initCmf(Framework cmf, ObjectName name, boolean db,
ModificationList list)
throws InstanceNotFoundException, InstanceAlreadyExistException,
ServiceNotFoundException
{
this.cmf = cmf;
if (name == null) {
name = new ObjectName(cmf.getDomain(), getClass().getName());
}
if (db) {
cmf.addDBObject(this, name);
} else {
cmf.addObject(this, name);
}
this.name = name;
ObjectName statsName = new ObjectName(cmf.getDomain(), statsMOName);
stats = (QStatsInterface) cmf.retrieveObject(statsName);
String jdbcDriverName = null;
Enumeration enum = list.elements();
while (enum.hasMoreElements()) {
Modification modif = (Modification) enum.nextElement();
String property = modif.getProperty();
String value = (String) modif.getValue();
if (property.equalsIgnoreCase("jdbcDriverName")) {
jdbcDriverName = value;
} else if (property.equalsIgnoreCase("jdbcUrlName")) {
jdbcUrlName = value;
} else if (property.equalsIgnoreCase("jdbcUserName")) {
jdbcUserName = value;
} else if (property.equalsIgnoreCase("jdbcPassword")) {
jdbcPassword = value;
} else if (property.equalsIgnoreCase("jdbcTableName")) {
jdbcTableName = value;
}
}
try {
Class.forName(jdbcDriverName);
} catch (ClassNotFoundException e) {
throw new
ServiceNotFoundException("cannot load JDBC driver " + jdbcDriverName);
}
}
.
.
.
Make sure that the m-bean declaration implements the ActivatableIf interface:
.
.
.
public class QDatabaseAccounting implements QConstants, QFlowAccountingListene
r, ActivatableIf
{
.
.
.
This makes the performStart() and performStop() methods available.
Implement the performStart() method. In the case of the QDatabaseAccounting m-bean the performStart() method calls a method to start an event listener for flow accounting:
.
.
.
public void performStart()
{
if (!isActive()) {
try {
jdbcConnection = DriverManager.getConnection(jdbcUrlName, jdbcUserName,
jdbcPassword);
flowTable = new QFlowTable(jdbcConnection, jdbcTableName);
stats.addQFlowAccountingListener(this);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
.
.
.
Implement the performStop() method. For the QDatabaseAccounting m-bean, the performStop() method looks like this:
.
.
.
public void performStop()
{
if (isActive()) {
stats.removeQFlowAccountingListener(this);
try {
jdbcConnection.commit();
jdbcConnection.close();
jdbcConnection = null;
flowTable = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
}
.
.
.
Implement the isActive() method:
.
.
.
public boolean isActive()
{
return (jdbcConnection != null && flowTable != null);
}
.
.
.