org.ow2.carol.cmi.lb.policy
Class HASingletonPolicy

java.lang.Object
  extended by org.ow2.carol.cmi.lb.policy.HASingletonPolicy
All Implemented Interfaces:
java.io.Serializable, org.ow2.carol.cmi.lb.policy.ILBPolicy<org.ow2.carol.cmi.reference.CMIReference>

@ThreadSafe
public class HASingletonPolicy
extends java.lang.Object
implements org.ow2.carol.cmi.lb.policy.ILBPolicy<org.ow2.carol.cmi.reference.CMIReference>

Implementation of a policy of load-balancing that always favors one server in the cluster.

Author:
The new CMI team
See Also:
Serialized Form

Constructor Summary
HASingletonPolicy()
          Construct a new instance of policy ha-singleton with the policy first available as rescue.
 
Method Summary
 org.ow2.carol.cmi.reference.CMIReference choose(java.util.List<org.ow2.carol.cmi.reference.CMIReference> cmiReferences)
          Always choose the same server (called singleton) on any client.
 java.lang.String getPolicyClassname()
           
 java.lang.String getSingleton()
           
 java.util.List<java.lang.String> getSingletons()
          Return the order to elect a singleton in the cluster.
 org.ow2.carol.cmi.lb.strategy.ILBStrategy<org.ow2.carol.cmi.reference.CMIReference> getStrategy()
           
 org.ow2.carol.cmi.lb.decision.DecisionManager<java.lang.Void> onInvokeException(java.lang.reflect.Method method, java.lang.Object[] parameters, org.ow2.carol.cmi.reference.CMIReference cmiReference, java.lang.Throwable thr)
          Returns a decision when an exception is thrown during an invocation for a given reference.
 org.ow2.carol.cmi.lb.decision.DecisionManager<java.lang.Void> onLookupException(org.ow2.carol.cmi.reference.CMIReference cmiReference, java.lang.Throwable thr)
          Returns a decision when an exception is thrown during an access to a registry for a given reference.
<ReturnType>
org.ow2.carol.cmi.lb.decision.DecisionManager<ReturnType>
onReturn(java.lang.reflect.Method method, java.lang.Object[] parameters, org.ow2.carol.cmi.reference.CMIReference cmiReference, ReturnType retVal)
          Returns a decision when the invocation of a remote method ends.
 void setPolicyClassname(java.lang.String lbPolicyClassname)
           
 void setSingleton(java.lang.String serverRef)
          Add a server in the list of singleton at the first position (it will be the new master).
 void setSingletons(java.util.List<java.lang.String> serverRefs)
          Set the order to elect a singleton in the cluster.
 void setStrategy(org.ow2.carol.cmi.lb.strategy.ILBStrategy<org.ow2.carol.cmi.reference.CMIReference> 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

HASingletonPolicy

public HASingletonPolicy()
Construct a new instance of policy ha-singleton with the policy first available as rescue.

Method Detail

choose

public org.ow2.carol.cmi.reference.CMIReference choose(java.util.List<org.ow2.carol.cmi.reference.CMIReference> cmiReferences)
                                                throws org.ow2.carol.cmi.lb.NoLoadBalanceableException
Always choose the same server (called singleton) on any client.

Specified by:
choose in interface org.ow2.carol.cmi.lb.policy.ILBPolicy<org.ow2.carol.cmi.reference.CMIReference>
Parameters:
cmiReferences - a list of references
Returns:
the singleton
Throws:
org.ow2.carol.cmi.lb.NoLoadBalanceableException - if no server available

onInvokeException

public org.ow2.carol.cmi.lb.decision.DecisionManager<java.lang.Void> onInvokeException(java.lang.reflect.Method method,
                                                                                       java.lang.Object[] parameters,
                                                                                       org.ow2.carol.cmi.reference.CMIReference cmiReference,
                                                                                       java.lang.Throwable thr)
Returns a decision when an exception is thrown during an invocation for a given reference. Also, remove the current master.

Specified by:
onInvokeException in interface org.ow2.carol.cmi.lb.policy.ILBPolicy<org.ow2.carol.cmi.reference.CMIReference>
Parameters:
method - the method that was invoked
parameters - the parameters of the method
cmiReference - the reference that has 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

onLookupException

public org.ow2.carol.cmi.lb.decision.DecisionManager<java.lang.Void> onLookupException(org.ow2.carol.cmi.reference.CMIReference cmiReference,
                                                                                       java.lang.Throwable thr)
Returns a decision when an exception is thrown during an access to a registry for a given reference. Also, remove the current master.

Specified by:
onLookupException in interface org.ow2.carol.cmi.lb.policy.ILBPolicy<org.ow2.carol.cmi.reference.CMIReference>
Parameters:
cmiReference - the reference that has 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 reference

onReturn

public <ReturnType> org.ow2.carol.cmi.lb.decision.DecisionManager<ReturnType> onReturn(java.lang.reflect.Method method,
                                                                                       java.lang.Object[] parameters,
                                                                                       org.ow2.carol.cmi.reference.CMIReference cmiReference,
                                                                                       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<org.ow2.carol.cmi.reference.CMIReference>
Type Parameters:
ReturnType - the type of the returned value
Parameters:
method - the method that was invoked
parameters - the parameters of the method
cmiReference - the reference used for the invocation
retVal - the returned value
Returns:
the decision when the invocation of a remote method ends

setStrategy

public void setStrategy(org.ow2.carol.cmi.lb.strategy.ILBStrategy<org.ow2.carol.cmi.reference.CMIReference> lbStrategy)
Sets a strategy to modify the behavior of this policy. It will be used only if no singleton is declared.

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

getStrategy

public org.ow2.carol.cmi.lb.strategy.ILBStrategy<org.ow2.carol.cmi.reference.CMIReference> getStrategy()

setPolicyClassname

public void setPolicyClassname(java.lang.String lbPolicyClassname)
                        throws org.ow2.carol.cmi.lb.NoLoadBalanceableException
Throws:
org.ow2.carol.cmi.lb.NoLoadBalanceableException

getPolicyClassname

public java.lang.String getPolicyClassname()
                                    throws org.ow2.carol.cmi.lb.NoLoadBalanceableException
Throws:
org.ow2.carol.cmi.lb.NoLoadBalanceableException

getSingletons

public java.util.List<java.lang.String> getSingletons()
Return the order to elect a singleton in the cluster. The first element will be the first elected.

Returns:
a list of reference on servers (e.g. {rmi://localhost:9000})

setSingletons

public void setSingletons(java.util.List<java.lang.String> serverRefs)
Set the order to elect a singleton in the cluster. The first element will be the first elected.

Parameters:
serverRefs - a list of reference on servers (e.g. {rmi://localhost:9000})

setSingleton

public void setSingleton(java.lang.String serverRef)
Add a server in the list of singleton at the first position (it will be the new master).

Parameters:
serverRef - a reference on server (e.g. rmi://localhost:9000)

getSingleton

public java.lang.String getSingleton()

toString

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


Copyright © 2007 OW2 Consortium. All Rights Reserved.