no need for specific time / empty based classes, just as final fields

This commit is contained in:
Shay Banon 2013-03-12 12:32:05 -07:00
parent 3a534c64e5
commit 877105ee19
3 changed files with 9 additions and 21 deletions

View File

@ -56,14 +56,14 @@ public class DynamicSettings {
} }
public synchronized void addDynamicSetting(String setting) { public synchronized void addDynamicSetting(String setting) {
addDynamicSetting(setting, Validator.EmptyValidator.INSTANCE); addDynamicSetting(setting, Validator.EMPTY);
} }
public synchronized void addDynamicSettings(String... settings) { public synchronized void addDynamicSettings(String... settings) {
MapBuilder<String, Validator> updatedSettings = MapBuilder.newMapBuilder(dynamicSettings); MapBuilder<String, Validator> updatedSettings = MapBuilder.newMapBuilder(dynamicSettings);
for (String setting : settings) { for (String setting : settings) {
updatedSettings.put(setting, Validator.EmptyValidator.INSTANCE); updatedSettings.put(setting, Validator.EMPTY);
} }
dynamicSettings = updatedSettings.immutableMap(); dynamicSettings = updatedSettings.immutableMap();
} }

View File

@ -23,32 +23,20 @@ import org.elasticsearch.ElasticSearchParseException;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
/** /**
* Validates a setting, returning a failure message if applicable.
*/ */
public interface Validator { public interface Validator {
String validate(String setting, String value); String validate(String setting, String value);
public static class EmptyValidator implements Validator { public static final Validator EMPTY = new Validator() {
public static final EmptyValidator INSTANCE = new EmptyValidator();
private EmptyValidator() {
}
@Override @Override
public String validate(String setting, String value) { public String validate(String setting, String value) {
return null; return null;
} }
} };
public static class TimeValueValidator implements Validator {
public static final TimeValueValidator INSTANCE = new TimeValueValidator();
private TimeValueValidator() {
}
public static final Validator TIME = new Validator() {
@Override @Override
public String validate(String setting, String value) { public String validate(String setting, String value) {
try { try {
@ -60,5 +48,5 @@ public interface Validator {
} }
return null; return null;
} }
} };
} }

View File

@ -63,7 +63,7 @@ public class IndexDynamicSettingsModule extends AbstractModule {
indexDynamicSettings.addDynamicSetting(IndexMetaData.SETTING_BLOCKS_METADATA); indexDynamicSettings.addDynamicSetting(IndexMetaData.SETTING_BLOCKS_METADATA);
indexDynamicSettings.addDynamicSetting(IndexShardGatewayService.INDEX_GATEWAY_SNAPSHOT_INTERVAL); indexDynamicSettings.addDynamicSetting(IndexShardGatewayService.INDEX_GATEWAY_SNAPSHOT_INTERVAL);
indexDynamicSettings.addDynamicSetting(IndicesTTLService.INDEX_TTL_DISABLE_PURGE); indexDynamicSettings.addDynamicSetting(IndicesTTLService.INDEX_TTL_DISABLE_PURGE);
indexDynamicSettings.addDynamicSetting(InternalIndexShard.INDEX_REFRESH_INTERVAL, Validator.TimeValueValidator.INSTANCE); indexDynamicSettings.addDynamicSetting(InternalIndexShard.INDEX_REFRESH_INTERVAL, Validator.TIME);
indexDynamicSettings.addDynamicSetting(LocalGatewayAllocator.INDEX_RECOVERY_INITIAL_SHARDS); indexDynamicSettings.addDynamicSetting(LocalGatewayAllocator.INDEX_RECOVERY_INITIAL_SHARDS);
indexDynamicSettings.addDynamicSetting(LogByteSizeMergePolicyProvider.INDEX_MERGE_POLICY_MIN_MERGE_SIZE); indexDynamicSettings.addDynamicSetting(LogByteSizeMergePolicyProvider.INDEX_MERGE_POLICY_MIN_MERGE_SIZE);
indexDynamicSettings.addDynamicSetting(LogByteSizeMergePolicyProvider.INDEX_MERGE_POLICY_MAX_MERGE_SIZE); indexDynamicSettings.addDynamicSetting(LogByteSizeMergePolicyProvider.INDEX_MERGE_POLICY_MAX_MERGE_SIZE);