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

java.lang.Object
  extended by org.ow2.carol.cmi.lb.policy.RandomPolicy<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 RandomPolicy<T extends org.ow2.carol.cmi.lb.LoadBalanceable>
extends java.lang.Object
implements org.ow2.carol.cmi.lb.policy.ILBPolicy<T>

Implementation of a policy of load-balancing that always selects randomly a load-balanceable.

Author:
The new CMI team
See Also:
Serialized Form

Constructor Summary
RandomPolicy()
           
 
Method Summary
 T choose(java.util.List<T> loadBalanceables)
          Chooses randomly a 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

RandomPolicy

public RandomPolicy()
Method Detail

choose

public T choose(java.util.List<T> loadBalanceables)
                                                      throws org.ow2.carol.cmi.lb.NoLoadBalanceableException
Chooses randomly a 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.