Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingRandom Class Reference

Inheritance diagram for org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingRandom:

Inheritance graph
[legend]
Collaboration diagram for org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingRandom:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ErrorCheckingRandom (int numberOfNodes)
ArrayList getBackends (ArrayList backends) throws ErrorCheckingException
String getInformation ()

Detailed Description

Chooses numberOfNodes nodes randomly for error checking.

Author:
Emmanuel Cecchet
Version:
1.0

Definition at line 38 of file ErrorCheckingRandom.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingRandom.ErrorCheckingRandom int  numberOfNodes  ) 
 

Creates a new ErrorCheckingRandom instance.

Parameters:
numberOfNodes number of nodes to use to check for errors on a query

Definition at line 47 of file ErrorCheckingRandom.java.

00048   {
00049     super(ErrorCheckingPolicy.RANDOM, numberOfNodes);
00050   }


Member Function Documentation

ArrayList org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingRandom.getBackends ArrayList  backends  )  throws ErrorCheckingException [virtual]
 

See also:
org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingPolicy.getBackends(ArrayList)

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   }

String org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingRandom.getInformation  )  [virtual]
 

See also:
org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingPolicy.getInformation()

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   }


The documentation for this class was generated from the following file:
Generated on Mon Apr 11 22:03:59 2005 for C-JDBC by  doxygen 1.3.9.1