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

RAIDb1OptimisticQueryLevelScheduler.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): _________________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.controller.scheduler.raidb1;
00026 
00027 import java.sql.SQLException;
00028 import java.util.HashSet;
00029 
00030 import org.objectweb.cjdbc.common.sql.AbstractWriteRequest;
00031 import org.objectweb.cjdbc.common.sql.ParsingGranularities;
00032 import org.objectweb.cjdbc.common.sql.SelectRequest;
00033 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
00034 import org.objectweb.cjdbc.controller.requestmanager.RAIDbLevels;
00035 import org.objectweb.cjdbc.controller.scheduler.AbstractScheduler;
00036 
00037 /**
00038  * This scheduler provides optimistic query level scheduling for RAIDb-1
00039  * controllers. Reads can execute in parallel of any request. Writes are
00040  * flagged as blocking or not based on the completion of a previous write
00041  * inside the same transaction.
00042  * 
00043  * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
00044  * @version 1.0
00045  */
00046 public class RAIDb1OptimisticQueryLevelScheduler extends AbstractScheduler
00047 {
00048 
00049   //
00050   // How the code is organized ?
00051   //
00052   // 1. Member variables
00053   // 2. Constructor
00054   // 3. Request handling
00055   // 4. Transaction management
00056   // 5. Debug/Monitoring
00057   //
00058 
00059   private long    requestId;
00060   private HashSet completedWrites = new HashSet(); // set of tids
00061 
00062   //
00063   // Constructor
00064   //
00065 
00066   /**
00067    * Creates a new Query Level Scheduler
00068    */
00069   public RAIDb1OptimisticQueryLevelScheduler()
00070   {
00071     super(RAIDbLevels.RAIDb1, ParsingGranularities.NO_PARSING);
00072     requestId = 0;
00073   }
00074 
00075   //
00076   // Request Handling
00077   //
00078 
00079   /**
00080    * Additionally to scheduling the request, this method replaces the SQL Date
00081    * macros such as now() with the current date.
00082    * 
00083    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#scheduleReadRequest(SelectRequest)
00084    */
00085   public synchronized void scheduleReadRequest(SelectRequest request)
00086       throws SQLException
00087   {
00088     request.setId(requestId++);
00089   }
00090 
00091   /**
00092    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#readCompletedNotify(SelectRequest)
00093    */
00094   public final void readCompletedNotify(SelectRequest request)
00095   {
00096   }
00097 
00098   /**
00099    * Additionally to scheduling the request, this method replaces the SQL Date
00100    * macros such as now() with the current date.
00101    * 
00102    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#scheduleWriteRequest(AbstractWriteRequest)
00103    */
00104   public synchronized void scheduleNonSuspendedWriteRequest(
00105       AbstractWriteRequest request) throws SQLException
00106   {
00107     request.setId(requestId++);
00108     //    if (request.isAutoCommit())
00109     //      request.setBlocking(true);
00110     //    else
00111     request.setBlocking(completedWrites.contains(new Long(request
00112         .getTransactionId())));
00113   }
00114 
00115   /**
00116    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#notifyWriteCompleted(AbstractWriteRequest)
00117    */
00118   public final synchronized void notifyWriteCompleted(
00119       AbstractWriteRequest request)
00120   {
00121     if (!request.isAutoCommit())
00122       completedWrites.add(new Long(request.getTransactionId()));
00123   }
00124 
00125   //
00126   // Transaction Management
00127   //
00128 
00129   /**
00130    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#commitTransaction(long)
00131    */
00132   protected final void commitTransaction(long transactionId)
00133   {
00134     completedWrites.remove(new Long(transactionId));
00135   }
00136 
00137   /**
00138    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#rollbackTransaction(long)
00139    */
00140   protected final void rollbackTransaction(long transactionId)
00141   {
00142     completedWrites.remove(new Long(transactionId));
00143   }
00144 
00145   //
00146   // Debug/Monitoring
00147   //
00148 
00149   /**
00150    * @see org.objectweb.cjdbc.controller.scheduler.AbstractScheduler#getXmlImpl()
00151    */
00152   public String getXmlImpl()
00153   {
00154     return "<" + DatabasesXmlTags.ELT_RAIDb1Scheduler + " "
00155         + DatabasesXmlTags.ATT_level + "=\""
00156         + DatabasesXmlTags.VAL_optimisticQuery + "\"/>";
00157   }
00158 
00159 }

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