Il seguente esempio mostra come utilizzare un advisor personalizzato standard.
Questo advisor funziona in modalità normale, pertanto la misurazione del carico si basa sul tempo trascorso (espresso in millisecondi) richiesto per eseguire le operazioni di apertura socket, di invio, di ricezione e chiusura.
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;
}
}