Example: Implementing the WAS advisor

The following examples show how custom advisors can be implemented.

A sample custom advisor for WebSphere Application Server is included in the install_root/servers/samples/CustomAdvisors/ directory. The full code is not duplicated in this document. Ensure that the following will be implemented:

The complete advisor is only slightly more complex than the sample. It adds a specialized parsing routine that is more compact than the StringTokenizer example shown in the topic Example: Using data returned from advisors.

The more complex part of the sample code is in the Java servlet. Among other methods, the servlet contains two methods required by the servlet specification: init() and service(), and one method, run(), that is required by the Java.lang.thread class.
The relevant fragments of the servlet code appear below:
...
  public void init(ServletConfig config) throws ServletException { 
    super.init(config); 
    ... 
    _checker = new Thread(this); 
    _checker.start(); 
  } 

  public void run() { 
    setStatus(GOOD); 

    while (true) { 
      if (!getKeepRunning()) 
        return; 
      setStatus(figureLoad()); 
      setLastUpdate(new java.util.Date()); 

    try { 
      _checker.sleep(_interval * 1000); 
    } catch (Exception ignore) { ; } 
  } 
} 

public void service(HttpServletRequest req, HttpServletResponse res) 
                    throws ServletException, IOException { 
  ServletOutputStream out = null; 
  try { 
    out = res.getOutputStream(); 
  } catch (Exception e) { ... } 
  ... 
  res.setContentType("text/x-application-LBAdvisor"); 
  out.println(getStatusString()); 
  out.println(getLastUpdate().toString()); 
  out.flush(); return; 
} 
... 
Reference topic    

Terms and conditions for information centers | Feedback

Last updated: September 12, 2012 11:41 PM EDT
File name: rprf_advexwas.html