simpler settings builder api

This commit is contained in:
kimchy 2010-03-05 12:39:38 +02:00
parent 45489ed1af
commit e735ff49d6
23 changed files with 81 additions and 60 deletions

View File

@ -278,13 +278,13 @@ public class SimpleStoreBenchmark {
store = new MmapFsStore(shardId, settings, environment, localNodeId);
} else if (type.equalsIgnoreCase("memory-direct")) {
Settings byteBufferSettings = settingsBuilder()
.putAll(settings)
.putBoolean("index.store.bytebuffer.direct", true)
.put(settings)
.put("index.store.bytebuffer.direct", true)
.build();
store = new ByteBufferStore(shardId, byteBufferSettings);
} else if (type.equalsIgnoreCase("memory-heap")) {
Settings memorySettings = settingsBuilder()
.putAll(settings)
.put(settings)
.build();
store = new HeapStore(shardId, memorySettings);
} else {

View File

@ -42,13 +42,13 @@ public class SimpleMemoryMonitorBenchmark {
Random random = new Random();
Settings settings = settingsBuilder()
.putTime("cluster.routing.schedule", 200, TimeUnit.MILLISECONDS)
.putInt(SETTING_NUMBER_OF_SHARDS, 5)
.putInt(SETTING_NUMBER_OF_REPLICAS, 1)
.put("cluster.routing.schedule", 200, TimeUnit.MILLISECONDS)
.put(SETTING_NUMBER_OF_SHARDS, 5)
.put(SETTING_NUMBER_OF_REPLICAS, 1)
.build();
Server server1 = serverBuilder().settings(settingsBuilder().putAll(settings).put("name", "server1")).server();
Server server2 = serverBuilder().settings(settingsBuilder().putAll(settings).put("name", "server2")).server();
Server server1 = serverBuilder().settings(settingsBuilder().put(settings).put("name", "server1")).server();
Server server2 = serverBuilder().settings(settingsBuilder().put(settings).put("name", "server2")).server();
Client client1 = server1.client();

View File

@ -68,7 +68,7 @@ public class Bootstrap {
if (tuple.v1().get(JmxService.SettingsConstants.CREATE_CONNECTOR) == null) {
// automatically create the connector if we are bootstrapping
Settings updated = settingsBuilder().putAll(tuple.v1()).putBoolean(JmxService.SettingsConstants.CREATE_CONNECTOR, true).build();
Settings updated = settingsBuilder().put(tuple.v1()).put(JmxService.SettingsConstants.CREATE_CONNECTOR, true).build();
tuple = new Tuple<Settings, Environment>(updated, tuple.v2());
}

View File

@ -74,7 +74,7 @@ import static org.elasticsearch.util.settings.ImmutableSettings.*;
* <p>The transport client important modules used is the {@link org.elasticsearch.transport.TransportModule} which is
* started in client mode (only connects, no bind).
*
* @author kimchy (Shay Banon)
* @author kimchy (shay.banon)
*/
public class TransportClient implements Client {
@ -117,9 +117,9 @@ public class TransportClient implements Client {
*/
public TransportClient(Settings pSettings, boolean loadConfigSettings) throws ElasticSearchException {
Tuple<Settings, Environment> tuple = InternalSettingsPerparer.prepareSettings(pSettings, loadConfigSettings);
this.settings = settingsBuilder().putAll(tuple.v1())
.putBoolean("network.server", false)
.putBoolean("discovery.client", true)
this.settings = settingsBuilder().put(tuple.v1())
.put("network.server", false)
.put("discovery.client", true)
.build();
this.environment = tuple.v2();

View File

@ -120,7 +120,7 @@ public class IndexMetaData {
}
public Builder numberOfShards(int numberOfShards) {
settings = settingsBuilder().putAll(settings).putInt(SETTING_NUMBER_OF_SHARDS, numberOfShards).build();
settings = settingsBuilder().put(settings).put(SETTING_NUMBER_OF_SHARDS, numberOfShards).build();
return this;
}
@ -129,7 +129,7 @@ public class IndexMetaData {
}
public Builder numberOfReplicas(int numberOfReplicas) {
settings = settingsBuilder().putAll(settings).putInt(SETTING_NUMBER_OF_REPLICAS, numberOfReplicas).build();
settings = settingsBuilder().put(settings).put(SETTING_NUMBER_OF_REPLICAS, numberOfReplicas).build();
return this;
}

View File

@ -129,12 +129,12 @@ public class MetaDataService extends AbstractComponent {
for (IndexRoutingTable indexRoutingTable : currentState.routingTable().indicesRouting().values()) {
routingTableBuilder.add(indexRoutingTable);
}
ImmutableSettings.Builder indexSettingsBuilder = settingsBuilder().putAll(indexSettings);
ImmutableSettings.Builder indexSettingsBuilder = settingsBuilder().put(indexSettings);
if (indexSettings.get(SETTING_NUMBER_OF_SHARDS) == null) {
indexSettingsBuilder.putInt(SETTING_NUMBER_OF_SHARDS, settings.getAsInt(SETTING_NUMBER_OF_SHARDS, 5));
indexSettingsBuilder.put(SETTING_NUMBER_OF_SHARDS, settings.getAsInt(SETTING_NUMBER_OF_SHARDS, 5));
}
if (indexSettings.get(SETTING_NUMBER_OF_REPLICAS) == null) {
indexSettingsBuilder.putInt(SETTING_NUMBER_OF_REPLICAS, settings.getAsInt(SETTING_NUMBER_OF_REPLICAS, 1));
indexSettingsBuilder.put(SETTING_NUMBER_OF_REPLICAS, settings.getAsInt(SETTING_NUMBER_OF_REPLICAS, 1));
}
Settings actualIndexSettings = indexSettingsBuilder.build();

View File

@ -62,6 +62,9 @@ public class MoreLikeThisFieldJsonQueryBuilder extends BaseJsonQueryBuilder {
return this;
}
/**
* The percentage of terms to match. Defaults to <tt>0.3</tt>.
*/
public MoreLikeThisFieldJsonQueryBuilder percentTermsToMatch(float percentTermsToMatch) {
this.percentTermsToMatch = percentTermsToMatch;
return this;

View File

@ -90,10 +90,14 @@ public class MoreLikeThisFieldJsonQueryParser extends AbstractIndexComponent imp
mltQuery.setBoostTerms(jp.getIntValue() != 0);
} else if ("boostTermsFactor".equals(currentFieldName)) {
mltQuery.setBoostTermsFactor(jp.getIntValue());
} else if ("percentTermsToMatch".equals(currentFieldName)) {
mltQuery.setPercentTermsToMatch(jp.getIntValue());
}
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
if ("boostTermsFactor".equals(currentFieldName)) {
mltQuery.setBoostTermsFactor(jp.getFloatValue());
} else if ("percentTermsToMatch".equals(currentFieldName)) {
mltQuery.setPercentTermsToMatch(jp.getFloatValue());
}
} else if (token == JsonToken.START_ARRAY) {
if ("stopWords".equals(currentFieldName)) {

View File

@ -63,6 +63,9 @@ public class MoreLikeThisJsonQueryBuilder extends BaseJsonQueryBuilder {
return this;
}
/**
* The percentage of terms to match. Defaults to <tt>0.3</tt>.
*/
public MoreLikeThisJsonQueryBuilder percentTermsToMatch(float percentTermsToMatch) {
this.percentTermsToMatch = percentTermsToMatch;
return this;

View File

@ -82,10 +82,14 @@ public class MoreLikeThisJsonQueryParser extends AbstractIndexComponent implemen
mltQuery.setBoostTerms(jp.getIntValue() != 0);
} else if ("boostTermsFactor".equals(currentFieldName)) {
mltQuery.setBoostTermsFactor(jp.getIntValue());
} else if ("percentTermsToMatch".equals(currentFieldName)) {
mltQuery.setPercentTermsToMatch(jp.getIntValue());
}
} else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
if ("boostTermsFactor".equals(currentFieldName)) {
mltQuery.setBoostTermsFactor(jp.getFloatValue());
} else if ("percentTermsToMatch".equals(currentFieldName)) {
mltQuery.setPercentTermsToMatch(jp.getFloatValue());
}
} else if (token == JsonToken.START_ARRAY) {
if ("stopWords".equals(currentFieldName)) {

View File

@ -166,8 +166,8 @@ public class InternalIndicesService extends AbstractComponent implements Indices
Settings indexSettings = settingsBuilder()
.put("settingsType", "index")
.putAll(this.settings)
.putAll(settings)
.put(this.settings)
.put(settings)
.classLoader(settings.getClassLoader())
.globalSettings(settings.getGlobalSettings())
.build();

View File

@ -38,7 +38,7 @@ public class InternalSettingsPerparer {
public static Tuple<Settings, Environment> prepareSettings(Settings pSettings, boolean loadConfigSettings) {
// just create enough settings to build the environment
ImmutableSettings.Builder settingsBuilder = settingsBuilder()
.putAll(pSettings)
.put(pSettings)
.putProperties("elasticsearch.", System.getProperties())
.putProperties("es.", System.getProperties())
.replacePropertyPlaceholders();
@ -46,7 +46,7 @@ public class InternalSettingsPerparer {
Environment environment = new Environment(settingsBuilder.build());
// put back the env settings
settingsBuilder = settingsBuilder().putAll(pSettings);
settingsBuilder = settingsBuilder().put(pSettings);
settingsBuilder.put("path.home", cleanPath(environment.homeFile().getAbsolutePath()));
settingsBuilder.put("path.work", cleanPath(environment.workFile().getAbsolutePath()));
settingsBuilder.put("path.workWithCluster", cleanPath(environment.workWithClusterFile().getAbsolutePath()));
@ -78,7 +78,7 @@ public class InternalSettingsPerparer {
}
}
settingsBuilder.putAll(pSettings)
settingsBuilder.put(pSettings)
.putProperties("elasticsearch.", System.getProperties())
.putProperties("es.", System.getProperties())
.replacePropertyPlaceholders();

View File

@ -71,7 +71,7 @@ public class LogConfigurator {
}
loaded = true;
Environment environment = new Environment(settings);
ImmutableSettings.Builder settingsBuilder = settingsBuilder().putAll(settings);
ImmutableSettings.Builder settingsBuilder = settingsBuilder().put(settings);
try {
settingsBuilder.loadFromUrl(environment.resolveConfig("logging.yml"));
} catch (FailedToResolveConfigException e) {

View File

@ -329,7 +329,7 @@ public class ImmutableSettings implements Settings {
* @param clazz The setting class value
* @return The builder
*/
public Builder putClass(String key, Class clazz) {
public Builder put(String key, Class clazz) {
map.put(key, clazz.getName());
return this;
}
@ -341,7 +341,7 @@ public class ImmutableSettings implements Settings {
* @param value The boolean value
* @return The builder
*/
public Builder putBoolean(String setting, boolean value) {
public Builder put(String setting, boolean value) {
put(setting, String.valueOf(value));
return this;
}
@ -353,7 +353,7 @@ public class ImmutableSettings implements Settings {
* @param value The int value
* @return The builder
*/
public Builder putInt(String setting, int value) {
public Builder put(String setting, int value) {
put(setting, String.valueOf(value));
return this;
}
@ -365,7 +365,7 @@ public class ImmutableSettings implements Settings {
* @param value The long value
* @return The builder
*/
public Builder putLong(String setting, long value) {
public Builder put(String setting, long value) {
put(setting, String.valueOf(value));
return this;
}
@ -377,12 +377,19 @@ public class ImmutableSettings implements Settings {
* @param value The float value
* @return The builder
*/
public Builder putFloat(String setting, float value) {
public Builder put(String setting, float value) {
put(setting, String.valueOf(value));
return this;
}
public Builder putDouble(String setting, double value) {
/**
* Sets the setting with the provided setting key and the double value.
*
* @param setting The setting key
* @param value The double value
* @return The builder
*/
public Builder put(String setting, double value) {
put(setting, String.valueOf(value));
return this;
}
@ -394,8 +401,8 @@ public class ImmutableSettings implements Settings {
* @param value The time value
* @return The builder
*/
public Builder putTime(String setting, long value, TimeUnit timeUnit) {
putLong(setting, timeUnit.toMillis(value));
public Builder put(String setting, long value, TimeUnit timeUnit) {
put(setting, timeUnit.toMillis(value));
return this;
}
@ -406,15 +413,15 @@ public class ImmutableSettings implements Settings {
* @param value The size value
* @return The builder
*/
public Builder putSize(String setting, long value, SizeUnit sizeUnit) {
putLong(setting, sizeUnit.toBytes(value));
public Builder put(String setting, long value, SizeUnit sizeUnit) {
put(setting, sizeUnit.toBytes(value));
return this;
}
/**
* Sets the setting group.
*/
public Builder putGroup(String settingPrefix, String groupName, String[] settings, String[] values) throws SettingsException {
public Builder put(String settingPrefix, String groupName, String[] settings, String[] values) throws SettingsException {
if (settings.length != values.length) {
throw new SettingsException("The settings length must match the value length");
}
@ -430,7 +437,7 @@ public class ImmutableSettings implements Settings {
/**
* Sets all the provided settings.
*/
public Builder putAll(Settings settings) {
public Builder put(Settings settings) {
map.putAll(settings.getAsMap());
return this;
}
@ -438,7 +445,7 @@ public class ImmutableSettings implements Settings {
/**
* Sets all the provided settings.
*/
public Builder putAll(Map<String, String> settings) {
public Builder put(Map<String, String> settings) {
map.putAll(settings);
return this;
}
@ -446,7 +453,7 @@ public class ImmutableSettings implements Settings {
/**
* Sets all the provided settings.
*/
public Builder putAll(Properties properties) {
public Builder put(Properties properties) {
for (Map.Entry entry : properties.entrySet()) {
map.put((String) entry.getKey(), (String) entry.getValue());
}
@ -461,7 +468,7 @@ public class ImmutableSettings implements Settings {
SettingsLoader settingsLoader = SettingsLoaderFactory.loaderFromSource(source);
try {
Map<String, String> loadedSettings = settingsLoader.load(source);
putAll(loadedSettings);
put(loadedSettings);
} catch (IOException e) {
throw new SettingsException("Failed to load settings from [" + source + "]");
}
@ -488,7 +495,7 @@ public class ImmutableSettings implements Settings {
SettingsLoader settingsLoader = SettingsLoaderFactory.loaderFromResource(resourceName);
try {
Map<String, String> loadedSettings = settingsLoader.load(Streams.copyToString(new InputStreamReader(is, "UTF-8")));
putAll(loadedSettings);
put(loadedSettings);
} catch (IOException e) {
throw new SettingsException("Failed to load settings from [" + resourceName + "]");
}

View File

@ -44,9 +44,9 @@ public class IndexQueryParserModuleTests {
@Test public void testCustomInjection() {
Settings settings = settingsBuilder()
.putClass("index.queryparser.json.query.my.type", MyJsonQueryParser.class)
.put("index.queryparser.json.query.my.type", MyJsonQueryParser.class)
.put("index.queryparser.json.query.my.param1", "value1")
.putClass("index.queryparser.json.filter.my.type", MyJsonFilterParser.class)
.put("index.queryparser.json.filter.my.type", MyJsonFilterParser.class)
.put("index.queryparser.json.filter.my.param2", "value2")
.put("index.cache.filter.type", "none")
.build();

View File

@ -53,8 +53,8 @@ public class BenchmarkNettyClient {
final boolean spawn = true;
Settings settings = ImmutableSettings.settingsBuilder()
.putBoolean("network.server", false)
.putInt("transport.netty.connectionsPerNode", 5)
.put("network.server", false)
.put("transport.netty.connectionsPerNode", 5)
.build();
final ThreadPool threadPool = new CachedThreadPool();

View File

@ -37,7 +37,7 @@ public class BenchmarkNettyServer {
final boolean spawn = true;
Settings settings = ImmutableSettings.settingsBuilder()
.putInt("transport.netty.port", 9999)
.put("transport.netty.port", 9999)
.build();
final ThreadPool threadPool = new CachedThreadPool();

View File

@ -56,7 +56,7 @@ public abstract class AbstractServersTests {
String settingsSource = getClass().getName().replace('.', '/') + ".yml";
Settings finalSettings = settingsBuilder()
.loadFromClasspath(settingsSource)
.putAll(settings)
.put(settings)
.put("name", id)
.build();
Server server = serverBuilder()

View File

@ -44,7 +44,7 @@ public class DiscoveryTransportClientTests extends AbstractServersTests {
public void testWithDiscovery() throws Exception {
startServer("server1");
client = new TransportClient(ImmutableSettings.settingsBuilder().putBoolean("discovery.enabled", true).build());
client = new TransportClient(ImmutableSettings.settingsBuilder().put("discovery.enabled", true).build());
// wait a bit so nodes will be discovered
Thread.sleep(1000);
client.admin().indices().create(createIndexRequest("test")).actionGet();

View File

@ -35,14 +35,14 @@ public class TransportClientDocumentActionsTests extends DocumentActionsTests {
@Override protected Client getClient1() {
TransportAddress server1Address = ((InternalServer) server("server1")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportClient client = new TransportClient(settingsBuilder().putBoolean("discovery.enabled", false).build());
TransportClient client = new TransportClient(settingsBuilder().put("discovery.enabled", false).build());
client.addTransportAddress(server1Address);
return client;
}
@Override protected Client getClient2() {
TransportAddress server1Address = ((InternalServer) server("server2")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportClient client = new TransportClient(settingsBuilder().putBoolean("discovery.enabled", false).build());
TransportClient client = new TransportClient(settingsBuilder().put("discovery.enabled", false).build());
client.addTransportAddress(server1Address);
return client;
}

View File

@ -35,14 +35,14 @@ public class TransportClientMoreLikeThisActionTests extends MoreLikeThisActionTe
@Override protected Client getClient1() {
TransportAddress server1Address = ((InternalServer) server("server1")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportClient client = new TransportClient(settingsBuilder().putBoolean("discovery.enabled", false).build());
TransportClient client = new TransportClient(settingsBuilder().put("discovery.enabled", false).build());
client.addTransportAddress(server1Address);
return client;
}
@Override protected Client getClient2() {
TransportAddress server1Address = ((InternalServer) server("server2")).injector().getInstance(TransportService.class).boundAddress().publishAddress();
TransportClient client = new TransportClient(settingsBuilder().putBoolean("discovery.enabled", false).build());
TransportClient client = new TransportClient(settingsBuilder().put("discovery.enabled", false).build());
client.addTransportAddress(server1Address);
return client;
}

View File

@ -42,7 +42,7 @@ public class SimpleDataNodesTests extends AbstractServersTests {
}
@Test public void testDataNodes() throws Exception {
startServer("nonData1", settingsBuilder().putBoolean("node.data", false).build());
startServer("nonData1", settingsBuilder().put("node.data", false).build());
client("nonData1").admin().indices().create(createIndexRequest("test")).actionGet();
try {
client("nonData1").index(Requests.indexRequest("test").type("type1").id("1").source(source("1", "test")).timeout(timeValueSeconds(1))).actionGet();
@ -51,7 +51,7 @@ public class SimpleDataNodesTests extends AbstractServersTests {
// all is well
}
startServer("nonData2", settingsBuilder().putBoolean("node.data", false).build());
startServer("nonData2", settingsBuilder().put("node.data", false).build());
Thread.sleep(500);
// still no shard should be allocated
@ -63,7 +63,7 @@ public class SimpleDataNodesTests extends AbstractServersTests {
}
// now, start a node data, and see that it gets with shards
startServer("data1", settingsBuilder().putBoolean("node.data", true).build());
startServer("data1", settingsBuilder().put("node.data", true).build());
Thread.sleep(500);
IndexResponse indexResponse = client("nonData2").index(Requests.indexRequest("test").type("type1").id("1").source(source("1", "test"))).actionGet();

View File

@ -54,8 +54,8 @@ public class IndexLifecycleActionTests extends AbstractServersTests {
@Test public void testIndexLifecycleActionsWith11Shards1Backup() throws Exception {
Settings settings = settingsBuilder()
.putInt(SETTING_NUMBER_OF_SHARDS, 11)
.putInt(SETTING_NUMBER_OF_REPLICAS, 1)
.put(SETTING_NUMBER_OF_SHARDS, 11)
.put(SETTING_NUMBER_OF_REPLICAS, 1)
.build();
// start one server
@ -189,8 +189,8 @@ public class IndexLifecycleActionTests extends AbstractServersTests {
@Test public void testIndexLifecycleActionsWith11Shards0Backup() throws Exception {
Settings settings = settingsBuilder()
.putInt(SETTING_NUMBER_OF_SHARDS, 11)
.putInt(SETTING_NUMBER_OF_REPLICAS, 0)
.put(SETTING_NUMBER_OF_SHARDS, 11)
.put(SETTING_NUMBER_OF_REPLICAS, 0)
.build();
// start one server
@ -323,8 +323,8 @@ public class IndexLifecycleActionTests extends AbstractServersTests {
@Test public void testTwoIndicesCreation() throws Exception {
Settings settings = settingsBuilder()
.putInt(SETTING_NUMBER_OF_SHARDS, 11)
.putInt(SETTING_NUMBER_OF_REPLICAS, 0)
.put(SETTING_NUMBER_OF_SHARDS, 11)
.put(SETTING_NUMBER_OF_REPLICAS, 0)
.build();
// start one server