KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > loadbalancer > raidb2 > RAIDb2ec_WRR


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Emmanuel Cecchet.
22  * Contributor(s): Julie Marguerite.
23  */

24
25 package org.objectweb.cjdbc.controller.loadbalancer.raidb2;
26
27 import java.sql.SQLException JavaDoc;
28 import java.util.HashMap JavaDoc;
29
30 import org.objectweb.cjdbc.common.exceptions.NotImplementedException;
31 import org.objectweb.cjdbc.common.sql.SelectRequest;
32 import org.objectweb.cjdbc.common.sql.StoredProcedure;
33 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
34 import org.objectweb.cjdbc.controller.cache.metadata.MetadataCache;
35 import org.objectweb.cjdbc.controller.loadbalancer.WeightedBalancer;
36 import org.objectweb.cjdbc.controller.loadbalancer.policies.WaitForCompletionPolicy;
37 import org.objectweb.cjdbc.controller.loadbalancer.policies.createtable.CreateTablePolicy;
38 import org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingPolicy;
39 import org.objectweb.cjdbc.controller.virtualdatabase.ControllerResultSet;
40 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase;
41
42 /**
43  * RAIDb-2 Weighted Round Robin load balancer with error checking.
44  * <p>
45  * This load balancer tolerates byzantine failures of databases. The read
46  * requests coming from the request manager are sent to multiple backend nodes
47  * and the results are compared. Write requests are broadcasted to all backends.
48  *
49  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
50  * @author <a HREF="mailto:Julie.Marguerite@inria.fr">Julie Marguerite </a>
51  * @version 1.0
52  */

53 public class RAIDb2ec_WRR extends RAIDb2ec
54 {
55   /*
56    * How the code is organized ? 1. Member variables 2. Constructor(s) 3.
57    * Request handling 4. Debug/Monitoring
58    */

59
60   private HashMap JavaDoc backends;
61
62   /*
63    * Constructors
64    */

65
66   /**
67    * Creates a new RAIDb-2 weighted round robin with error checking request load
68    * balancer.
69    *
70    * @param vdb The virtual database this load balancer belongs to.
71    * @param waitForCompletionPolicy How many backends must complete before
72    * returning the result?
73    * @param createTablePolicy The policy defining how 'create table' statements
74    * should be handled
75    * @param errorCheckingPolicy Policy to apply for error checking.
76    * @param nbOfConcurrentReads Number of concurrent reads allowed
77    * @exception Exception if an error occurs
78    */

79   public RAIDb2ec_WRR(VirtualDatabase vdb,
80       WaitForCompletionPolicy waitForCompletionPolicy,
81       CreateTablePolicy createTablePolicy,
82       ErrorCheckingPolicy errorCheckingPolicy, int nbOfConcurrentReads)
83       throws Exception JavaDoc
84   {
85     super(vdb, waitForCompletionPolicy, createTablePolicy, errorCheckingPolicy,
86         nbOfConcurrentReads);
87   }
88
89   /*
90    * Request Handling
91    */

92
93   /**
94    * Performs a read request. It is up to the implementation to choose to which
95    * backend node(s) this request should be sent.
96    *
97    * @param request an <code>SelectRequest</code>
98    * @param metadataCache cached metadata to use to construct the result set
99    * @return the corresponding <code>java.sql.ResultSet</code>
100    * @exception SQLException if an error occurs
101    * @see org.objectweb.cjdbc.controller.loadbalancer.raidb2.RAIDb2#execReadRequest(SelectRequest,
102    * MetadataCache)
103    */

104   public ControllerResultSet execReadRequest(SelectRequest request,
105       MetadataCache metadataCache) throws SQLException JavaDoc
106   {
107     throw new NotImplementedException(this.getClass().getName()
108         + ":execReadRequest");
109   }
110
111   /**
112    * Not implemented.
113    *
114    * @see org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer#execReadOnlyReadStoredProcedure(StoredProcedure,
115    * MetadataCache)
116    */

117   public ControllerResultSet execReadOnlyReadStoredProcedure(
118       StoredProcedure proc, MetadataCache metadataCache) throws SQLException JavaDoc
119   {
120     throw new NotImplementedException(this.getClass().getName()
121         + ":execReadStoredProcedure");
122   }
123
124   /*
125    * Backends management
126    */

127
128   /**
129    * @see org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer#setWeight(String,
130    * int)
131    */

132   public void setWeight(String JavaDoc name, int w) throws SQLException JavaDoc
133   {
134     throw new SQLException JavaDoc("Weight is not supported with this load balancer");
135   }
136
137   /*
138    * Debug/Monitoring
139    */

140
141   /**
142    * Gets information about the request load balancer.
143    *
144    * @return <code>String</code> containing information
145    */

146   public String JavaDoc getInformation()
147   {
148     if (backends == null)
149       return "RAIDb-2 Error Checking with Weighted Round Robin Request load balancer: "
150           + "!!!Warning!!! No backend nodes found\n";
151     else
152       return "RAIDb-2 Error Checking with Weighted Round Robin Request load balancer balancing over "
153           + backends.size() + " nodes\n";
154   }
155
156   /**
157    * @see RAIDb2#getRaidb2Xml()
158    */

159   public String JavaDoc getRaidb2Xml()
160   {
161     return WeightedBalancer.getRaidbXml(backends,
162         DatabasesXmlTags.ELT_RAIDb_2ec_WeightedRoundRobin);
163   }
164 }
Popular Tags