001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Contact: sequoia@continuent.org
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: *
019: * Initial developer(s): Emmanuel Cecchet.
020: * Contributor(s): ______________________.
021: */package org.continuent.sequoia.controller.loadbalancer.raidb2;
022:
023: import java.util.ArrayList;
024:
025: import org.continuent.sequoia.common.log.Trace;
026: import org.continuent.sequoia.common.xml.DatabasesXmlTags;
027: import org.continuent.sequoia.controller.loadbalancer.policies.WaitForCompletionPolicy;
028: import org.continuent.sequoia.controller.loadbalancer.policies.createtable.CreateTablePolicy;
029: import org.continuent.sequoia.controller.loadbalancer.policies.errorchecking.ErrorCheckingPolicy;
030: import org.continuent.sequoia.controller.virtualdatabase.VirtualDatabase;
031:
032: /**
033: * RAIDb-2ec load balancer.
034: * <p>
035: * This class is an abstract call because the read requests coming from the
036: * request manager are NOT treated here but in the subclasses. This class deals
037: * with backend enable/disable for backendReadThreads creation/termination.
038: *
039: * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
040: * @version 1.0
041: */
042: public abstract class RAIDb2ec extends RAIDb2 {
043: /*
044: * How the code is organized ? 1. Member variables 2. Constructor(s) 3.
045: * Request handling 4. Transaction handling 5. Backend management
046: */
047:
048: protected ArrayList backendReadThreads;
049: protected int nbOfConcurrentReads;
050: protected ErrorCheckingPolicy errorCheckingPolicy;
051:
052: protected static Trace logger = Trace
053: .getLogger("org.continuent.sequoia.controller.loadbalancer.RAIDb2ec");
054:
055: /*
056: * Constructors
057: */
058:
059: /**
060: * Creates a new RAIDb-1 Round Robin request load balancer. A new backend
061: * worker thread is created for each backend.
062: *
063: * @param vdb the virtual database this load balancer belongs to.
064: * @param waitForCompletionPolicy how many backends must complete before
065: * returning the result?
066: * @param createTablePolicy the policy defining how 'create table' statements
067: * should be handled
068: * @param errorCheckingPolicy policy to apply for error checking.
069: * @param nbOfConcurrentReads number of concurrent reads allowed
070: * @exception Exception if an error occurs
071: */
072: public RAIDb2ec(VirtualDatabase vdb,
073: WaitForCompletionPolicy waitForCompletionPolicy,
074: CreateTablePolicy createTablePolicy,
075: ErrorCheckingPolicy errorCheckingPolicy,
076: int nbOfConcurrentReads) throws Exception {
077: super (vdb, waitForCompletionPolicy, createTablePolicy);
078: backendReadThreads = new ArrayList();
079: this .errorCheckingPolicy = errorCheckingPolicy;
080: this .nbOfConcurrentReads = nbOfConcurrentReads;
081: }
082:
083: /*
084: * Backends management
085: */
086:
087: /**
088: * @see org.continuent.sequoia.controller.loadbalancer.AbstractLoadBalancer#getXmlImpl
089: */
090: public String getXmlImpl() {
091: StringBuffer info = new StringBuffer();
092: info.append("<" + DatabasesXmlTags.ELT_RAIDb_2ec + " "
093: + DatabasesXmlTags.ATT_nbOfConcurrentReads + "=\""
094: + this .nbOfConcurrentReads + "\">");
095: this .getRaidb2Xml();
096: if (waitForCompletionPolicy != null)
097: info.append(waitForCompletionPolicy.getXml());
098: info.append("</" + DatabasesXmlTags.ELT_RAIDb_2ec + ">");
099: return info.toString();
100: }
101: }
|