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

RAIDb2_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.raidb2;
00026 
00027 import java.sql.SQLException;
00028 import java.util.HashMap;
00029 
00030 import org.objectweb.cjdbc.common.sql.NotImplementedException;
00031 import org.objectweb.cjdbc.common.sql.SelectRequest;
00032 import org.objectweb.cjdbc.common.sql.StoredProcedure;
00033 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
00034 import org.objectweb.cjdbc.controller.cache.metadata.MetadataCache;
00035 import org.objectweb.cjdbc.controller.loadbalancer.WeightedBalancer;
00036 import org.objectweb.cjdbc.controller.loadbalancer.policies.WaitForCompletionPolicy;
00037 import org.objectweb.cjdbc.controller.loadbalancer.policies.createtable.CreateTablePolicy;
00038 import org.objectweb.cjdbc.controller.virtualdatabase.ControllerResultSet;
00039 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase;
00040 
00041 /**
00042  * RAIDb-2 Weighted Round Robin load balancer.
00043  * <p>
00044  * The read requests coming from the request manager are sent to the backend
00045  * nodes using a weighted round robin. Write requests are broadcasted to all
00046  * backends.
00047  * 
00048  * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
00049  * @author <a href="mailto:Julie.Marguerite@inria.fr">Julie Marguerite </a>
00050  * @version 1.0
00051  */
00052 public class RAIDb2_WRR extends RAIDb2
00053 {
00054   /*
00055    * How the code is organized ? 1. Member variables 2. Constructor(s) 3.
00056    * Request handling 4. Debug/Monitoring
00057    */
00058 
00059   private HashMap weights;
00060 
00061   /*
00062    * Constructors
00063    */
00064 
00065   /**
00066    * Creates a new RAIDb-2 Weighted Round Robin request load balancer.
00067    * 
00068    * @param vdb The virtual database this load balancer belongs to.
00069    * @param waitForCompletionPolicy How many backends must complete before
00070    *          returning the result?
00071    * @param createTablePolicy The policy defining how 'create table' statements
00072    *          should be handled
00073    * @exception Exception if an error occurs
00074    */
00075   public RAIDb2_WRR(VirtualDatabase vdb,
00076       WaitForCompletionPolicy waitForCompletionPolicy,
00077       CreateTablePolicy createTablePolicy) throws Exception
00078   {
00079     super(vdb, waitForCompletionPolicy, createTablePolicy);
00080   }
00081 
00082   /*
00083    * Request Handling
00084    */
00085 
00086   /**
00087    * Performs a read request. It is up to the implementation to choose to which
00088    * backend node(s) this request should be sent.
00089    * 
00090    * @param request an <code>SelectRequest</code>
00091    * @param metadataCache cached metadata to use to construct the result set
00092    * @return the corresponding <code>java.sql.ResultSet</code>
00093    * @exception SQLException if an error occurs
00094    * @see org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2#execReadRequest(SelectRequest,
00095    *      MetadataCache)
00096    */
00097   public ControllerResultSet execReadRequest(SelectRequest request,
00098       MetadataCache metadataCache) throws SQLException
00099   {
00100     throw new NotImplementedException(this.getClass().getName()
00101         + ":execReadRequest");
00102   }
00103 
00104   /**
00105    * Chooses the node to execute the stored procedure using a round-robin
00106    * algorithm. If the next node has not the needed stored procedure, we try the
00107    * next one and so on until a suitable backend is found.
00108    * 
00109    * @see org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer#execReadOnlyReadStoredProcedure(StoredProcedure,
00110    *      MetadataCache)
00111    */
00112   public ControllerResultSet execReadOnlyReadStoredProcedure(
00113       StoredProcedure proc, MetadataCache metadataCache) throws SQLException
00114   {
00115     throw new NotImplementedException(this.getClass().getName()
00116         + ":execReadStoredProcedure");
00117   }
00118 
00119   /*
00120    * Backends management
00121    */
00122 
00123   /**
00124    * @see org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer#setWeight(String,
00125    *      int)
00126    */
00127   public void setWeight(String name, int w) throws SQLException
00128   {
00129     throw new SQLException("Weight is not supported with this load balancer");
00130   }
00131 
00132   /*
00133    * Debug/Monitoring
00134    */
00135 
00136   /**
00137    * Gets information about the request load balancer.
00138    * 
00139    * @return <code>String</code> containing information
00140    */
00141   public String getInformation()
00142   {
00143     if (weights == null)
00144       return "RAIDb-2 Weighted Round Robin Request load balancer: !!!Warning!!! No backend nodes found\n";
00145     else
00146       return "RAIDb-2 Weighted Round Robin Request load balancer balancing over "
00147           + weights.size() + " nodes\n";
00148   }
00149 
00150   /**
00151    * @see org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2#getRaidb2Xml
00152    */
00153   public String getRaidb2Xml()
00154   {
00155     return WeightedBalancer.getRaidbXml(weights,
00156         DatabasesXmlTags.ELT_RAIDb_2_WeightedRoundRobin);
00157   }
00158 }

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