KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > loadbalancer > WeightedBalancer


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk
22  */

23
24 package org.objectweb.cjdbc.controller.loadbalancer;
25
26 import java.util.HashMap JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
30
31 /**
32  * To return information, weighted load balancers share the same kind of
33  * information on backend configuration.
34  *
35  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
36  * @version 1.0
37  */

38 public abstract class WeightedBalancer
39 {
40   /**
41    * get different xml tags of the weights in the system.
42    *
43    * @param weights a list ((String)name,(Integer)weight) of weights
44    * @return xml formatted string of weighted backends
45    */

46   public static final String JavaDoc getWeightedXml(HashMap JavaDoc weights)
47   {
48     if (weights == null)
49       return "";
50     StringBuffer JavaDoc info = new StringBuffer JavaDoc();
51     String JavaDoc nametmp;
52     for (Iterator JavaDoc iterator = weights.keySet().iterator(); iterator.hasNext();)
53     {
54       nametmp = (String JavaDoc) iterator.next();
55       info
56           .append("<" + DatabasesXmlTags.ELT_BackendWeight + " "
57               + DatabasesXmlTags.ATT_name + "=\"" + nametmp + "\" "
58               + DatabasesXmlTags.ATT_weight + "=\"" + weights.get(nametmp)
59               + "\"/>");
60     }
61     return info.toString();
62   }
63
64   /**
65    * Convert raidb weighted balancers into xml because they share common views.
66    *
67    * @param weights hashmap of (name,weight)
68    * @param xmltag the xml tag to use
69    * @return xml formatted string
70    */

71   public static final String JavaDoc getRaidbXml(HashMap JavaDoc weights, String JavaDoc xmltag)
72   {
73     StringBuffer JavaDoc info = new StringBuffer JavaDoc();
74     info.append("<" + xmltag + ">");
75     info.append(WeightedBalancer.getWeightedXml(weights));
76     info.append("</" + xmltag + ">");
77     return info.toString();
78   }
79 }
Popular Tags