org.apache.cassandra.locator
Class DatacenterEndPointSnitch

java.lang.Object
  extended by org.apache.cassandra.locator.DatacenterEndPointSnitch
All Implemented Interfaces:
IEndPointSnitch

public class DatacenterEndPointSnitch
extends java.lang.Object
implements IEndPointSnitch

DataCenterEndPointSnitch

This class basically reads the configuration and sets the IP Ranges to a hashMap which can be read later. this class also provides a way to compare 2 EndPoints and also get details from the same.


Constructor Summary
DatacenterEndPointSnitch()
          Constructor, intialize XML config and read the config in...
 
Method Summary
 java.lang.String getLocation(java.net.InetAddress endpoint)
          Given endpoints this method will help us know the datacenter name where the node is located at.
 java.util.HashMap<java.lang.String,java.lang.Integer> getMapQuorumFactor()
          Returns a DC replication map, the key will be the dc name and the value will be the replication factor of that Datacenter.
 java.util.HashMap<java.lang.String,java.lang.Integer> getMapReplicationFactor()
          Returns a DC replication map, the key will be the dc name and the value will be the replication factor of that Datacenter.
 java.lang.String getRackForEndPoint(java.net.InetAddress endPoint)
          Return the rack for which an endpoint resides in
static byte intToByte(int n)
           
 boolean isInSameDataCenter(java.net.InetAddress host, java.net.InetAddress host2)
          This methood will return ture if the hosts are in the same DC else false.
 boolean isOnSameRack(java.net.InetAddress host, java.net.InetAddress host2)
          This methood will return ture if the hosts are in the same RAC else false.
 void reloadConfiguration()
          This method will load the configuration from the xml file.
 java.util.List<java.net.InetAddress> sortByProximity(java.net.InetAddress address, java.util.Collection<java.net.InetAddress> unsortedAddress)
          This method will sort the Set according to the proximity of the given address.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatacenterEndPointSnitch

public DatacenterEndPointSnitch()
                         throws java.io.IOException,
                                javax.xml.parsers.ParserConfigurationException,
                                org.xml.sax.SAXException
Constructor, intialize XML config and read the config in...

Throws:
java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
Method Detail

getRackForEndPoint

public java.lang.String getRackForEndPoint(java.net.InetAddress endPoint)
                                    throws java.net.UnknownHostException
Return the rack for which an endpoint resides in

Throws:
java.net.UnknownHostException

reloadConfiguration

public void reloadConfiguration()
                         throws java.io.IOException
This method will load the configuration from the xml file. Mandatory fields are Atleast 1 DC and 1RAC configurations. Name of the DC/RAC, IP Quadrents for RAC and DC.

This method will not be called everytime

Throws:
java.io.IOException

isOnSameRack

public boolean isOnSameRack(java.net.InetAddress host,
                            java.net.InetAddress host2)
                     throws java.net.UnknownHostException
This methood will return ture if the hosts are in the same RAC else false.

Specified by:
isOnSameRack in interface IEndPointSnitch
Parameters:
host - a specified endpoint
host2 - another specified endpoint
Returns:
true if on the same rack false otherwise
Throws:
java.net.UnknownHostException

isInSameDataCenter

public boolean isInSameDataCenter(java.net.InetAddress host,
                                  java.net.InetAddress host2)
                           throws java.net.UnknownHostException
This methood will return ture if the hosts are in the same DC else false.

Specified by:
isInSameDataCenter in interface IEndPointSnitch
Parameters:
host - a specified endpoint
host2 - another specified endpoint
Returns:
true if in the same data center false otherwise
Throws:
java.net.UnknownHostException

getMapReplicationFactor

public java.util.HashMap<java.lang.String,java.lang.Integer> getMapReplicationFactor()
Returns a DC replication map, the key will be the dc name and the value will be the replication factor of that Datacenter.


getMapQuorumFactor

public java.util.HashMap<java.lang.String,java.lang.Integer> getMapQuorumFactor()
Returns a DC replication map, the key will be the dc name and the value will be the replication factor of that Datacenter.


intToByte

public static byte intToByte(int n)

getLocation

public java.lang.String getLocation(java.net.InetAddress endpoint)
                             throws java.net.UnknownHostException
Description copied from interface: IEndPointSnitch
Given endpoints this method will help us know the datacenter name where the node is located at.

Specified by:
getLocation in interface IEndPointSnitch
Throws:
java.net.UnknownHostException

sortByProximity

public java.util.List<java.net.InetAddress> sortByProximity(java.net.InetAddress address,
                                                            java.util.Collection<java.net.InetAddress> unsortedAddress)
Description copied from interface: IEndPointSnitch
This method will sort the Set according to the proximity of the given address.

Specified by:
sortByProximity in interface IEndPointSnitch


Copyright © 2009 The Apache Software Foundation