以下の例では、標準カスタム advisor を使用する方法を具体的に示します。
この advisor は通常モードで操作されるため、負荷測定は、ソケットのオープン、送信、受信、およびクローズ操作の実行に必要な経過時間 (ミリ秒) に 基づいて行われます。
package CustomAdvisors;
import com.ibm.internet.lb.advisors.*;
public class ADV_sample extends ADV_Base implements ADV_MethodInterface {
static final String ADV_NAME ="Sample";
static final int ADV_DEF_ADV_ON_PORT = 80;
static final int ADV_DEF_INTERVAL = 7;
static final String ADV_SEND_REQUEST =
"HEAD / HTTP/1.0¥r¥nAccept: */*¥r¥nUser-Agent: " +
"IBM_Load_Balancer_HTTP_Advisor¥r¥n¥r¥n";
//--------
// Constructor
public ADV_sample() {
super(ADV_NAME, "3.0.0.0-03.31.00",
ADV_DEF_ADV_ON_PORT, ADV_DEF_INTERVAL, "",
false);
super.setAdvisor( this );
}
//--------
// ADV_AdvisorInitialize
public void ADV_AdvisorInitialize() {
return; // usually an empty routine
}
//--------
// getLoad
public int getLoad(int iConnectTime, ADV_Thread caller) {
int iRc;
int iLoad = ADV_HOST_INACCESSIBLE; // initialize to inaccessible
iRc = caller.send(ADV_SEND_REQUEST); // send the HTTP request to
// the server
if (0 <= iRc) { // if the send is successful
StringBuffer sbReceiveData = new StringBuffer(""); // allocate a buffer
// for the response
iRc = caller.receive(sbReceiveData); // receive the result
// parse the result here if you need to
if (0 <= iRc) { // if the receive is successful
iLoad = 0; // return 0 for success
} // (advisor's load value is ignored by
} // base in normal mode)
return iLoad;
}
}