Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

WeightedBalancer.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Nicolas Modrzyk
00022  */
00023 
00024 package org.objectweb.cjdbc.controller.loadbalancer;
00025 
00026 import java.util.HashMap;
00027 import java.util.Iterator;
00028 
00029 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
00030 
00031 /**
00032  * To return information, weighted load balancers share the same kind of
00033  * information on backend configuration.
00034  * 
00035  * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
00036  * @version 1.0
00037  */
00038 public abstract class WeightedBalancer
00039 {
00040   /**
00041    * get different xml tags of the weights in the system.
00042    * 
00043    * @param weights a list ((String)name,(Integer)weight) of weights
00044    * @return xml formatted string of weighted backends
00045    */
00046   public static final String getWeightedXml(HashMap weights)
00047   {
00048     if (weights == null)
00049       return "";
00050     StringBuffer info = new StringBuffer();
00051     String nametmp;
00052     for (Iterator iterator = weights.keySet().iterator(); iterator.hasNext();)
00053     {
00054       nametmp = (String) iterator.next();
00055       info
00056           .append("<" + DatabasesXmlTags.ELT_BackendWeight + " "
00057               + DatabasesXmlTags.ATT_name + "=\"" + nametmp + "\" "
00058               + DatabasesXmlTags.ATT_weight + "=\"" + weights.get(nametmp)
00059               + "\"/>");
00060     }
00061     return info.toString();
00062   }
00063 
00064   /**
00065    * Convert raidb weighted balancers into xml because they share common views.
00066    * 
00067    * @param weights hashmap of (name,weight)
00068    * @param xmltag the xml tag to use
00069    * @return xml formatted string
00070    */
00071   public static final String getRaidbXml(HashMap weights, String xmltag)
00072   {
00073     StringBuffer info = new StringBuffer();
00074     info.append("<" + xmltag + ">");
00075     info.append(WeightedBalancer.getWeightedXml(weights));
00076     info.append("</" + xmltag + ">");
00077     return info.toString();
00078   }
00079 }

Generated on Mon Apr 11 22:01:35 2005 for C-JDBC by  doxygen 1.3.9.1