KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > driver > connectpolicy > SingleConnectPolicy


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2005 Emic Networks.
4  * Contact: c-jdbc@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or any later
9  * version.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19  *
20  * Initial developer(s): Emmanuel Cecchet.
21  * Contributor(s): ______________________.
22  */

23
24 package org.objectweb.cjdbc.driver.connectpolicy;
25
26 import org.objectweb.cjdbc.common.exceptions.NoMoreControllerException;
27 import org.objectweb.cjdbc.driver.ControllerInfo;
28 import org.objectweb.cjdbc.driver.Driver;
29
30 /**
31  * This class defines a SingleConnectPolicy used when a C-JDBC URL only contains
32  * one controller.
33  *
34  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
35  * </a>
36  * @version 1.0
37  */

38 public class SingleConnectPolicy extends AbstractControllerConnectPolicy
39 {
40
41   /**
42    * Creates a new <code>SingleConnectPolicy</code> object
43    *
44    * @param controllerList list of controller from C-JDBC url
45    * @param debugLevel the debug level to use
46    * @see org.objectweb.cjdbc.driver.CjdbcUrl#DEBUG_LEVEL_OFF
47    */

48   public SingleConnectPolicy(ControllerInfo[] controllerList, int debugLevel)
49   {
50     super(controllerList, Driver.DEFAULT_RETRY_INTERVAL_IN_MS, debugLevel);
51     if (controllerList.length != 1)
52       throw new RuntimeException JavaDoc("Invalid number of controllers ("
53           + controllerList.length + ") in URL for SingleConnectPolicy");
54   }
55
56   /**
57    * @see org.objectweb.cjdbc.driver.connectpolicy.AbstractControllerConnectPolicy#getController()
58    */

59   public ControllerInfo getController() throws NoMoreControllerException
60   {
61     if (suspectedControllers.size() == 1)
62       throw new NoMoreControllerException();
63     return controllerList[0];
64   }
65
66 }
67
Popular Tags