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

java.lang.Object
  extended by org.ow2.cmi.lb.policy.AbstractPolicy<T>
Type Parameters:
T - The type of objects that are load-balanced
All Implemented Interfaces:
org.ow2.cmi.lb.policy.IPolicy<T>
Direct Known Subclasses:
FirstAvailable, HASingleton, Random, RoundRobin

public abstract class AbstractPolicy<T extends org.ow2.cmi.lb.LoadBalanceable>
extends java.lang.Object
implements org.ow2.cmi.lb.policy.IPolicy<T>

Abstract implementation of a IPolicy, using the class DecisionUtil to take a decision and the class BasicDecisionManager to execute the decision.

Author:
Loris Bouzonnet
See Also:
DecisionUtil, BasicDecisionManager

Constructor Summary
AbstractPolicy()
          Default constructor.
AbstractPolicy(org.ow2.cmi.controller.common.ClusterViewManager clusterViewManager)
           
 
Method Summary
abstract  T choose(java.util.Collection<T> loadBalanceables)
          Chooses a load-balanceable among the list of load-balanceables.
 org.ow2.cmi.lb.strategy.IStrategy<T> getStrategy()
          Return a strategy to modify the behavior of this policy.
<ReturnType>
org.ow2.cmi.lb.decision.DecisionManager<ReturnType>
onChoose(java.lang.reflect.Method method, java.lang.Object[] parameters, ReturnType chosenValue)
          Return a decision when a server is chosen and its delegate retrieved.
 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 setClusterViewManager(org.ow2.cmi.controller.common.ClusterViewManager clusterViewManager)
          Set the manager of the cluster view.
 void setStrategy(org.ow2.cmi.lb.strategy.IStrategy<T> strategy)
          Sets a strategy to modify the behavior of this policy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractPolicy

public AbstractPolicy()
Default constructor.


AbstractPolicy

public AbstractPolicy(org.ow2.cmi.controller.common.ClusterViewManager clusterViewManager)
Parameters:
clusterViewManager - the manager of the cluster view
Method Detail

choose

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

Specified by:
choose in interface org.ow2.cmi.lb.policy.IPolicy<T extends org.ow2.cmi.lb.LoadBalanceable>
Parameters:
loadBalanceables - a list of load-balanceables
Returns:
the chosen load-balanceable
Throws:
org.ow2.cmi.lb.NoLoadBalanceableException - if no server is 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.cmi.lb.policy.IPolicy<T extends org.ow2.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

onChoose

public <ReturnType> org.ow2.cmi.lb.decision.DecisionManager<ReturnType> onChoose(java.lang.reflect.Method method,
                                                                                 java.lang.Object[] parameters,
                                                                                 ReturnType chosenValue)
Return a decision when a server is chosen and its delegate retrieved.

Specified by:
onChoose in interface org.ow2.cmi.lb.policy.IPolicy<T extends org.ow2.cmi.lb.LoadBalanceable>
Type Parameters:
ReturnType - the type of delegate
Parameters:
method - the method that was invoked
parameters - the parameters of the method
chosenValue - the delegate of chosen server
Returns:
the decision when the server is chosen and its delegate retrieved

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.cmi.lb.policy.IPolicy<T extends org.ow2.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.cmi.lb.policy.IPolicy<T extends org.ow2.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.cmi.lb.strategy.IStrategy<T> strategy)
Sets a strategy to modify the behavior of this policy.

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

getStrategy

public org.ow2.cmi.lb.strategy.IStrategy<T> getStrategy()
Return a strategy to modify the behavior of this policy.

Specified by:
getStrategy in interface org.ow2.cmi.lb.policy.IPolicy<T extends org.ow2.cmi.lb.LoadBalanceable>
Returns:
a strategy to modify the behavior of this policy

setClusterViewManager

public void setClusterViewManager(org.ow2.cmi.controller.common.ClusterViewManager clusterViewManager)
Set the manager of the cluster view.

Parameters:
clusterViewManager - the manager of the cluster view


Copyright © 2009 OW2 Consortium. All Rights Reserved.