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

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

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

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

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

Detailed Description

Chooses the number of nodes nodes for error checking using a round-robin algorithm.

Author:
Emmanuel Cecchet
Version:
1.0

Definition at line 38 of file ErrorCheckingRoundRobin.java.


Constructor & Destructor Documentation

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

Creates a new ErrorCheckingRoundRobin instance.

Parameters:
numberOfNodes number of nodes

Definition at line 48 of file ErrorCheckingRoundRobin.java.

00049   {
00050     super(ErrorCheckingPolicy.ROUND_ROBIN, numberOfNodes);
00051   }


Member Function Documentation

ArrayList org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingRoundRobin.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 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   }

String org.objectweb.cjdbc.controller.loadbalancer.policies.errorchecking.ErrorCheckingRoundRobin.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 102 of file ErrorCheckingRoundRobin.java.

00103   {
00104     return "Error checking using "
00105       + nbOfNodes
00106       + " nodes choosen using a round-robin algorithm";
00107   }


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