例: 標準 advisor の実装

以下の例では、標準カスタム advisor を使用する方法を具体的に示します。

このサンプル・ソース・コードは、標準 Load Balancer HTTP advisor の場合と 類似しています。これは次のように機能します。
  1. 送信要求の "HEAD/HTTP" コマンドが出されます。
  2. 応答が受信されます。情報は解析されませんが、この応答によって、getLoad メソッドは終了します。
  3. getLoad メソッドでは、成功を示す場合には 0 を、失敗を示す場合には -1 を戻します。

この 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; 
  } 
} 
Reference topic    

Terms and conditions for information centers | Feedback

Last updated: May 28, 2013 08:30 AM EDT
File name: rprf_advexstand.html