KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > scheduler > raidb1 > RAIDb1PassThroughScheduler


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 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): Jean-Bernard van Zuylen.
23  */

24
25 package org.objectweb.cjdbc.controller.scheduler.raidb1;
26
27 import java.sql.SQLException JavaDoc;
28 import java.util.LinkedList JavaDoc;
29
30 import org.objectweb.cjdbc.common.exceptions.RollbackException;
31 import org.objectweb.cjdbc.common.sql.AbstractWriteRequest;
32 import org.objectweb.cjdbc.common.sql.ParsingGranularities;
33 import org.objectweb.cjdbc.common.sql.SelectRequest;
34 import org.objectweb.cjdbc.common.sql.StoredProcedure;
35 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
36 import org.objectweb.cjdbc.controller.requestmanager.RAIDbLevels;
37 import org.objectweb.cjdbc.controller.scheduler.AbstractScheduler;
38 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase;
39 import org.objectweb.cjdbc.controller.virtualdatabase.protocol.Commit;
40 import org.objectweb.cjdbc.controller.virtualdatabase.protocol.ReleaseSavepoint;
41 import org.objectweb.cjdbc.controller.virtualdatabase.protocol.Rollback;
42 import org.objectweb.cjdbc.controller.virtualdatabase.protocol.RollbackToSavepoint;
43 import org.objectweb.cjdbc.controller.virtualdatabase.protocol.SetSavepoint;
44
45 /**
46  * This scheduler provides pass through scheduling for RAIDb-1 controllers.
47  * Requests are only assigned a unique id and passed to the load balancer.
48  *
49  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
50  * @author <a HREF="mailto:jbvanzuylen@transwide.com">Jean-Bernard van Zuylen
51  * </a>
52  * @version 1.0
53  */

54 public class RAIDb1PassThroughScheduler extends AbstractScheduler
55 {
56
57   //
58
// How the code is organized ?
59
//
60
// 1. Member variables
61
// 2. Constructor
62
// 3. Request handling
63
// 4. Transaction management
64
// 5. Debug/Monitoring
65
//
66

67   private long requestId;
68   private LinkedList JavaDoc totalOrderQueue = null;
69
70   //
71
// Constructor
72
//
73

74   /**
75    * Creates a new Pass Through Scheduler that will set a new total order queue
76    * on the virtual database.
77    *
78    * @param vdb the virtual database we belong to
79    */

80   public RAIDb1PassThroughScheduler(VirtualDatabase vdb)
81   {
82     super(RAIDbLevels.RAIDb1, ParsingGranularities.NO_PARSING);
83     requestId = 0;
84     if (vdb.isDistributed())
85     {
86       totalOrderQueue = new LinkedList JavaDoc();
87       vdb.setTotalOrderQueue(totalOrderQueue);
88     }
89   }
90
91   //
92
// Request Handling
93
//
94

95   /**
96    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#scheduleReadRequest(SelectRequest)
97    */

98   public final synchronized void scheduleReadRequest(SelectRequest request)
99   {
100     request.setId(requestId++);
101   }
102
103   /**
104    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#readCompletedNotify(SelectRequest)
105    */

106   public final void readCompletedNotify(SelectRequest request)
107   {
108   }
109
110   /**
111    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#scheduleWriteRequest(AbstractWriteRequest)
112    */

113   public final synchronized void scheduleNonSuspendedWriteRequest(
114       AbstractWriteRequest request)
115   {
116     request.setId(requestId++);
117     if (totalOrderQueue != null)
118     {
119       synchronized (totalOrderQueue)
120       {
121         totalOrderQueue.addLast(request);
122       }
123     }
124   }
125
126   /**
127    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#notifyWriteCompleted(AbstractWriteRequest)
128    */

129   public final void notifyWriteCompleted(AbstractWriteRequest request)
130   {
131   }
132
133   /**
134    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#scheduleNonSuspendedStoredProcedure(org.objectweb.cjdbc.common.sql.StoredProcedure)
135    */

136   public final synchronized void scheduleNonSuspendedStoredProcedure(
137       StoredProcedure proc) throws SQLException JavaDoc, RollbackException
138   {
139     proc.setId(requestId++);
140     if (totalOrderQueue != null)
141     {
142       synchronized (totalOrderQueue)
143       {
144         totalOrderQueue.addLast(proc);
145       }
146     }
147   }
148
149   /**
150    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#notifyStoredProcedureCompleted(org.objectweb.cjdbc.common.sql.StoredProcedure)
151    */

152   public final void notifyStoredProcedureCompleted(StoredProcedure proc)
153   {
154   }
155
156   //
157
// Transaction Management
158
//
159

160   /**
161    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#commitTransaction(long)
162    */

163   protected final void commitTransaction(long transactionId)
164   {
165     if (totalOrderQueue != null)
166     {
167       synchronized (totalOrderQueue)
168       {
169         totalOrderQueue.addLast(new Commit("", transactionId));
170       }
171     }
172   }
173
174   /**
175    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#rollbackTransaction(long)
176    */

177   protected final void rollbackTransaction(long transactionId)
178   {
179     if (totalOrderQueue != null)
180     {
181       synchronized (totalOrderQueue)
182       {
183         totalOrderQueue.addLast(new Rollback("", transactionId));
184       }
185     }
186   }
187
188   /**
189    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#rollbackTransaction(long,
190    * String)
191    */

192   protected final void rollbackTransaction(long transactionId,
193       String JavaDoc savepointName)
194   {
195     if (totalOrderQueue != null)
196     {
197       synchronized (totalOrderQueue)
198       {
199         totalOrderQueue.addLast(new RollbackToSavepoint(transactionId,
200             savepointName));
201       }
202     }
203   }
204
205   /**
206    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#setSavepointTransaction(long,
207    * String)
208    */

209   protected final void setSavepointTransaction(long transactionId, String JavaDoc name)
210   {
211     if (totalOrderQueue != null)
212     {
213       synchronized (totalOrderQueue)
214       {
215         totalOrderQueue.addLast(new SetSavepoint(transactionId, name));
216       }
217     }
218   }
219
220   /**
221    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#releaseSavepointTransaction(long,
222    * String)
223    */

224   protected final void releaseSavepointTransaction(long transactionId,
225       String JavaDoc name)
226   {
227     if (totalOrderQueue != null)
228     {
229       synchronized (totalOrderQueue)
230       {
231         totalOrderQueue.addLast(new ReleaseSavepoint(transactionId, name));
232       }
233     }
234   }
235
236   //
237
// Debug/Monitoring
238
//
239
/**
240    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#getXmlImpl()
241    */

242   public String JavaDoc getXmlImpl()
243   {
244     return "<" + DatabasesXmlTags.ELT_RAIDb1Scheduler + " "
245         + DatabasesXmlTags.ATT_level + "=\"" + DatabasesXmlTags.VAL_passThrough
246         + "\"/>";
247   }
248 }
249
Popular Tags