Esempio: Implementazione di advisor standard

Il seguente esempio mostra come utilizzare un advisor personalizzato standard.

Questo codice sorgente di esempio è simile all'advisor HTTP Load Balancer standard. Funziona come segue:
  1. Viene emessa una richiesta di invio, ovvero un comando "HEAD/HTTP".
  2. Si riceve una risposta. L'informazione non viene analizzata, ma la risposta causa l'interruzione del metodo getLoad.
  3. Il metodo getLoad restituisce 0 per indicare una riuscita o -1 per indicare un errore.

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; 
  } 
} 
Argomento di riferimento    

Clausole e condizioni per i centri informazioni | Feedback

Ultimo aggiornamento: May 14, 2012 01:50 PM EDT
Nome file: rprf_advexstand.html