Java Code Examples for org.apache.cassandra.config.DatabaseDescriptor#setDynamicBadnessThreshold()

The following examples show how to use org.apache.cassandra.config.DatabaseDescriptor#setDynamicBadnessThreshold() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StorageService.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void updateSnitch(String epSnitchClassName, Boolean dynamic, Integer dynamicUpdateInterval, Integer dynamicResetInterval, Double dynamicBadnessThreshold) throws ClassNotFoundException
{
    IEndpointSnitch oldSnitch = DatabaseDescriptor.getEndpointSnitch();

    // new snitch registers mbean during construction
    IEndpointSnitch newSnitch;
    try
    {
        newSnitch = FBUtilities.construct(epSnitchClassName, "snitch");
    }
    catch (ConfigurationException e)
    {
        throw new ClassNotFoundException(e.getMessage());
    }
    if (dynamic)
    {
        DatabaseDescriptor.setDynamicUpdateInterval(dynamicUpdateInterval);
        DatabaseDescriptor.setDynamicResetInterval(dynamicResetInterval);
        DatabaseDescriptor.setDynamicBadnessThreshold(dynamicBadnessThreshold);
        newSnitch = new DynamicEndpointSnitch(newSnitch);
    }

    // point snitch references to the new instance
    DatabaseDescriptor.setEndpointSnitch(newSnitch);
    for (String ks : Schema.instance.getKeyspaces())
    {
        Keyspace.open(ks).getReplicationStrategy().snitch = newSnitch;
    }

    if (oldSnitch instanceof DynamicEndpointSnitch)
        ((DynamicEndpointSnitch)oldSnitch).unregisterMBean();
}