KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > loadbalancer > WeightedBalancer


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: sequoia@continuent.org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Initial developer(s): Nicolas Modrzyk
20  */

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

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

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

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