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

java.lang.Object
  extended by org.ow2.cmi.lb.policy.AbstractPolicy<T>
      extended by org.ow2.cmi.lb.policy.HASingleton<T>
Type Parameters:
T - The type of objects that was load-balanced
All Implemented Interfaces:
org.ow2.cmi.lb.policy.IPolicy<T>

@ThreadSafe
public class HASingleton<T extends org.ow2.cmi.lb.LoadBalanceable>
extends AbstractPolicy<T>

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

Author:
The new CMI team

Constructor Summary
HASingleton()
          Construct a new instance of policy ha-singleton with the policy first available as rescue.
 
Method Summary
 T choose(java.util.Collection<T> cmiReferences)
          Always choose the same server (called singleton) on any client.
 java.lang.String getSingleton()
           
 java.util.List<java.lang.String> getSingletons()
          Return the order to elect a singleton in the cluster.
 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.cmi.lb.strategy.IStrategy<T> strategy)
          Sets a strategy to modify the behavior of the rescue policy.
 java.lang.String toString()
           
 
Methods inherited from class org.ow2.cmi.lb.policy.AbstractPolicy
getStrategy, onChoose, onInvokeException, onLookupException, onReturn, setClusterViewManager
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HASingleton

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

Method Detail

choose

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

Specified by:
choose in interface org.ow2.cmi.lb.policy.IPolicy<T extends org.ow2.cmi.lb.LoadBalanceable>
Specified by:
choose in class AbstractPolicy<T extends org.ow2.cmi.lb.LoadBalanceable>
Parameters:
cmiReferences - a list of references
Returns:
the singleton
Throws:
org.ow2.cmi.lb.NoLoadBalanceableException - if no server available

setStrategy

public void setStrategy(org.ow2.cmi.lb.strategy.IStrategy<T> strategy)
Sets a strategy to modify the behavior of the rescue policy. It will be used only if no singleton is declared.

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

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()
Returns:
the reference on server that is at the first position

toString

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


Copyright © 2009 OW2 Consortium. All Rights Reserved.