WebSphere Extended Deployment, Version 6.0.x     Operating Systems: AIX, HP-UX, Linux, Solaris, Windows

一例

次のリストは、サンプルの HTTP 区画化機能アプリケーション・サーブレットの 内容です。
  	public class ListPartitions extends HttpServlet implements Servlet,
  HttpPartitionNotification {
	private static String className = "ListPartitions";
	private static String appName = "http.wpf.sample";
	private static HttpPartitionManager httpPartitionManager =
  HttpPartitionManager.instance;
	    
public void init() throws ServletException {
	   System.out.println(className+": Registering notification ");
		 httpPartitionManager.registerNotification(appName, this);
 }
    
  public void destroy() {
	   System.out.println(className+": Deregistering notification ");
	   httpPartitionManager.deregisterNotification(appName, this);
   }
	
  public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
		
	  resp.setContentType("text/html");
   	ServletOutputStream out = resp.getOutputStream();
out.println("<html>");
   	out.println("<head><title>Hello World</title></head>");
   	out.println("<body>");
   	out.println("<h1>Hello World</h1><h1>");
		out.println(listPartitions());
		out.println("</h1>");
		out.println("");	
}
	    
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
 }
	    
  public static String listPartitions() {
		HttpPartitionManager httpPartitionManager =
    HttpPartitionManager.instance;
    Vector partitions = httpPartitionManager.getActivePartitions
    (appName);
    String output = "Number of Partitions: "+partitions.size()+":
    ¥nPartitions:¥n";
     for (int i=0; i< partitions.size(); i++)
    output = output.concat(partitions.elementAt(i) + "¥n");
    return output;
  }
	
public Vector getPartitions() {
		System.out.println(className+": getPartitions ");
		Vector myVect = new Vector();
		myVect.add("jian");
		myVect.add("lou");
	  System.out.println(className+": getPartitions number of partitions:
    "+myVect.size());
	  return myVect;   // Do not override partitions
 	 }
	
public HttpPartitionExpression[] getExpressions() {
		System.out.println(className+": getExpressions ");
		HttpPartitionExpression[] expressions = new HttpPartitionExpression[2];
		expressions[0] = httpPartitionManager.createHttpPartitionExpression
    ("(user=)(.*)&", "$2");
		expressions[1] = httpPartitionManager.createHttpPartitionExpression
    ("(user=)(.*)$", "$2");
		System.out.println(className+": getExpressions number of expressions
    "+expressions.length);
		return expressions;   // Do not override expressions
  }
	
public boolean loadEvent(String partitionName) {
		 /*
		 * now is a good time to start caching relevant data
		 */
		System.out.println(className+": load "+partitionName);
	
return true;
  }
	    
public void unloadEvent(String partitionName)
	    {
		/*
		 * now is a good time to flush relevant cached data
		 */
		System.out.println(className+": unload "+partitionName);
  }
	    
public boolean isPartitionAlive(String partitionName)
	    {
		/*
		 * can check if a partition is still active
		 */	
		System.out.println(className+": isPartitionAlive ");
return true;
	    }
}
この例では、HttpPartitionManager で 2 つの区画名 (この例の場合 lou および jian) と 2 つの要求表現を指定する方法を示しています。 区画名の指定には通知インターフェースの getPartitions() を、要求表現の指定には通知インターフェースの getExpressions() メソッドを使用しています。このサーブレットでどちらも指定しない場合 (例えば、付属の partitions.xml ファイルで 提供されている場合や、EJB で指定されている場合など)、この 2 つのメソッドは NULL を返します。



Related concepts
HTTP 区画

Reference topic    

Terms of Use | Feedback Last updated: Mar 20, 2006 12:35:11 PM EST
http://publib.boulder.ibm.com/infocenter/wxdinfo/v6r0/index.jsp?topic=?topic=/com.ibm.websphere.xd.doc/info/WPF51/rwpfexample.html

© Copyright IBM 2005, 2006. All Rights Reserved.
This information center is powered by Eclipse technology. (http://www.eclipse.org)