KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashSet 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
39 /**
40  * This scheduler provides optimistic query level scheduling for RAIDb-1
41  * controllers. Reads can execute in parallel of any request. Writes are flagged
42  * as blocking or not based on the completion of a previous write inside the
43  * same transaction.
44  *
45  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
46  * @author <a HREF="mailto:jbvanzuylen@transwide.com">Jean-Bernard van Zuylen
47  * </a>
48  * @version 1.0
49  */

50 public class RAIDb1OptimisticQueryLevelScheduler extends AbstractScheduler
51 {
52
53   //
54
// How the code is organized ?
55
//
56
// 1. Member variables
57
// 2. Constructor
58
// 3. Request handling
59
// 4. Transaction management
60
// 5. Debug/Monitoring
61
//
62

63   private long requestId;
64   private HashSet JavaDoc completedWrites = new HashSet JavaDoc(); // set of tids
65

66   //
67
// Constructor
68
//
69

70   /**
71    * Creates a new Query Level Scheduler
72    */

73   public RAIDb1OptimisticQueryLevelScheduler()
74   {
75     super(RAIDbLevels.RAIDb1, ParsingGranularities.NO_PARSING);
76     requestId = 0;
77   }
78
79   //
80
// Request Handling
81
//
82

83   /**
84    * Additionally to scheduling the request, this method replaces the SQL Date
85    * macros such as now() with the current date.
86    *
87    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#scheduleReadRequest(SelectRequest)
88    */

89   public synchronized void scheduleReadRequest(SelectRequest request)
90       throws SQLException JavaDoc
91   {
92     request.setId(requestId++);
93   }
94
95   /**
96    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#readCompletedNotify(SelectRequest)
97    */

98   public final void readCompletedNotify(SelectRequest request)
99   {
100   }
101
102   /**
103    * Additionally to scheduling the request, this method replaces the SQL Date
104    * macros such as now() with the current date.
105    *
106    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#scheduleWriteRequest(AbstractWriteRequest)
107    */

108   public synchronized void scheduleNonSuspendedWriteRequest(
109       AbstractWriteRequest request) throws SQLException JavaDoc
110   {
111     request.setId(requestId++);
112     // if (request.isAutoCommit())
113
// request.setBlocking(true);
114
// else
115
request.setBlocking(completedWrites.contains(new Long JavaDoc(request
116         .getTransactionId())));
117   }
118
119   /**
120    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#notifyWriteCompleted(AbstractWriteRequest)
121    */

122   public final synchronized void notifyWriteCompleted(
123       AbstractWriteRequest request)
124   {
125     if (!request.isAutoCommit())
126       completedWrites.add(new Long JavaDoc(request.getTransactionId()));
127   }
128
129   /**
130    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#scheduleNonSuspendedStoredProcedure(org.objectweb.cjdbc.common.sql.StoredProcedure)
131    */

132   public final synchronized void scheduleNonSuspendedStoredProcedure(
133       StoredProcedure proc) throws SQLException JavaDoc, RollbackException
134   {
135     proc.setId(requestId++);
136     proc.setBlocking(completedWrites
137         .contains(new Long JavaDoc(proc.getTransactionId())));
138   }
139
140   /**
141    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#notifyStoredProcedureCompleted(org.objectweb.cjdbc.common.sql.StoredProcedure)
142    */

143   public final void notifyStoredProcedureCompleted(StoredProcedure proc)
144   {
145     if (!proc.isAutoCommit())
146       completedWrites.add(new Long JavaDoc(proc.getTransactionId()));
147   }
148
149   //
150
// Transaction Management
151
//
152

153   /**
154    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#commitTransaction(long)
155    */

156   protected final void commitTransaction(long transactionId)
157   {
158     completedWrites.remove(new Long JavaDoc(transactionId));
159   }
160
161   /**
162    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#rollbackTransaction(long)
163    */

164   protected final void rollbackTransaction(long transactionId)
165   {
166     completedWrites.remove(new Long JavaDoc(transactionId));
167   }
168
169   /**
170    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#rollbackTransaction(long,
171    * String)
172    */

173   protected final void rollbackTransaction(long transactionId,
174       String JavaDoc savepointName)
175   {
176   }
177
178   /**
179    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#setSavepointTransaction(long,
180    * String)
181    */

182   protected final void setSavepointTransaction(long transactionId, String JavaDoc name)
183   {
184   }
185
186   /**
187    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#releaseSavepointTransaction(long,
188    * String)
189    */

190   protected final void releaseSavepointTransaction(long transactionId,
191       String JavaDoc name)
192   {
193   }
194
195   //
196
// Debug/Monitoring
197
//
198

199   /**
200    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#getXmlImpl()
201    */

202   public String JavaDoc getXmlImpl()
203   {
204     return "<" + DatabasesXmlTags.ELT_RAIDb1Scheduler + " "
205         + DatabasesXmlTags.ATT_level + "=\""
206         + DatabasesXmlTags.VAL_optimisticQuery + "\"/>";
207   }
208 }
209
Popular Tags