A custom advisor is a small piece of Java code, provided as a class file, that is called by the Load Balancer base code to determine the load on a server. The base code provides all necessary administrative services, including starting and stopping an instance of the custom advisor, providing status and reports, recording history information in a log file, and reporting advisor results to the manager component.
When the Load Balancer base code calls a custom advisor, the following steps happen.
Custom advisors can be designed to interact with the Load Balancer in either normal mode or replace mode.
The choice for the mode of operation is specified in the custom advisor file as a parameter in the constructor method. (Each advisor operates in only one of these modes, based on its design.)
In normal mode, the custom advisor exchanges data with the server, and the base advisor code times the exchange and calculates the load value. The base code then reports this load value to the manager. The custom advisor returns the value zero to indicate success, or negative one to indicate an error.
To specify normal mode, set the replace flag in the constructor to false.
In replace mode, the base code does not perform any timing measurements. The custom advisor code performs whatever operations are specified, based on its unique requirements, and then returns an actual load number. The base code accepts the load number and reports it, unaltered, to the manager. For best results, normalize your load numbers between 10 and 1000, with 10 representing a fast server and 1000 representing a slow server.
To specify replace mode, set the replace flag in the constructor to true.
Custom advisor file names must follow the form ADV_name.java, where name is the name that you choose for your advisor. The complete name must start with the prefix ADV_ in uppercase letters, and all subsequent characters must be lowercase letters. The requirement for lowercase letters ensures that the command for running the advisor is not case sensitive.
According to Java conventions, the name of the class defined within the file must match the name of the file.
You must write custom advisors in the Java language and compile them with a Java compiler that is at the same level as the Load Balancer code. To check the version of Java on your system, run the following command from the install_path/java/bin directory:
java -fullversion
If the current directory is not part of your path, you will need to specify that Java should be run from the current directory to ensure you are getting the correct version information. In this case, run the following command from theinstall_path/java/bin directory:
./java -fullversion
The following files are referenced during compilation:
Your classpath environment variable must point to both the custom advisor file and the base classes file during the compilation. A compile command might have the following format: For UNIX Windows systems, a sample compile command is:
install_path/java/bin/javac -classpath /opt/ibm/edge/lb/servers/lib/ibmlb.jar ADV_name.java
where:
The output of the compilation is a class file, for example, ADV_name.class. Before starting the advisor, copy the class file to the install_path/servers/lib/CustomAdvisors/ directory.
To run the custom advisor, you must first copy the advisor's class file to the lib/CustomAdvisors/ subdirectory on the Load Balancer machine. For example, for a custom advisor named myping, the file path is install_path/servers/lib/CustomAdvisors/ADV_myping.class
Configure the Load Balancer, start its manager function, and issue the command to start your custom advisor. The custom advisor is specified by its name, excluding the ADV_ prefix and the file extension:
dscontrol advisor start myping port_number
The port number specified in the command is the port on which the advisor will open a connection with the target server.
Like all advisors, a custom advisor extends the functionality of the advisor base class, which is called ADV_Base. The advisor base performs most of the advisor's functions, such as reporting loads back to the manager for use in the manager's weight algorithm. The advisor base also performs socket connect and close operations and provides send and receive methods for use by the advisor. The advisor is used only for sending and receiving data on the specified port for the server that is being investigated. The TCP methods provided within the advisor base are timed to calculate load. A flag within the constructor of the advisor base overwrites the existing load with the new load returned from the advisor, if desired.
Advisors have the following base class methods:
Details about these required routines appear later in this section.
Custom advisors are called after native, or standard, advisors have been searched. If the Load Balancer does not find a specified advisor among the list of standard advisors, it consults the list of custom advisors. Additional information about using advisors is available in the WebSphere® Application Server Load Balancer Administration Guide.
Remember the following requirements for custom advisor names and paths.
public <advisor_name> ( String sName; String sVersion; int iDefaultPort; int iInterval; String sDefaultLogFileName; boolean replace )
void ADV_AdvisorInitialize()
This method is provided to perform any initialization that might be required for the custom advisor. This method is called after the advisor base module starts.
In many cases, including the standard advisors, this method is not used and its code consists of a return statement only. This method can be used to call the suppressBaseOpeningSocket method, which is valid only from within this method.
int getLoad( int iConnectTime; ADV_Thread *caller )
The methods, or functions, described in the following sections can be called from custom advisors. These methods are supported by the advisor base code.
Some of these function calls can be made directly, for example, function_name(), but others require the prefix caller. Caller represents the base advisor instance that supports the custom advisor that is being executed.
The ADVLOG function allows a custom advisor to write a text message to the advisor base log file. The format follows:
void ADVLOG (int logLevel, String message)
The getAdvisorName function returns a Java string with the suffix portion of your custom advisor's name. For example, for an advisor named ADV_cdload.java, this function returns the value cdload.
This function takes no parameters.
Note that it is not possible for this value to change during one instantiation of an advisor.
The getAdviseOnPort function returns the port number on which the calling custom advisor is running. The return value is a Java integer (int), and the function takes no parameters.
Note that it is not possible for this value to change during one instantiation of an advisor.
The getCurrentServerId function returns a Java string which is a unique representation for the current server.
Typically, this value changes each time you call your custom advisor, because the advisor base code queries all server machines in series.
This function takes no parameters.
The getCurrentClusterId function call returns a Java string which is a unique representation for the current cluster.
Typically, this value changes each time you call your custom advisor, because the advisor base queries all clusters in series.
This function takes no parameters.
The getSocket function call returns a Java socket which represents the socket opened to the current server for communication.
This function takes no parameters.
The getInterval function returns the advisor interval, that is, the number of seconds between advisor cycles. This value is equal to the default value set in the custom advisor's constructor, unless the value has been modified at run time by using the dscontrol command.
The return value is a Java integer (int). The function takes no parameters.
The getLatestLoad function allows a custom advisor to obtain the latest load value for a given server object. The load values are maintained in internal tables by the advisor base code and the manager daemon.
int caller.getLatestLoad (String clusterId, int port, String serverId)
The three arguments together define one server object.
The return value is an integer.
This function call is useful if you want to make the behavior of one protocol or port dependent on the behavior of another. For example, you might use this function call in a custom advisor that disabled a particular application server if the Telnet server on that same machine was disabled.
The receive function gets information from the socket connection.
caller.receive(StringBuffer *response)
The parameter response is a string buffer into which the retrieved data is placed. Additionally, the function returns an integer value with the following significance:
The send function uses the established socket connection to send a packet of data to the server, using the specified port.
caller.send(String command)
The parameter command is a string containing the data to send to the server. The function returns an integer value with the following significance:
The suppressBaseOpeningSocket function call allows a custom advisor to specify whether the base advisor code opens a TCP socket to the server on the custom advisor's behalf. If your advisor does not use direct communication with the server to determine its status, it might not be necessary to open this socket.
This function call can be issued only once, and it must be issued from the ADV_AdvisorInitialize routine.
The function takes no parameters.