1 23 24 package org.objectweb.cjdbc.driver.connectpolicy; 25 26 import org.objectweb.cjdbc.common.exceptions.NoMoreControllerException; 27 import org.objectweb.cjdbc.driver.CjdbcUrl; 28 import org.objectweb.cjdbc.driver.ControllerInfo; 29 30 41 public class RoundRobinConnectPolicy extends AbstractControllerConnectPolicy 42 { 43 private int index = -1; 44 45 54 public RoundRobinConnectPolicy(ControllerInfo[] controllerList, 55 long retryIntervalInMs, int debugLevel) 56 { 57 super(controllerList, retryIntervalInMs, debugLevel); 58 } 59 60 63 public ControllerInfo getController() throws NoMoreControllerException 64 { 65 synchronized (suspectedControllers) 66 { 67 if (suspectedControllers.size() == controllerList.length) 68 throw new NoMoreControllerException(); 69 do 70 { 71 index = (index + 1) % controllerList.length; 72 } 73 while (suspectedControllers.contains(controllerList[index])); 74 } 75 if (debugLevel == CjdbcUrl.DEBUG_LEVEL_DEBUG) 76 System.out.println("Selected controller[" + index + "]:" 77 + controllerList[index]); 78 return controllerList[index]; 79 } 80 81 } 82 | Popular Tags |