01: /**
02: * Sequoia: Database clustering technology.
03: * Copyright (C) 2002-2004 French National Institute For Research In Computer
04: * Science And Control (INRIA).
05: * Contact: sequoia@continuent.org
06: *
07: * Licensed under the Apache License, Version 2.0 (the "License");
08: * you may not use this file except in compliance with the License.
09: * 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: */package org.continuent.sequoia.controller.loadbalancer;
21:
22: import java.util.HashMap;
23: import java.util.Iterator;
24:
25: import org.continuent.sequoia.common.xml.DatabasesXmlTags;
26:
27: /**
28: * To return information, weighted load balancers share the same kind of
29: * information on backend configuration.
30: *
31: * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
32: * @version 1.0
33: */
34: public abstract class WeightedBalancer {
35: /**
36: * get different xml tags of the weights in the system.
37: *
38: * @param weights a list ((String)name,(Integer)weight) of weights
39: * @return xml formatted string of weighted backends
40: */
41: public static final String getWeightedXml(HashMap weights) {
42: if (weights == null)
43: return "";
44: StringBuffer info = new StringBuffer();
45: String nametmp;
46: for (Iterator iterator = weights.keySet().iterator(); iterator
47: .hasNext();) {
48: nametmp = (String) iterator.next();
49: info.append("<" + DatabasesXmlTags.ELT_BackendWeight + " "
50: + DatabasesXmlTags.ATT_name + "=\"" + nametmp
51: + "\" " + DatabasesXmlTags.ATT_weight + "=\""
52: + weights.get(nametmp) + "\"/>");
53: }
54: return info.toString();
55: }
56:
57: /**
58: * Convert raidb weighted balancers into xml because they share common views.
59: *
60: * @param weights hashmap of (name,weight)
61: * @param xmltag the xml tag to use
62: * @return xml formatted string
63: */
64: public static final String getRaidbXml(HashMap weights,
65: String xmltag) {
66: StringBuffer info = new StringBuffer();
67: info.append("<" + xmltag + ">");
68: info.append(WeightedBalancer.getWeightedXml(weights));
69: info.append("</" + xmltag + ">");
70: return info.toString();
71: }
72: }
|