Public Member Functions | |
ErrorCheckingRoundRobin (int numberOfNodes) | |
ArrayList | getBackends (ArrayList backends) throws ErrorCheckingException |
String | getInformation () |
Definition at line 38 of file ErrorCheckingRoundRobin.java.
|
Creates a new
Definition at line 48 of file ErrorCheckingRoundRobin.java. 00049 { 00050 super(ErrorCheckingPolicy.ROUND_ROBIN, numberOfNodes); 00051 }
|
|
Implements org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingPolicy. Definition at line 56 of file ErrorCheckingRoundRobin.java. References org.objectweb.cjdbc.controller.backend.DatabaseBackend.isReadEnabled(), and org.objectweb.cjdbc.controller.backend.DatabaseBackend.isWriteEnabled(). 00058 { 00059 int size = backends.size(); 00060 00061 if (nbOfNodes == 0) 00062 return null; 00063 else if (nbOfNodes == size) 00064 return backends; 00065 00066 ArrayList result = new ArrayList(nbOfNodes); 00067 ArrayList clonedList = new ArrayList(size); 00068 for (int i = 0; i < size; i++) 00069 { // Take all enabled backends 00070 DatabaseBackend db = (DatabaseBackend) backends.get(i); 00071 if (db.isReadEnabled() || db.isWriteEnabled()) 00072 clonedList.add(db); 00073 } 00074 00075 int clonedSize = clonedList.size(); 00076 00077 if (nbOfNodes == clonedSize) 00078 return backends; 00079 else if (nbOfNodes > clonedSize) 00080 throw new ErrorCheckingException( 00081 "Asking for more backends (" 00082 + nbOfNodes 00083 + ") than available (" 00084 + clonedSize 00085 + ")"); 00086 00087 synchronized (this) 00088 { // index must be modified in mutual exclusion 00089 for (int i = 0; i < nbOfNodes; i++) 00090 { 00091 index = (index + 1) % clonedSize; 00092 result.add(clonedList.remove(index)); 00093 } 00094 } 00095 00096 return result; 00097 }
|
|
Implements org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingPolicy. Definition at line 102 of file ErrorCheckingRoundRobin.java. 00103 { 00104 return "Error checking using " 00105 + nbOfNodes 00106 + " nodes choosen using a round-robin algorithm"; 00107 }
|