KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > loadbalancer > raidb1 > RAIDb1ec_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.raidb1;
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.i18n.Translate;
32 import org.objectweb.cjdbc.common.sql.SelectRequest;
33 import org.objectweb.cjdbc.common.sql.StoredProcedure;
34 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
35 import org.objectweb.cjdbc.controller.cache.metadata.MetadataCache;
36 import org.objectweb.cjdbc.controller.loadbalancer.WeightedBalancer;
37 import org.objectweb.cjdbc.controller.loadbalancer.policies.WaitForCompletionPolicy;
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-1 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 RAIDb1ec_WRR extends RAIDb1ec
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 int index; // index in the backend vector the Round-Robin
61
private HashMap JavaDoc weights;
62
63   /*
64    * Constructors
65    */

66
67   /**
68    * Creates a new RAIDb-1 Weighted Round Robin with error checking request load
69    * balancer.
70    *
71    * @param vdb the virtual database this load balancer belongs to.
72    * @param waitForCompletionPolicy How many backends must complete before
73    * returning the result?
74    * @param errorCheckingPolicy policy to apply for error checking.
75    * @param nbOfConcurrentReads number of concurrent reads allowed
76    * @exception Exception if an error occurs
77    */

78   public RAIDb1ec_WRR(VirtualDatabase vdb,
79       WaitForCompletionPolicy waitForCompletionPolicy,
80       ErrorCheckingPolicy errorCheckingPolicy, int nbOfConcurrentReads)
81       throws Exception JavaDoc
82   {
83     super(vdb, waitForCompletionPolicy, errorCheckingPolicy,
84         nbOfConcurrentReads);
85     // index = -1;
86
}
87
88   /*
89    * Request Handling
90    */

91
92   /**
93    * Not implemented.
94    *
95    * @see org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1#execReadRequest(SelectRequest, MetadataCache)
96    */

97   public ControllerResultSet execReadRequest(SelectRequest request, MetadataCache metadataCache)
98       throws SQLException JavaDoc
99   {
100     throw new NotImplementedException(this.getClass().getName()
101         + ":execReadRequest");
102   }
103
104   /**
105    * Not implemented.
106    *
107    * @see org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer#execReadOnlyReadStoredProcedure(StoredProcedure, MetadataCache)
108    */

109   public ControllerResultSet execReadOnlyReadStoredProcedure(StoredProcedure proc, MetadataCache metadataCache)
110       throws SQLException JavaDoc
111   {
112     throw new NotImplementedException(this.getClass().getName()
113         + ":execReadStoredProcedure");
114   }
115
116   /*
117    * Backends management
118    */

119
120   /**
121    * @see org.objectweb.cjdbc.controller.loadbalancer.AbstractLoadBalancer#setWeight(String,
122    * int)
123    */

124   public void setWeight(String JavaDoc name, int w) throws SQLException JavaDoc
125   {
126     if (logger.isDebugEnabled())
127       logger.debug(Translate.get("loadbalancer.weight.set", new String JavaDoc[]{
128           String.valueOf(w), name}));
129
130     weights.put(name, new Integer JavaDoc(w));
131   }
132
133   /*
134    * Debug/Monitoring
135    */

136
137   /**
138    * Gets information about the request load balancer.
139    *
140    * @return <code>String</code> containing information
141    */

142   public String JavaDoc getInformation()
143   {
144     // We don't lock since we don't need a top accurate value
145
int size = vdb.getBackends().size();
146
147     if (size == 0)
148       return "RAIDb-1 Error Checking with Weighted Round-Robin Request load balancer: "
149           + "!!!Warning!!! No backend nodes found\n";
150     else
151       return "RAIDb-1 Error Checking with Weighted Round-Robin Request load balancer ("
152           + size + " backends)\n";
153   }
154
155   /**
156    * @see org.objectweb.cjdbc.controller.loadbalancer.raidb1.RAIDb1#getRaidb1Xml
157    */

158   public String JavaDoc getRaidb1Xml()
159   {
160     return WeightedBalancer.getRaidbXml(weights,
161         DatabasesXmlTags.ELT_RAIDb_1ec_WeightedRoundRobin);
162   }
163 }
Popular Tags