org.apache.cassandra.locator
Class DatacenterEndPointSnitch

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

public class DatacenterEndPointSnitch
extends AbstractEndpointSnitch

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)
          Determines the name of the datacenter this endpoint lives in.
 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.
 
Methods inherited from class org.apache.cassandra.locator.AbstractEndpointSnitch
getSortedListByProximity, sortByProximity
 
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 class AbstractEndpointSnitch
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 class AbstractEndpointSnitch
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 class: AbstractEndpointSnitch
Determines the name of the datacenter this endpoint lives in.

Specified by:
getLocation in class AbstractEndpointSnitch
Returns:
the name of the datacenter the endpoint lives in
Throws:
java.net.UnknownHostException


Copyright © 2010 The Apache Software Foundation