org.apache.cassandra.locator

## Class NetworkTopologyStrategy

- java.lang.Object
- - org.apache.cassandra.locator.AbstractReplicationStrategy
  - - org.apache.cassandra.locator.NetworkTopologyStrategy

    public class NetworkTopologyStrategy
    extends AbstractReplicationStrategy

This Replication Strategy takes a property file that gives the intended replication factor in each datacenter. The sum total of the datacenter replication factor values should be equal to the keyspace replication factor.

So for example, if the keyspace replication factor is 6, the datacenter replication factors could be 3, 2, and 1 - so 3 replicas in one datacenter, 2 in another, and 1 in another - totalling 6.

This class also caches the Endpoints and invalidates the cache if there is a change in the number of tokens.

### Field Summary

### Fields inherited from class org.apache.cassandra.locator.AbstractReplicationStrategy

`configOptions, snitch`

### Constructor Summary

Constructors
Constructor and Description
`NetworkTopologyStrategy(java.lang.String keyspaceName, TokenMetadata tokenMetadata, IEndpointSnitch snitch, java.util.Map<java.lang.String,java.lang.String> configOptions)`

### Method Summary

All Methods Instance Methods Concrete Methods
`java.util.List<java.net.InetAddress>` `calculateNaturalEndpoints(Token searchToken, TokenMetadata tokenMetadata)` calculate endpoints in one pass through the tokens by tracking our progress in each DC.
`java.util.Set<java.lang.String>` `getDatacenters()`
`int` `getReplicationFactor()` calculate the RF based on strategy_options.
`int` `getReplicationFactor(java.lang.String dc)`
`boolean` `hasSameSettings(AbstractReplicationStrategy other)`
`void` `validateOptions()`

### Methods inherited from class org.apache.cassandra.locator.AbstractReplicationStrategy

`createReplicationStrategy, getAddressRanges, getAddressRanges, getCachedEndpoints, getClass, getNaturalEndpoints, getPendingAddressRanges, getPendingAddressRanges, getRangeAddresses, getWriteResponseHandler, recognizedOptions, validateReplicationFactor, validateReplicationStrategy`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### NetworkTopologyStrategy

    public NetworkTopologyStrategy(java.lang.String keyspaceName,
                                   TokenMetadata tokenMetadata,
                                   IEndpointSnitch snitch,
                                   java.util.Map<java.lang.String,java.lang.String> configOptions)
                            throws ConfigurationException

Throws:
  `ConfigurationException`

### Method Detail

#### calculateNaturalEndpoints

    public java.util.List<java.net.InetAddress> calculateNaturalEndpoints(Token searchToken,
                                                                          TokenMetadata tokenMetadata)

calculate endpoints in one pass through the tokens by tracking our progress in each DC.

Specified by:
  `calculateNaturalEndpoints` in class `AbstractReplicationStrategy`
Parameters:
  `searchToken` - the token the natural endpoints are requested for
Returns:
  a copy of the natural endpoints for the given token
See Also:
  `AbstractReplicationStrategy.getNaturalEndpoints(org.apache.cassandra.dht.RingPosition)`

#### getReplicationFactor

    public int getReplicationFactor()

Description copied from class: `AbstractReplicationStrategy`
calculate the RF based on strategy_options. When overwriting, ensure that this get() is FAST, as this is called often.

Specified by:
  `getReplicationFactor` in class `AbstractReplicationStrategy`
Returns:
  the replication factor

#### getReplicationFactor

    public int getReplicationFactor(java.lang.String dc)

#### getDatacenters

    public java.util.Set<java.lang.String> getDatacenters()

#### validateOptions

    public void validateOptions()
                         throws ConfigurationException

Specified by:
  `validateOptions` in class `AbstractReplicationStrategy`
Throws:
  `ConfigurationException`

#### hasSameSettings

    public boolean hasSameSettings(AbstractReplicationStrategy other)

Overrides:
  `hasSameSettings` in class `AbstractReplicationStrategy`