Public Member Functions | |
ErrorCheckingRandom (int numberOfNodes) | |
ArrayList | getBackends (ArrayList backends) throws ErrorCheckingException |
String | getInformation () |
Definition at line 38 of file ErrorCheckingRandom.java.
|
Creates a new
Definition at line 47 of file ErrorCheckingRandom.java. 00048 { 00049 super(ErrorCheckingPolicy.RANDOM, numberOfNodes); 00050 }
|
|
Implements org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingPolicy. Definition at line 55 of file ErrorCheckingRandom.java. References org.objectweb.cjdbc.controller.backend.DatabaseBackend.isReadEnabled(), and org.objectweb.cjdbc.controller.backend.DatabaseBackend.isWriteEnabled(). 00057 { 00058 int size = backends.size(); 00059 00060 if (nbOfNodes == size) 00061 return backends; 00062 else if (nbOfNodes > size) 00063 throw new ErrorCheckingException( 00064 "Asking for more backends (" 00065 + nbOfNodes 00066 + ") than available (" 00067 + size 00068 + ")"); 00069 00070 ArrayList result = new ArrayList(nbOfNodes); 00071 ArrayList clonedList = new ArrayList(size); 00072 for (int i = 0; i < size; i++) 00073 { // Take all enabled backends 00074 DatabaseBackend db = (DatabaseBackend) backends.get(i); 00075 if (db.isReadEnabled() || db.isWriteEnabled()) 00076 clonedList.add(db); 00077 } 00078 00079 int clonedSize = clonedList.size(); 00080 00081 if (nbOfNodes == clonedSize) 00082 return backends; 00083 else if (nbOfNodes > clonedSize) 00084 throw new ErrorCheckingException( 00085 "Asking for more backends (" 00086 + nbOfNodes 00087 + ") than available (" 00088 + clonedSize 00089 + ")"); 00090 00091 // Pickup the nodes randomly 00092 for (int i = 0; i < nbOfNodes; i++) 00093 result.add(clonedList.remove(random.nextInt(clonedSize))); 00094 00095 return result; 00096 }
|
|
Implements org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingPolicy. Definition at line 101 of file ErrorCheckingRandom.java. 00102 { 00103 return "Error checking using " + nbOfNodes + " nodes choosen randomly"; 00104 }
|