01: /**
02: * Sequoia: Database clustering technology.
03: * Copyright (C) 2005 Emic Networks.
04: * Contact: sequoia@continuent.org
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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: */package org.continuent.sequoia.driver.connectpolicy;
21:
22: import org.continuent.sequoia.common.exceptions.NoMoreControllerException;
23: import org.continuent.sequoia.driver.ControllerInfo;
24: import org.continuent.sequoia.driver.SequoiaUrl;
25:
26: /**
27: * This class defines an OrderedConnectPolicy used when the Sequoia URL has the
28: * following form:
29: * jdbc:sequoia://node1,node2,node3/myDB?preferredController=ordered
30: * <p>
31: * This always direct to the first available controller in the list following
32: * the order of the list. With this example, we first try node1, and if not
33: * available then try to node2 and finally if none are available try node3.
34: *
35: * @author <a href="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
36: * </a>
37: * @version 1.0
38: */
39: public class OrderedConnectPolicy extends
40: AbstractControllerConnectPolicy {
41:
42: /**
43: * Creates a new <code>OrderedConnectPolicy</code> object
44: *
45: * @param controllerList the controller list on which the policy applies
46: * @param pingDelayInMs Interval in milliseconds between two pings of a
47: * controller
48: * @param controllerTimeoutInMs timeout in milliseconds after which a
49: * controller is considered as dead if it did not respond to pings
50: * @param debugLevel the debug level to use
51: * @see org.continuent.sequoia.driver.SequoiaUrl#DEBUG_LEVEL_OFF
52: */
53: public OrderedConnectPolicy(ControllerInfo[] controllerList,
54: int pingDelayInMs, int controllerTimeoutInMs, int debugLevel) {
55: super (controllerList, pingDelayInMs, controllerTimeoutInMs,
56: debugLevel);
57: }
58:
59: /**
60: * @see org.continuent.sequoia.driver.connectpolicy.AbstractControllerConnectPolicy#getController()
61: */
62: public synchronized ControllerInfo getController()
63: throws NoMoreControllerException {
64: ControllerInfo selectedController = super .getControllerByNum(0);
65: if (debugLevel >= SequoiaUrl.DEBUG_LEVEL_DEBUG)
66: System.out.println("Selected controller "
67: + selectedController);
68: return selectedController;
69: }
70: }
|