From 9464c390acb349d19c552af223897a844016b0f4 Mon Sep 17 00:00:00 2001 From: kimchy Date: Wed, 7 Apr 2010 18:30:39 +0300 Subject: [PATCH] Allow to define custom prefix for settings when components do not use the org.elasticsearch package --- .../index/AbstractIndexComponent.java | 8 ++++++++ .../shard/AbstractIndexShardComponent.java | 10 +++++++++- .../util/component/AbstractComponent.java | 18 ++++++++++++++++++ .../component/AbstractLifecycleComponent.java | 12 ++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/AbstractIndexComponent.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/AbstractIndexComponent.java index b9687396ad6..9be312b4583 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/AbstractIndexComponent.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/AbstractIndexComponent.java @@ -48,6 +48,14 @@ public abstract class AbstractIndexComponent implements IndexComponent { this.logger = Loggers.getLogger(getClass(), indexSettings, index); } + protected AbstractIndexComponent(Index index, @IndexSettings Settings indexSettings, String prefixSettings) { + this.index = index; + this.indexSettings = indexSettings; + this.componentSettings = indexSettings.getComponentSettings(prefixSettings, getClass()); + + this.logger = Loggers.getLogger(getClass(), indexSettings, index); + } + @Override public Index index() { return this.index; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/AbstractIndexShardComponent.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/AbstractIndexShardComponent.java index 4b1e1f684cb..2de9a05e4f4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/AbstractIndexShardComponent.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/AbstractIndexShardComponent.java @@ -28,7 +28,7 @@ import org.slf4j.Logger; import static org.elasticsearch.index.shard.IndexShardManagement.*; /** - * @author kimchy (Shay Banon) + * @author kimchy (shay.banon) */ public abstract class AbstractIndexShardComponent implements IndexShardComponent { @@ -48,6 +48,14 @@ public abstract class AbstractIndexShardComponent implements IndexShardComponent this.logger = Loggers.getLogger(getClass(), indexSettings, shardId); } + protected AbstractIndexShardComponent(ShardId shardId, @IndexSettings Settings indexSettings, String prefixSettings) { + this.shardId = shardId; + this.indexSettings = indexSettings; + this.componentSettings = indexSettings.getComponentSettings(prefixSettings, getClass()); + + this.logger = Loggers.getLogger(getClass(), indexSettings, shardId); + } + @Override public ShardId shardId() { return this.shardId; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/AbstractComponent.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/AbstractComponent.java index 53c31f9f39c..87250121b3e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/AbstractComponent.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/AbstractComponent.java @@ -40,18 +40,36 @@ public class AbstractComponent { this.componentSettings = settings.getComponentSettings(getClass()); } + public AbstractComponent(Settings settings, String prefixSettings) { + this.logger = Loggers.getLogger(getClass(), settings); + this.settings = settings; + this.componentSettings = settings.getComponentSettings(prefixSettings, getClass()); + } + public AbstractComponent(Settings settings, Class customClass) { this.logger = Loggers.getLogger(customClass, settings); this.settings = settings; this.componentSettings = settings.getComponentSettings(customClass); } + public AbstractComponent(Settings settings, String prefixSettings, Class customClass) { + this.logger = Loggers.getLogger(customClass, settings); + this.settings = settings; + this.componentSettings = settings.getComponentSettings(prefixSettings, customClass); + } + public AbstractComponent(Settings settings, Class loggerClass, Class componentClass) { this.logger = Loggers.getLogger(loggerClass, settings); this.settings = settings; this.componentSettings = settings.getComponentSettings(componentClass); } + public AbstractComponent(Settings settings, String prefixSettings, Class loggerClass, Class componentClass) { + this.logger = Loggers.getLogger(loggerClass, settings); + this.settings = settings; + this.componentSettings = settings.getComponentSettings(prefixSettings, componentClass); + } + public String nodeName() { return settings.get("name", ""); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/AbstractLifecycleComponent.java b/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/AbstractLifecycleComponent.java index 57f52d02613..4914f02e89e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/AbstractLifecycleComponent.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/util/component/AbstractLifecycleComponent.java @@ -46,6 +46,18 @@ public abstract class AbstractLifecycleComponent extends AbstractComponent im super(settings, loggerClass, componentClass); } + protected AbstractLifecycleComponent(Settings settings, String prefixSettings) { + super(settings, prefixSettings); + } + + protected AbstractLifecycleComponent(Settings settings, String prefixSettings, Class customClass) { + super(settings, prefixSettings, customClass); + } + + protected AbstractLifecycleComponent(Settings settings, String prefixSettings, Class loggerClass, Class componentClass) { + super(settings, prefixSettings, loggerClass, componentClass); + } + @Override public Lifecycle.State lifecycleState() { return this.lifecycle.state(); }