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

RAIDb1ec_WRR.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): Emmanuel Cecchet.
00022  * Contributor(s): Julie Marguerite.
00023  */
00024 
00025 package org.objectweb.cjdbc.controller.loadbalancer.raidb1;
00026 
00027 import java.sql.SQLException;
00028 import java.util.HashMap;
00029 
00030 import org.objectweb.cjdbc.common.i18n.Translate;
00031 import org.objectweb.cjdbc.common.sql.NotImplementedException;
00032 import org.objectweb.cjdbc.common.sql.SelectRequest;
00033 import org.objectweb.cjdbc.common.sql.StoredProcedure;
00034 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
00035 import org.objectweb.cjdbc.controller.cache.metadata.MetadataCache;
00036 import org.objectweb.cjdbc.controller.loadbalancer.WeightedBalancer;
00037 import org.objectweb.cjdbc.controller.loadbalancer.policies.WaitForCompletionPolicy;
00038 import org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingPolicy;
00039 import org.objectweb.cjdbc.controller.virtualdatabase.ControllerResultSet;
00040 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase;
00041 
00042 /**
00043  * RAIDb-1 Weighted Round Robin load balancer with error checking.
00044  * <p>
00045  * This load balancer tolerates byzantine failures of databases. The read
00046  * requests coming from the Request Manager are sent to multiple backend nodes
00047  * and the results are compared. Write requests are broadcasted to all backends.
00048  * 
00049  * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
00050  * @author <a href="mailto:Julie.Marguerite@inria.fr">Julie Marguerite </a>
00051  * @version 1.0
00052  */
00053 public class RAIDb1ec_WRR extends RAIDb1ec
00054 {
00055   /*
00056    * How the code is organized ? 1. Member variables 2. Constructor(s) 3.
00057    * Request handling 4. Debug/Monitoring
00058    */
00059 
00060   //  private int index; // index in the backend vector the Round-Robin
00061   private HashMap weights;
00062 
00063   /*
00064    * Constructors
00065    */
00066 
00067   /**
00068    * Creates a new RAIDb-1 Weighted Round Robin with error checking request load
00069    * balancer.
00070    * 
00071    * @param vdb the virtual database this load balancer belongs to.
00072    * @param waitForCompletionPolicy How many backends must complete before
00073    *          returning the result?
00074    * @param errorCheckingPolicy policy to apply for error checking.
00075    * @param nbOfConcurrentReads number of concurrent reads allowed
00076    * @exception Exception if an error occurs
00077    */
00078   public RAIDb1ec_WRR(VirtualDatabase vdb,
00079       WaitForCompletionPolicy waitForCompletionPolicy,
00080       ErrorCheckingPolicy errorCheckingPolicy, int nbOfConcurrentReads)
00081       throws Exception
00082   {
00083     super(vdb, waitForCompletionPolicy, errorCheckingPolicy,
00084         nbOfConcurrentReads);
00085     // index = -1;
00086   }
00087 
00088   /*
00089    * Request Handling
00090    */
00091 
00092   /**
00093    * Not implemented.
00094    * 
00095    * @see org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1#execReadRequest(SelectRequest, MetadataCache)
00096    */
00097   public ControllerResultSet execReadRequest(SelectRequest request, MetadataCache metadataCache)
00098       throws SQLException
00099   {
00100     throw new NotImplementedException(this.getClass().getName()
00101         + ":execReadRequest");
00102   }
00103 
00104   /**
00105    * Not implemented.
00106    * 
00107    * @see org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer#execReadOnlyReadStoredProcedure(StoredProcedure, MetadataCache)
00108    */
00109   public ControllerResultSet execReadOnlyReadStoredProcedure(StoredProcedure proc, MetadataCache metadataCache)
00110       throws SQLException
00111   {
00112     throw new NotImplementedException(this.getClass().getName()
00113         + ":execReadStoredProcedure");
00114   }
00115 
00116   /*
00117    * Backends management
00118    */
00119 
00120   /**
00121    * @see org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer#setWeight(String,
00122    *      int)
00123    */
00124   public void setWeight(String name, int w) throws SQLException
00125   {
00126     if (logger.isDebugEnabled())
00127       logger.debug(Translate.get("loadbalancer.weight.set", new String[]{
00128           String.valueOf(w), name}));
00129 
00130     weights.put(name, new Integer(w));
00131   }
00132 
00133   /*
00134    * Debug/Monitoring
00135    */
00136 
00137   /**
00138    * Gets information about the request load balancer.
00139    * 
00140    * @return <code>String</code> containing information
00141    */
00142   public String getInformation()
00143   {
00144     // We don't lock since we don't need a top accurate value
00145     int size = vdb.getBackends().size();
00146 
00147     if (size == 0)
00148       return "RAIDb-1 Error Checking with Weighted Round-Robin Request load balancer: "
00149           + "!!!Warning!!! No backend nodes found\n";
00150     else
00151       return "RAIDb-1 Error Checking with Weighted Round-Robin Request load balancer ("
00152           + size + " backends)\n";
00153   }
00154 
00155   /**
00156    * @see org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1#getRaidb1Xml
00157    */
00158   public String getRaidb1Xml()
00159   {
00160     return WeightedBalancer.getRaidbXml(weights,
00161         DatabasesXmlTags.ELT_RAIDb_1ec_WeightedRoundRobin);
00162   }
00163 }

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