KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > driver > connectpolicy > SingleConnectPolicy


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2005 Emic Networks.
4  * Contact: sequoia@continuent.org
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Initial developer(s): Emmanuel Cecchet.
19  * Contributor(s): ______________________.
20  */

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

36 public class SingleConnectPolicy extends AbstractControllerConnectPolicy
37 {
38
39   /**
40    * Creates a new <code>SingleConnectPolicy</code> object
41    *
42    * @param controllerList list of controller from Sequoia url
43    * @param debugLevel the debug level to use
44    * @see org.continuent.sequoia.driver.SequoiaUrl#DEBUG_LEVEL_OFF
45    */

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

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