org.ow2.carol.cmi.lb.policy
Class RoundRobinPolicy<T extends org.ow2.carol.cmi.lb.LoadBalanceable>

java.lang.Object
  extended by org.ow2.carol.cmi.lb.policy.RoundRobinPolicy<T>
Type Parameters:
T - The type of object that was load-balanced
All Implemented Interfaces:
java.io.Serializable, org.ow2.carol.cmi.lb.policy.ILBPolicy<T>

@ThreadSafe
public final class RoundRobinPolicy<T extends org.ow2.carol.cmi.lb.LoadBalanceable>
extends java.lang.Object
implements org.ow2.carol.cmi.lb.policy.ILBPolicy<T>

The default load-balancing policy (Round Robin) that always chooses the next available load-balanceable.

Author:
The new CMI team
See Also:
Serialized Form

Constructor Summary
RoundRobinPolicy()
          Build a default load-balancing policy (the Round Robin policy).
 
Method Summary
 T choose(java.util.List<T> loadBalanceables)
          Chooses the next load-balanceable among the list of load-balanceables.
 BasicDecisionManager<java.lang.Void> onInvokeException(java.lang.reflect.Method method, java.lang.Object[] parameters, T loadBalanceable, java.lang.Throwable thr)
          Returns a decision when an exception is thrown during an invocation for a given load-balanceable.
 BasicDecisionManager<java.lang.Void> onLookupException(T loadBalanceable, java.lang.Throwable thr)
          Returns a decision when an exception is thrown during an access to a registry for a given load-balanceable.
<ReturnType>
BasicDecisionManager<ReturnType>
onReturn(java.lang.reflect.Method method, java.lang.Object[] parameters, T loadBalanceable, ReturnType retVal)
          Returns a decision when the invocation of a remote method ends.
 void setStrategy(org.ow2.carol.cmi.lb.strategy.ILBStrategy<T> lbStrategy)
          Sets a strategy to modify the behavior of this policy.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RoundRobinPolicy

public RoundRobinPolicy()
Build a default load-balancing policy (the Round Robin policy). Give to the pointer an initial value

Method Detail

choose

public T choose(java.util.List<T> loadBalanceables)
                                                      throws org.ow2.carol.cmi.lb.NoLoadBalanceableException
Chooses the next load-balanceable among the list of load-balanceables.

Specified by:
choose in interface org.ow2.carol.cmi.lb.policy.ILBPolicy<T extends org.ow2.carol.cmi.lb.LoadBalanceable>
Parameters:
loadBalanceables - the list of load-balanceables
Returns:
the chosen load-balanceable
Throws:
org.ow2.carol.cmi.lb.NoLoadBalanceableException - if no server available

onInvokeException

public BasicDecisionManager<java.lang.Void> onInvokeException(java.lang.reflect.Method method,
                                                              java.lang.Object[] parameters,
                                                              T loadBalanceable,
                                                              java.lang.Throwable thr)
Returns a decision when an exception is thrown during an invocation for a given load-balanceable.

Specified by:
onInvokeException in interface org.ow2.carol.cmi.lb.policy.ILBPolicy<T extends org.ow2.carol.cmi.lb.LoadBalanceable>
Parameters:
method - the method that was invoked
parameters - the parameters of the method
loadBalanceable - the load-balanceable that have caused the exception
thr - the exception that is thrown
Returns:
the decision when an exception is thrown during an invocation for a given load-balanceable

onReturn

public <ReturnType> BasicDecisionManager<ReturnType> onReturn(java.lang.reflect.Method method,
                                                              java.lang.Object[] parameters,
                                                              T loadBalanceable,
                                                              ReturnType retVal)
Returns a decision when the invocation of a remote method ends.

Specified by:
onReturn in interface org.ow2.carol.cmi.lb.policy.ILBPolicy<T extends org.ow2.carol.cmi.lb.LoadBalanceable>
Type Parameters:
ReturnType - the type of the returned value
Parameters:
method - the method that was invoked
parameters - the parameters of the method
loadBalanceable - the load-balanceable used for the invocation
retVal - the returned value
Returns:
the decision when the invocation of a remote method ends

onLookupException

public BasicDecisionManager<java.lang.Void> onLookupException(T loadBalanceable,
                                                              java.lang.Throwable thr)
Returns a decision when an exception is thrown during an access to a registry for a given load-balanceable.

Specified by:
onLookupException in interface org.ow2.carol.cmi.lb.policy.ILBPolicy<T extends org.ow2.carol.cmi.lb.LoadBalanceable>
Parameters:
loadBalanceable - the load-balanceable that have caused the exception
thr - the exception that is thrown
Returns:
the decision when an exception is thrown during an access to a registry for a given load-balanceable

setStrategy

public void setStrategy(org.ow2.carol.cmi.lb.strategy.ILBStrategy<T> lbStrategy)
Sets a strategy to modify the behavior of this policy.

Specified by:
setStrategy in interface org.ow2.carol.cmi.lb.policy.ILBPolicy<T extends org.ow2.carol.cmi.lb.LoadBalanceable>
Parameters:
lbStrategy - a strategy of load-balancing

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2007 OW2 Consortium. All Rights Reserved.