org.jboss.ha.singleton
public class: PreferredMasterElectionPolicy [javadoc |
source]
java.lang.Object
org.jboss.ha.singleton.HASingletonElectionPolicySimple
org.jboss.ha.singleton.PreferredMasterElectionPolicy
All Implemented Interfaces:
PreferredMasterElectionPolicyMBean, HASingletonElectionPolicy, HASingletonElectionPolicySimpleMBean
Election policy that chooses the node where the singleton should run based on
the given preferred master node in ip_address:port_number or
host_name:port_number format. If the preferred master is null, or its
ip_address does not resolve to a valid host name, or the port number is
invalid, it delegates to the standard policy.
| Methods from java.lang.Object: |
|---|
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from org.jboss.ha.singleton.PreferredMasterElectionPolicy Detail: |
public ClusterNode elect(List<ClusterNode> candidates) {
InetSocketAddress sockAddress = this.preferredMaster;
ClusterNode master = null;
// If preferred master is defined and contained in cluster, return it
if (sockAddress != null)
{
InetAddress address = sockAddress.getAddress();
int port = sockAddress.getPort();
// First find by address
master = this.find(candidates, address.getHostAddress(), port);
if (master == null)
{
// Then try by hostname
master = this.find(candidates, address.getHostName(), port);
}
}
return (master != null) ? master : super.elect(candidates);
}
|
public String getPreferredMaster() {
InetSocketAddress address = this.preferredMaster;
return (address != null) ? address.toString() : null;
}
|
public void setPreferredMaster(String value) {
String node = (value != null) ? value.trim() : "";
if (node.length() > 0)
{
try
{
URI uri = new URI("cluster://" + node);
String host = uri.getHost();
if (host == null)
{
throw new IllegalArgumentException("Cannot extract host/address from " + node);
}
this.preferredMaster = new InetSocketAddress(InetAddress.getByName(host), uri.getPort());
}
catch (URISyntaxException e)
{
throw new IllegalArgumentException("Cannot extract URI from " + node, e);
}
catch (UnknownHostException e)
{
throw new IllegalArgumentException("Cannot resolve host from " + node, e);
}
}
else
{
this.preferredMaster = null;
}
}
|