1 23 24 package org.objectweb.cjdbc.driver.connectpolicy; 25 26 import java.util.ArrayList ; 27 28 import org.objectweb.cjdbc.common.exceptions.NoMoreControllerException; 29 import org.objectweb.cjdbc.driver.CjdbcUrl; 30 import org.objectweb.cjdbc.driver.ControllerInfo; 31 32 45 public class OrderedConnectPolicy extends AbstractControllerConnectPolicy 46 { 47 private ArrayList availableControllerList; 48 49 58 public OrderedConnectPolicy(ControllerInfo[] controllerList, 59 long retryIntervalInMs, int debugLevel) 60 { 61 super(controllerList, retryIntervalInMs, debugLevel); 62 availableControllerList = new ArrayList (controllerList.length); 64 for (int i = 0; i < controllerList.length; i++) 65 availableControllerList.add(controllerList[i]); 66 } 67 68 71 public synchronized void removeControllerFromSuspectList( 72 ControllerInfo controller) 73 { 74 super.removeControllerFromSuspectList(controller); 75 availableControllerList.clear(); 77 for (int i = 0; i < controllerList.length; i++) 78 if (!isSuspectedOfFailure(controllerList[i])) 79 availableControllerList.add(controllerList[i]); 80 } 81 82 85 public synchronized void suspectControllerOfFailure( 86 ControllerInfo controllerInfo) 87 { 88 super.suspectControllerOfFailure(controllerInfo); 89 availableControllerList.remove(controllerInfo); 90 } 91 92 95 public synchronized ControllerInfo getController() 96 throws NoMoreControllerException 97 { 98 int size = availableControllerList.size(); 99 if (size == 0) 100 throw new NoMoreControllerException(); 101 102 ControllerInfo controllerInfo = (ControllerInfo) availableControllerList 104 .get(0); 105 if (debugLevel == CjdbcUrl.DEBUG_LEVEL_DEBUG) 106 System.out.println("Selected controller " + controllerInfo); 107 return controllerInfo; 108 } 109 110 } 111 | Popular Tags |