Make return type of MapBuilder#immutableMap Map

We won't be removing that method - just deprecating it. So we need to remove
ImmutableMap from it. And the only way to do that is not to return one.
This commit is contained in:
Nik Everett 2015-10-05 10:49:27 -04:00
parent dd8edd4015
commit 672a54b39a
14 changed files with 256 additions and 227 deletions

View File

@ -19,35 +19,42 @@
package org.elasticsearch.client.transport.support;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.action.*;
import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.GenericAction;
import org.elasticsearch.action.TransportActionNodeProxy;
import org.elasticsearch.client.transport.TransportClientNodesService;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.transport.TransportService;
import java.util.HashMap;
import java.util.Map;
import static java.util.Collections.unmodifiableMap;
/**
*
*/
public class TransportProxyClient {
private final TransportClientNodesService nodesService;
private final ImmutableMap<Action, TransportActionNodeProxy> proxies;
private final Map<Action, TransportActionNodeProxy> proxies;
@Inject
public TransportProxyClient(Settings settings, TransportService transportService, TransportClientNodesService nodesService, Map<String, GenericAction> actions) {
this.nodesService = nodesService;
MapBuilder<Action, TransportActionNodeProxy> actionsBuilder = new MapBuilder<>();
Map<Action, TransportActionNodeProxy> proxies = new HashMap<>();
for (GenericAction action : actions.values()) {
if (action instanceof Action) {
actionsBuilder.put((Action) action, new TransportActionNodeProxy(settings, action, transportService));
proxies.put((Action) action, new TransportActionNodeProxy(settings, action, transportService));
}
}
this.proxies = actionsBuilder.immutableMap();
this.proxies = unmodifiableMap(proxies);
}
public <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void execute(final Action<Request, Response, RequestBuilder> action, final Request request, ActionListener<Response> listener) {

View File

@ -19,22 +19,27 @@
package org.elasticsearch.common.blobstore.fs;
import com.google.common.collect.ImmutableMap;
import org.apache.lucene.util.IOUtils;
import org.elasticsearch.common.blobstore.BlobMetaData;
import org.elasticsearch.common.blobstore.BlobPath;
import org.elasticsearch.common.blobstore.support.AbstractBlobContainer;
import org.elasticsearch.common.blobstore.support.PlainBlobMetaData;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.io.Streams;
import java.io.*;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.HashMap;
import java.util.Map;
import static java.util.Collections.unmodifiableMap;
/**
*
@ -52,14 +57,14 @@ public class FsBlobContainer extends AbstractBlobContainer {
}
@Override
public ImmutableMap<String, BlobMetaData> listBlobs() throws IOException {
public Map<String, BlobMetaData> listBlobs() throws IOException {
return listBlobsByPrefix(null);
}
@Override
public ImmutableMap<String, BlobMetaData> listBlobsByPrefix(String blobNamePrefix) throws IOException {
// using MapBuilder and not ImmutableMap.Builder as it seems like File#listFiles might return duplicate files!
MapBuilder<String, BlobMetaData> builder = MapBuilder.newMapBuilder();
public Map<String, BlobMetaData> listBlobsByPrefix(String blobNamePrefix) throws IOException {
// If we get duplicate files we should just take the last entry
Map<String, BlobMetaData> builder = new HashMap<>();
blobNamePrefix = blobNamePrefix == null ? "" : blobNamePrefix;
try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, blobNamePrefix + "*")) {
@ -70,7 +75,7 @@ public class FsBlobContainer extends AbstractBlobContainer {
}
}
}
return builder.immutableMap();
return unmodifiableMap(builder);
}
@Override

View File

@ -19,11 +19,11 @@
package org.elasticsearch.common.collect;
import com.google.common.collect.ImmutableMap;
import java.util.HashMap;
import java.util.Map;
import static java.util.Collections.unmodifiableMap;
/**
*
*/
@ -90,8 +90,8 @@ public class MapBuilder<K, V> {
* HashMap by hand and wrapping it in an unmodifiableMap
*/
@Deprecated
public ImmutableMap<K, V> immutableMap() {
public Map<K, V> immutableMap() {
// Note that this whole method is going to have to go next but we're changing it like this here just to keep the commit smaller.
return ImmutableMap.<K, V>builder().putAll(map).build();
return unmodifiableMap(new HashMap<>(map));
}
}

View File

@ -19,10 +19,8 @@
package org.elasticsearch.common.logging.log4j;
import com.google.common.collect.ImmutableMap;
import org.apache.log4j.PropertyConfigurator;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.env.Environment;
@ -36,10 +34,12 @@ import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import static java.util.Collections.unmodifiableMap;
import static org.elasticsearch.common.Strings.cleanPath;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
@ -50,38 +50,41 @@ public class LogConfigurator {
static final List<String> ALLOWED_SUFFIXES = Arrays.asList(".yml", ".yaml", ".json", ".properties");
private static boolean loaded;
private static ImmutableMap<String, String> replacements = new MapBuilder<String, String>()
.put("console", "org.elasticsearch.common.logging.log4j.ConsoleAppender")
.put("async", "org.apache.log4j.AsyncAppender")
.put("dailyRollingFile", "org.apache.log4j.DailyRollingFileAppender")
.put("externallyRolledFile", "org.apache.log4j.ExternallyRolledFileAppender")
.put("file", "org.apache.log4j.FileAppender")
.put("jdbc", "org.apache.log4j.jdbc.JDBCAppender")
.put("jms", "org.apache.log4j.net.JMSAppender")
.put("lf5", "org.apache.log4j.lf5.LF5Appender")
.put("ntevent", "org.apache.log4j.nt.NTEventLogAppender")
.put("null", "org.apache.log4j.NullAppender")
.put("rollingFile", "org.apache.log4j.RollingFileAppender")
.put("extrasRollingFile", "org.apache.log4j.rolling.RollingFileAppender")
.put("smtp", "org.apache.log4j.net.SMTPAppender")
.put("socket", "org.apache.log4j.net.SocketAppender")
.put("socketHub", "org.apache.log4j.net.SocketHubAppender")
.put("syslog", "org.apache.log4j.net.SyslogAppender")
.put("telnet", "org.apache.log4j.net.TelnetAppender")
private static final Map<String, String> REPLACEMENTS;
static {
Map<String, String> replacements = new HashMap<>();
replacements.put("console", "org.elasticsearch.common.logging.log4j.ConsoleAppender");
replacements.put("async", "org.apache.log4j.AsyncAppender");
replacements.put("dailyRollingFile", "org.apache.log4j.DailyRollingFileAppender");
replacements.put("externallyRolledFile", "org.apache.log4j.ExternallyRolledFileAppender");
replacements.put("file", "org.apache.log4j.FileAppender");
replacements.put("jdbc", "org.apache.log4j.jdbc.JDBCAppender");
replacements.put("jms", "org.apache.log4j.net.JMSAppender");
replacements.put("lf5", "org.apache.log4j.lf5.LF5Appender");
replacements.put("ntevent", "org.apache.log4j.nt.NTEventLogAppender");
replacements.put("null", "org.apache.log4j.NullAppender");
replacements.put("rollingFile", "org.apache.log4j.RollingFileAppender");
replacements.put("extrasRollingFile", "org.apache.log4j.rolling.RollingFileAppender");
replacements.put("smtp", "org.apache.log4j.net.SMTPAppender");
replacements.put("socket", "org.apache.log4j.net.SocketAppender");
replacements.put("socketHub", "org.apache.log4j.net.SocketHubAppender");
replacements.put("syslog", "org.apache.log4j.net.SyslogAppender");
replacements.put("telnet", "org.apache.log4j.net.TelnetAppender");
// policies
.put("timeBased", "org.apache.log4j.rolling.TimeBasedRollingPolicy")
.put("sizeBased", "org.apache.log4j.rolling.SizeBasedTriggeringPolicy")
replacements.put("timeBased", "org.apache.log4j.rolling.TimeBasedRollingPolicy");
replacements.put("sizeBased", "org.apache.log4j.rolling.SizeBasedTriggeringPolicy");
// layouts
.put("simple", "org.apache.log4j.SimpleLayout")
.put("html", "org.apache.log4j.HTMLLayout")
.put("pattern", "org.apache.log4j.PatternLayout")
.put("consolePattern", "org.apache.log4j.PatternLayout")
.put("enhancedPattern", "org.apache.log4j.EnhancedPatternLayout")
.put("ttcc", "org.apache.log4j.TTCCLayout")
.put("xml", "org.apache.log4j.XMLLayout")
.immutableMap();
replacements.put("simple", "org.apache.log4j.SimpleLayout");
replacements.put("html", "org.apache.log4j.HTMLLayout");
replacements.put("pattern", "org.apache.log4j.PatternLayout");
replacements.put("consolePattern", "org.apache.log4j.PatternLayout");
replacements.put("enhancedPattern", "org.apache.log4j.EnhancedPatternLayout");
replacements.put("ttcc", "org.apache.log4j.TTCCLayout");
replacements.put("xml", "org.apache.log4j.XMLLayout");
REPLACEMENTS = unmodifiableMap(replacements);
}
private static boolean loaded;
public static void configure(Settings settings) {
if (loaded) {
@ -100,9 +103,7 @@ public class LogConfigurator {
for (Map.Entry<String, String> entry : settingsBuilder.build().getAsMap().entrySet()) {
String key = "log4j." + entry.getKey();
String value = entry.getValue();
if (replacements.containsKey(value)) {
value = replacements.get(value);
}
value = REPLACEMENTS.getOrDefault(value, value);
if (key.endsWith(".value")) {
props.setProperty(key.substring(0, key.length() - ".value".length()), value);
} else if (key.endsWith(".type")) {

View File

@ -19,8 +19,6 @@
package org.elasticsearch.index.analysis;
import java.nio.charset.StandardCharsets;
import com.google.common.collect.ImmutableMap;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.NumericTokenStream;
import org.apache.lucene.analysis.TokenStream;
@ -60,7 +58,6 @@ import org.apache.lucene.analysis.tr.TurkishAnalyzer;
import org.apache.lucene.analysis.util.CharArraySet;
import org.apache.lucene.util.Version;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.lucene.Lucene;
@ -71,15 +68,19 @@ import org.elasticsearch.index.settings.IndexSettings;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import static java.util.Collections.unmodifiableMap;
/**
*
*/
@ -124,40 +125,44 @@ public class Analysis {
}
}
public static final ImmutableMap<String, Set<?>> namedStopWords = MapBuilder.<String, Set<?>>newMapBuilder()
.put("_arabic_", ArabicAnalyzer.getDefaultStopSet())
.put("_armenian_", ArmenianAnalyzer.getDefaultStopSet())
.put("_basque_", BasqueAnalyzer.getDefaultStopSet())
.put("_brazilian_", BrazilianAnalyzer.getDefaultStopSet())
.put("_bulgarian_", BulgarianAnalyzer.getDefaultStopSet())
.put("_catalan_", CatalanAnalyzer.getDefaultStopSet())
.put("_czech_", CzechAnalyzer.getDefaultStopSet())
.put("_danish_", DanishAnalyzer.getDefaultStopSet())
.put("_dutch_", DutchAnalyzer.getDefaultStopSet())
.put("_english_", EnglishAnalyzer.getDefaultStopSet())
.put("_finnish_", FinnishAnalyzer.getDefaultStopSet())
.put("_french_", FrenchAnalyzer.getDefaultStopSet())
.put("_galician_", GalicianAnalyzer.getDefaultStopSet())
.put("_german_", GermanAnalyzer.getDefaultStopSet())
.put("_greek_", GreekAnalyzer.getDefaultStopSet())
.put("_hindi_", HindiAnalyzer.getDefaultStopSet())
.put("_hungarian_", HungarianAnalyzer.getDefaultStopSet())
.put("_indonesian_", IndonesianAnalyzer.getDefaultStopSet())
.put("_irish_", IrishAnalyzer.getDefaultStopSet())
.put("_italian_", ItalianAnalyzer.getDefaultStopSet())
.put("_latvian_", LatvianAnalyzer.getDefaultStopSet())
.put("_lithuanian_", LithuanianAnalyzer.getDefaultStopSet())
.put("_norwegian_", NorwegianAnalyzer.getDefaultStopSet())
.put("_persian_", PersianAnalyzer.getDefaultStopSet())
.put("_portuguese_", PortugueseAnalyzer.getDefaultStopSet())
.put("_romanian_", RomanianAnalyzer.getDefaultStopSet())
.put("_russian_", RussianAnalyzer.getDefaultStopSet())
.put("_sorani_", SoraniAnalyzer.getDefaultStopSet())
.put("_spanish_", SpanishAnalyzer.getDefaultStopSet())
.put("_swedish_", SwedishAnalyzer.getDefaultStopSet())
.put("_thai_", ThaiAnalyzer.getDefaultStopSet())
.put("_turkish_", TurkishAnalyzer.getDefaultStopSet())
.immutableMap();
public static final Map<String, Set<?>> NAMED_STOP_WORDS;
static {
Map<String, Set<?>> namedStopWords = new HashMap<>();
namedStopWords.put("_arabic_", ArabicAnalyzer.getDefaultStopSet());
namedStopWords.put("_armenian_", ArmenianAnalyzer.getDefaultStopSet());
namedStopWords.put("_basque_", BasqueAnalyzer.getDefaultStopSet());
namedStopWords.put("_brazilian_", BrazilianAnalyzer.getDefaultStopSet());
namedStopWords.put("_bulgarian_", BulgarianAnalyzer.getDefaultStopSet());
namedStopWords.put("_catalan_", CatalanAnalyzer.getDefaultStopSet());
namedStopWords.put("_czech_", CzechAnalyzer.getDefaultStopSet());
namedStopWords.put("_danish_", DanishAnalyzer.getDefaultStopSet());
namedStopWords.put("_dutch_", DutchAnalyzer.getDefaultStopSet());
namedStopWords.put("_english_", EnglishAnalyzer.getDefaultStopSet());
namedStopWords.put("_finnish_", FinnishAnalyzer.getDefaultStopSet());
namedStopWords.put("_french_", FrenchAnalyzer.getDefaultStopSet());
namedStopWords.put("_galician_", GalicianAnalyzer.getDefaultStopSet());
namedStopWords.put("_german_", GermanAnalyzer.getDefaultStopSet());
namedStopWords.put("_greek_", GreekAnalyzer.getDefaultStopSet());
namedStopWords.put("_hindi_", HindiAnalyzer.getDefaultStopSet());
namedStopWords.put("_hungarian_", HungarianAnalyzer.getDefaultStopSet());
namedStopWords.put("_indonesian_", IndonesianAnalyzer.getDefaultStopSet());
namedStopWords.put("_irish_", IrishAnalyzer.getDefaultStopSet());
namedStopWords.put("_italian_", ItalianAnalyzer.getDefaultStopSet());
namedStopWords.put("_latvian_", LatvianAnalyzer.getDefaultStopSet());
namedStopWords.put("_lithuanian_", LithuanianAnalyzer.getDefaultStopSet());
namedStopWords.put("_norwegian_", NorwegianAnalyzer.getDefaultStopSet());
namedStopWords.put("_persian_", PersianAnalyzer.getDefaultStopSet());
namedStopWords.put("_portuguese_", PortugueseAnalyzer.getDefaultStopSet());
namedStopWords.put("_romanian_", RomanianAnalyzer.getDefaultStopSet());
namedStopWords.put("_russian_", RussianAnalyzer.getDefaultStopSet());
namedStopWords.put("_sorani_", SoraniAnalyzer.getDefaultStopSet());
namedStopWords.put("_spanish_", SpanishAnalyzer.getDefaultStopSet());
namedStopWords.put("_swedish_", SwedishAnalyzer.getDefaultStopSet());
namedStopWords.put("_thai_", ThaiAnalyzer.getDefaultStopSet());
namedStopWords.put("_turkish_", TurkishAnalyzer.getDefaultStopSet());
NAMED_STOP_WORDS = unmodifiableMap(namedStopWords);
}
public static CharArraySet parseWords(Environment env, Settings settings, String name, CharArraySet defaultWords, Map<String, Set<?>> namedWords, boolean ignoreCase) {
String value = settings.get(name);
@ -176,7 +181,7 @@ public class Analysis {
}
public static CharArraySet parseCommonWords(Environment env, Settings settings, CharArraySet defaultCommonWords, boolean ignoreCase) {
return parseWords(env, settings, "common_words", defaultCommonWords, namedStopWords, ignoreCase);
return parseWords(env, settings, "common_words", defaultCommonWords, NAMED_STOP_WORDS, ignoreCase);
}
public static CharArraySet parseArticles(Environment env, Settings settings) {
@ -188,7 +193,7 @@ public class Analysis {
}
public static CharArraySet parseStopWords(Environment env, Settings settings, CharArraySet defaultStopWords, boolean ignoreCase) {
return parseWords(env, settings, "stopwords", defaultStopWords, namedStopWords, ignoreCase);
return parseWords(env, settings, "stopwords", defaultStopWords, NAMED_STOP_WORDS, ignoreCase);
}
private static CharArraySet resolveNamedWords(Collection<String> words, Map<String, Set<?>> namedWords, boolean ignoreCase) {

View File

@ -18,13 +18,11 @@
*/
package org.elasticsearch.index.analysis;
import com.google.common.collect.ImmutableMap;
import org.apache.lucene.analysis.core.StopAnalyzer;
import org.apache.lucene.analysis.de.GermanAnalyzer;
import org.apache.lucene.analysis.fr.FrenchAnalyzer;
import org.apache.lucene.analysis.nl.DutchAnalyzer;
import org.apache.lucene.analysis.util.CharArraySet;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.inject.assistedinject.Assisted;
import org.elasticsearch.common.settings.Settings;
@ -32,6 +30,11 @@ import org.elasticsearch.env.Environment;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.settings.IndexSettings;
import java.util.HashMap;
import java.util.Map;
import static java.util.Collections.unmodifiableMap;
/**
* Creates a SnowballAnalyzer initialized with stopwords and Snowball filter. Only
* supports Dutch, English (default), French, German and German2 where stopwords
@ -46,14 +49,17 @@ import org.elasticsearch.index.settings.IndexSettings;
*
*/
public class SnowballAnalyzerProvider extends AbstractIndexAnalyzerProvider<SnowballAnalyzer> {
private static final Map<String, CharArraySet> DEFAULT_LANGUAGE_STOPWORDS;
private static final ImmutableMap<String, CharArraySet> defaultLanguageStopwords = MapBuilder.<String, CharArraySet>newMapBuilder()
.put("English", StopAnalyzer.ENGLISH_STOP_WORDS_SET)
.put("Dutch", DutchAnalyzer.getDefaultStopSet())
.put("German", GermanAnalyzer.getDefaultStopSet())
.put("German2", GermanAnalyzer.getDefaultStopSet())
.put("French", FrenchAnalyzer.getDefaultStopSet())
.immutableMap();
static {
Map<String, CharArraySet> defaultLanguageStopwords = new HashMap<>();
defaultLanguageStopwords.put("English", StopAnalyzer.ENGLISH_STOP_WORDS_SET);
defaultLanguageStopwords.put("Dutch", DutchAnalyzer.getDefaultStopSet());
defaultLanguageStopwords.put("German", GermanAnalyzer.getDefaultStopSet());
defaultLanguageStopwords.put("German2", GermanAnalyzer.getDefaultStopSet());
defaultLanguageStopwords.put("French", FrenchAnalyzer.getDefaultStopSet());
DEFAULT_LANGUAGE_STOPWORDS = unmodifiableMap(defaultLanguageStopwords);
}
private final SnowballAnalyzer analyzer;
@ -62,7 +68,7 @@ public class SnowballAnalyzerProvider extends AbstractIndexAnalyzerProvider<Snow
super(index, indexSettings, name, settings);
String language = settings.get("language", settings.get("name", "English"));
CharArraySet defaultStopwords = defaultLanguageStopwords.containsKey(language) ? defaultLanguageStopwords.get(language) : CharArraySet.EMPTY_SET;
CharArraySet defaultStopwords = DEFAULT_LANGUAGE_STOPWORDS.getOrDefault(language, CharArraySet.EMPTY_SET);
CharArraySet stopWords = Analysis.parseStopWords(env, settings, defaultStopwords);
analyzer = new SnowballAnalyzer(language, stopWords);

View File

@ -19,13 +19,10 @@
package org.elasticsearch.index.mapper;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.geo.ShapesAvailability;
@ -80,6 +77,7 @@ import java.util.SortedMap;
import java.util.TreeMap;
import static java.util.Collections.unmodifiableMap;
import static java.util.Collections.unmodifiableSortedMap;
import static org.elasticsearch.index.mapper.MapperBuilders.doc;
public class DocumentMapperParser {
@ -97,8 +95,8 @@ public class DocumentMapperParser {
private final Version indexVersionCreated;
private final ParseFieldMatcher parseFieldMatcher;
private volatile ImmutableMap<String, Mapper.TypeParser> typeParsers;
private volatile ImmutableMap<String, Mapper.TypeParser> rootTypeParsers;
private volatile Map<String, Mapper.TypeParser> typeParsers;
private volatile Map<String, Mapper.TypeParser> rootTypeParsers;
private volatile SortedMap<String, Mapper.TypeParser> additionalRootMappers;
public DocumentMapperParser(@IndexSettings Settings indexSettings, MapperService mapperService, AnalysisService analysisService,
@ -109,66 +107,65 @@ public class DocumentMapperParser {
this.analysisService = analysisService;
this.similarityLookupService = similarityLookupService;
this.scriptService = scriptService;
MapBuilder<String, Mapper.TypeParser> typeParsersBuilder = new MapBuilder<String, Mapper.TypeParser>()
.put(ByteFieldMapper.CONTENT_TYPE, new ByteFieldMapper.TypeParser())
.put(ShortFieldMapper.CONTENT_TYPE, new ShortFieldMapper.TypeParser())
.put(IntegerFieldMapper.CONTENT_TYPE, new IntegerFieldMapper.TypeParser())
.put(LongFieldMapper.CONTENT_TYPE, new LongFieldMapper.TypeParser())
.put(FloatFieldMapper.CONTENT_TYPE, new FloatFieldMapper.TypeParser())
.put(DoubleFieldMapper.CONTENT_TYPE, new DoubleFieldMapper.TypeParser())
.put(BooleanFieldMapper.CONTENT_TYPE, new BooleanFieldMapper.TypeParser())
.put(BinaryFieldMapper.CONTENT_TYPE, new BinaryFieldMapper.TypeParser())
.put(DateFieldMapper.CONTENT_TYPE, new DateFieldMapper.TypeParser())
.put(IpFieldMapper.CONTENT_TYPE, new IpFieldMapper.TypeParser())
.put(StringFieldMapper.CONTENT_TYPE, new StringFieldMapper.TypeParser())
.put(TokenCountFieldMapper.CONTENT_TYPE, new TokenCountFieldMapper.TypeParser())
.put(ObjectMapper.CONTENT_TYPE, new ObjectMapper.TypeParser())
.put(ObjectMapper.NESTED_CONTENT_TYPE, new ObjectMapper.TypeParser())
.put(TypeParsers.MULTI_FIELD_CONTENT_TYPE, TypeParsers.multiFieldConverterTypeParser)
.put(CompletionFieldMapper.CONTENT_TYPE, new CompletionFieldMapper.TypeParser())
.put(GeoPointFieldMapper.CONTENT_TYPE, new GeoPointFieldMapper.TypeParser());
Map<String, Mapper.TypeParser> typeParsers = new HashMap<>();
typeParsers.put(ByteFieldMapper.CONTENT_TYPE, new ByteFieldMapper.TypeParser());
typeParsers.put(ShortFieldMapper.CONTENT_TYPE, new ShortFieldMapper.TypeParser());
typeParsers.put(IntegerFieldMapper.CONTENT_TYPE, new IntegerFieldMapper.TypeParser());
typeParsers.put(LongFieldMapper.CONTENT_TYPE, new LongFieldMapper.TypeParser());
typeParsers.put(FloatFieldMapper.CONTENT_TYPE, new FloatFieldMapper.TypeParser());
typeParsers.put(DoubleFieldMapper.CONTENT_TYPE, new DoubleFieldMapper.TypeParser());
typeParsers.put(BooleanFieldMapper.CONTENT_TYPE, new BooleanFieldMapper.TypeParser());
typeParsers.put(BinaryFieldMapper.CONTENT_TYPE, new BinaryFieldMapper.TypeParser());
typeParsers.put(DateFieldMapper.CONTENT_TYPE, new DateFieldMapper.TypeParser());
typeParsers.put(IpFieldMapper.CONTENT_TYPE, new IpFieldMapper.TypeParser());
typeParsers.put(StringFieldMapper.CONTENT_TYPE, new StringFieldMapper.TypeParser());
typeParsers.put(TokenCountFieldMapper.CONTENT_TYPE, new TokenCountFieldMapper.TypeParser());
typeParsers.put(ObjectMapper.CONTENT_TYPE, new ObjectMapper.TypeParser());
typeParsers.put(ObjectMapper.NESTED_CONTENT_TYPE, new ObjectMapper.TypeParser());
typeParsers.put(TypeParsers.MULTI_FIELD_CONTENT_TYPE, TypeParsers.multiFieldConverterTypeParser);
typeParsers.put(CompletionFieldMapper.CONTENT_TYPE, new CompletionFieldMapper.TypeParser());
typeParsers.put(GeoPointFieldMapper.CONTENT_TYPE, new GeoPointFieldMapper.TypeParser());
if (ShapesAvailability.JTS_AVAILABLE) {
typeParsersBuilder.put(GeoShapeFieldMapper.CONTENT_TYPE, new GeoShapeFieldMapper.TypeParser());
typeParsers.put(GeoShapeFieldMapper.CONTENT_TYPE, new GeoShapeFieldMapper.TypeParser());
}
typeParsers = typeParsersBuilder.immutableMap();
this.typeParsers = unmodifiableMap(typeParsers);
rootTypeParsers = new MapBuilder<String, Mapper.TypeParser>()
.put(IndexFieldMapper.NAME, new IndexFieldMapper.TypeParser())
.put(SourceFieldMapper.NAME, new SourceFieldMapper.TypeParser())
.put(TypeFieldMapper.NAME, new TypeFieldMapper.TypeParser())
.put(AllFieldMapper.NAME, new AllFieldMapper.TypeParser())
.put(ParentFieldMapper.NAME, new ParentFieldMapper.TypeParser())
.put(RoutingFieldMapper.NAME, new RoutingFieldMapper.TypeParser())
.put(TimestampFieldMapper.NAME, new TimestampFieldMapper.TypeParser())
.put(TTLFieldMapper.NAME, new TTLFieldMapper.TypeParser())
.put(UidFieldMapper.NAME, new UidFieldMapper.TypeParser())
.put(VersionFieldMapper.NAME, new VersionFieldMapper.TypeParser())
.put(IdFieldMapper.NAME, new IdFieldMapper.TypeParser())
.put(FieldNamesFieldMapper.NAME, new FieldNamesFieldMapper.TypeParser())
.immutableMap();
Map<String, Mapper.TypeParser> rootTypeParsers = new HashMap<>();
rootTypeParsers.put(IndexFieldMapper.NAME, new IndexFieldMapper.TypeParser());
rootTypeParsers.put(SourceFieldMapper.NAME, new SourceFieldMapper.TypeParser());
rootTypeParsers.put(TypeFieldMapper.NAME, new TypeFieldMapper.TypeParser());
rootTypeParsers.put(AllFieldMapper.NAME, new AllFieldMapper.TypeParser());
rootTypeParsers.put(ParentFieldMapper.NAME, new ParentFieldMapper.TypeParser());
rootTypeParsers.put(RoutingFieldMapper.NAME, new RoutingFieldMapper.TypeParser());
rootTypeParsers.put(TimestampFieldMapper.NAME, new TimestampFieldMapper.TypeParser());
rootTypeParsers.put(TTLFieldMapper.NAME, new TTLFieldMapper.TypeParser());
rootTypeParsers.put(UidFieldMapper.NAME, new UidFieldMapper.TypeParser());
rootTypeParsers.put(VersionFieldMapper.NAME, new VersionFieldMapper.TypeParser());
rootTypeParsers.put(IdFieldMapper.NAME, new IdFieldMapper.TypeParser());
rootTypeParsers.put(FieldNamesFieldMapper.NAME, new FieldNamesFieldMapper.TypeParser());
this.rootTypeParsers = unmodifiableMap(rootTypeParsers);
additionalRootMappers = Collections.emptySortedMap();
indexVersionCreated = Version.indexCreated(indexSettings);
}
public void putTypeParser(String type, Mapper.TypeParser typeParser) {
synchronized (typeParsersMutex) {
typeParsers = new MapBuilder<>(typeParsers)
.put(type, typeParser)
.immutableMap();
Map<String, Mapper.TypeParser> typeParsers = new HashMap<>(this.typeParsers);
typeParsers.put(type, typeParser);
this.typeParsers = unmodifiableMap(typeParsers);
}
}
public void putRootTypeParser(String type, Mapper.TypeParser typeParser) {
synchronized (typeParsersMutex) {
rootTypeParsers = new MapBuilder<>(rootTypeParsers)
.put(type, typeParser)
.immutableMap();
SortedMap<String, Mapper.TypeParser> newAdditionalRootMappers = new TreeMap<>();
newAdditionalRootMappers.putAll(additionalRootMappers);
newAdditionalRootMappers.put(type, typeParser);
additionalRootMappers = Collections.unmodifiableSortedMap(newAdditionalRootMappers);
Map<String, Mapper.TypeParser> rootTypeParsers = new HashMap<>(this.rootTypeParsers);
rootTypeParsers.put(type, typeParser);
this.rootTypeParsers = rootTypeParsers;
SortedMap<String, Mapper.TypeParser> additionalRootMappers = new TreeMap<>(this.additionalRootMappers);
additionalRootMappers.put(type, typeParser);
this.additionalRootMappers = unmodifiableSortedMap(additionalRootMappers);
}
}

View File

@ -19,7 +19,6 @@
package org.elasticsearch.index.mapper;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseFieldMatcher;
@ -89,14 +88,14 @@ public abstract class Mapper implements ToXContent, Iterable<Mapper> {
private final MapperService mapperService;
private final ImmutableMap<String, TypeParser> typeParsers;
private final Map<String, TypeParser> typeParsers;
private final Version indexVersionCreated;
private final ParseFieldMatcher parseFieldMatcher;
public ParserContext(String type, AnalysisService analysisService, SimilarityLookupService similarityLookupService,
MapperService mapperService, ImmutableMap<String, TypeParser> typeParsers,
MapperService mapperService, Map<String, TypeParser> typeParsers,
Version indexVersionCreated, ParseFieldMatcher parseFieldMatcher) {
this.type = type;
this.analysisService = analysisService;

View File

@ -19,13 +19,24 @@
package org.elasticsearch.index.similarity;
import com.google.common.collect.ImmutableMap;
import org.apache.lucene.search.similarities.*;
import org.elasticsearch.common.collect.MapBuilder;
import org.apache.lucene.search.similarities.Distribution;
import org.apache.lucene.search.similarities.DistributionLL;
import org.apache.lucene.search.similarities.DistributionSPL;
import org.apache.lucene.search.similarities.IBSimilarity;
import org.apache.lucene.search.similarities.Lambda;
import org.apache.lucene.search.similarities.LambdaDF;
import org.apache.lucene.search.similarities.LambdaTTF;
import org.apache.lucene.search.similarities.Normalization;
import org.apache.lucene.search.similarities.Similarity;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.inject.assistedinject.Assisted;
import org.elasticsearch.common.settings.Settings;
import java.util.HashMap;
import java.util.Map;
import static java.util.Collections.unmodifiableMap;
/**
* {@link SimilarityProvider} for {@link IBSimilarity}.
* <p>
@ -39,19 +50,19 @@ import org.elasticsearch.common.settings.Settings;
*/
public class IBSimilarityProvider extends AbstractSimilarityProvider {
private static final ImmutableMap<String, Distribution> DISTRIBUTION_CACHE;
private static final ImmutableMap<String, Lambda> LAMBDA_CACHE;
private static final Map<String, Distribution> DISTRIBUTIONS;
private static final Map<String, Lambda> LAMBDAS;
static {
MapBuilder<String, Distribution> distributions = MapBuilder.newMapBuilder();
Map<String, Distribution> distributions = new HashMap<>();
distributions.put("ll", new DistributionLL());
distributions.put("spl", new DistributionSPL());
DISTRIBUTION_CACHE = distributions.immutableMap();
DISTRIBUTIONS = unmodifiableMap(distributions);
MapBuilder<String, Lambda> lamdas = MapBuilder.newMapBuilder();
Map<String, Lambda> lamdas = new HashMap<>();
lamdas.put("df", new LambdaDF());
lamdas.put("ttf", new LambdaTTF());
LAMBDA_CACHE = lamdas.immutableMap();
LAMBDAS = unmodifiableMap(lamdas);
}
private final IBSimilarity similarity;
@ -73,7 +84,7 @@ public class IBSimilarityProvider extends AbstractSimilarityProvider {
*/
protected Distribution parseDistribution(Settings settings) {
String rawDistribution = settings.get("distribution");
Distribution distribution = DISTRIBUTION_CACHE.get(rawDistribution);
Distribution distribution = DISTRIBUTIONS.get(rawDistribution);
if (distribution == null) {
throw new IllegalArgumentException("Unsupported Distribution [" + rawDistribution + "]");
}
@ -88,7 +99,7 @@ public class IBSimilarityProvider extends AbstractSimilarityProvider {
*/
protected Lambda parseLambda(Settings settings) {
String rawLambda = settings.get("lambda");
Lambda lambda = LAMBDA_CACHE.get(rawLambda);
Lambda lambda = LAMBDAS.get(rawLambda);
if (lambda == null) {
throw new IllegalArgumentException("Unsupported Lambda [" + rawLambda + "]");
}

View File

@ -19,26 +19,29 @@
package org.elasticsearch.index.similarity;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableMap;
import org.apache.lucene.search.similarities.BM25Similarity;
import org.apache.lucene.search.similarities.DefaultSimilarity;
import org.elasticsearch.common.collect.MapBuilder;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import static java.util.Collections.unmodifiableMap;
/**
* Cache of pre-defined Similarities
*/
public class Similarities {
private static final ImmutableMap<String, PreBuiltSimilarityProvider.Factory> PRE_BUILT_SIMILARITIES;
private static final Map<String, PreBuiltSimilarityProvider.Factory> PRE_BUILT_SIMILARITIES;
static {
MapBuilder<String, PreBuiltSimilarityProvider.Factory> similarities = MapBuilder.newMapBuilder();
Map<String, PreBuiltSimilarityProvider.Factory> similarities = new HashMap<>();
similarities.put(SimilarityLookupService.DEFAULT_SIMILARITY,
new PreBuiltSimilarityProvider.Factory(SimilarityLookupService.DEFAULT_SIMILARITY, new DefaultSimilarity()));
similarities.put("BM25", new PreBuiltSimilarityProvider.Factory("BM25", new BM25Similarity()));
PRE_BUILT_SIMILARITIES = similarities.immutableMap();
PRE_BUILT_SIMILARITIES = unmodifiableMap(similarities);
}
private Similarities() {
@ -49,7 +52,7 @@ public class Similarities {
*
* @return Pre-defined SimilarityProvider Factories
*/
public static ImmutableCollection<PreBuiltSimilarityProvider.Factory> listFactories() {
public static Collection<PreBuiltSimilarityProvider.Factory> listFactories() {
return PRE_BUILT_SIMILARITIES.values();
}
}

View File

@ -19,20 +19,20 @@
package org.elasticsearch.monitor.jvm;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.FutureUtils;
import org.elasticsearch.monitor.jvm.JvmStats.GarbageCollector;
import org.elasticsearch.threadpool.ThreadPool;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ScheduledFuture;
import static java.util.Collections.unmodifiableMap;
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
import static org.elasticsearch.monitor.jvm.JvmStats.GarbageCollector;
import static org.elasticsearch.monitor.jvm.JvmStats.jvmStats;
/**
@ -43,7 +43,7 @@ public class JvmMonitorService extends AbstractLifecycleComponent<JvmMonitorServ
private final ThreadPool threadPool;
private final boolean enabled;
private final TimeValue interval;
private final ImmutableMap<String, GcThreshold> gcThresholds;
private final Map<String, GcThreshold> gcThresholds;
private volatile ScheduledFuture scheduledFuture;
@ -79,7 +79,7 @@ public class JvmMonitorService extends AbstractLifecycleComponent<JvmMonitorServ
this.enabled = this.settings.getAsBoolean("monitor.jvm.enabled", true);
this.interval = this.settings.getAsTime("monitor.jvm.interval", timeValueSeconds(1));
MapBuilder<String, GcThreshold> gcThresholds = MapBuilder.newMapBuilder();
Map<String, GcThreshold> gcThresholds = new HashMap<>();
Map<String, Settings> gcThresholdGroups = this.settings.getGroups("monitor.jvm.gc");
for (Map.Entry<String, Settings> entry : gcThresholdGroups.entrySet()) {
String name = entry.getKey();
@ -92,17 +92,10 @@ public class JvmMonitorService extends AbstractLifecycleComponent<JvmMonitorServ
gcThresholds.put(name, new GcThreshold(name, warn.millis(), info.millis(), debug.millis()));
}
}
if (!gcThresholds.containsKey(GcNames.YOUNG)) {
gcThresholds.put(GcNames.YOUNG, new GcThreshold(GcNames.YOUNG, 1000, 700, 400));
}
if (!gcThresholds.containsKey(GcNames.OLD)) {
gcThresholds.put(GcNames.OLD, new GcThreshold(GcNames.OLD, 10000, 5000, 2000));
}
if (!gcThresholds.containsKey("default")) {
gcThresholds.put("default", new GcThreshold("default", 10000, 5000, 2000));
}
this.gcThresholds = gcThresholds.immutableMap();
gcThresholds.putIfAbsent(GcNames.YOUNG, new GcThreshold(GcNames.YOUNG, 1000, 700, 400));
gcThresholds.putIfAbsent(GcNames.OLD, new GcThreshold(GcNames.OLD, 10000, 5000, 2000));
gcThresholds.putIfAbsent("default", new GcThreshold("default", 10000, 5000, 2000));
this.gcThresholds = unmodifiableMap(gcThresholds);
logger.debug("enabled [{}], interval [{}], gc_threshold [{}]", enabled, interval, this.gcThresholds);
}

View File

@ -18,9 +18,6 @@
*/
package org.elasticsearch.search.aggregations;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
@ -30,19 +27,22 @@ import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory;
import org.elasticsearch.search.internal.SearchContext;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.util.Collections.unmodifiableMap;
/**
* A registry for all the aggregator parser, also servers as the main parser for the aggregations module
*/
public class AggregatorParsers {
public static final Pattern VALID_AGG_NAME = Pattern.compile("[^\\[\\]>]+");
private final ImmutableMap<String, Aggregator.Parser> aggParsers;
private final ImmutableMap<String, PipelineAggregator.Parser> pipelineAggregatorParsers;
private final Map<String, Aggregator.Parser> aggParsers;
private final Map<String, PipelineAggregator.Parser> pipelineAggregatorParsers;
/**
@ -55,16 +55,16 @@ public class AggregatorParsers {
*/
@Inject
public AggregatorParsers(Set<Aggregator.Parser> aggParsers, Set<PipelineAggregator.Parser> pipelineAggregatorParsers) {
MapBuilder<String, Aggregator.Parser> aggParsersBuilder = MapBuilder.newMapBuilder();
Map<String, Aggregator.Parser> aggParsersBuilder = new HashMap<>(aggParsers.size());
for (Aggregator.Parser parser : aggParsers) {
aggParsersBuilder.put(parser.type(), parser);
}
this.aggParsers = aggParsersBuilder.immutableMap();
MapBuilder<String, PipelineAggregator.Parser> pipelineAggregatorParsersBuilder = MapBuilder.newMapBuilder();
this.aggParsers = unmodifiableMap(aggParsersBuilder);
Map<String, PipelineAggregator.Parser> pipelineAggregatorParsersBuilder = new HashMap<>(pipelineAggregatorParsers.size());
for (PipelineAggregator.Parser parser : pipelineAggregatorParsers) {
pipelineAggregatorParsersBuilder.put(parser.type(), parser);
}
this.pipelineAggregatorParsers = pipelineAggregatorParsersBuilder.immutableMap();
this.pipelineAggregatorParsers = unmodifiableMap(pipelineAggregatorParsersBuilder);
}
/**

View File

@ -18,10 +18,7 @@
*/
package org.elasticsearch.search.aggregations.bucket.histogram;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.rounding.DateTimeUnit;
import org.elasticsearch.common.rounding.Rounding;
import org.elasticsearch.common.rounding.TimeZoneRounding;
@ -34,7 +31,12 @@ import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.search.aggregations.support.ValuesSourceParser;
import org.elasticsearch.search.internal.SearchContext;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import static java.util.Collections.unmodifiableMap;
/**
*
@ -45,27 +47,27 @@ public class DateHistogramParser implements Aggregator.Parser {
static final ParseField OFFSET = new ParseField("offset");
static final ParseField INTERVAL = new ParseField("interval");
public static final ImmutableMap<String, DateTimeUnit> DATE_FIELD_UNITS;
public static final Map<String, DateTimeUnit> DATE_FIELD_UNITS;
static {
DATE_FIELD_UNITS = MapBuilder.<String, DateTimeUnit>newMapBuilder()
.put("year", DateTimeUnit.YEAR_OF_CENTURY)
.put("1y", DateTimeUnit.YEAR_OF_CENTURY)
.put("quarter", DateTimeUnit.QUARTER)
.put("1q", DateTimeUnit.QUARTER)
.put("month", DateTimeUnit.MONTH_OF_YEAR)
.put("1M", DateTimeUnit.MONTH_OF_YEAR)
.put("week", DateTimeUnit.WEEK_OF_WEEKYEAR)
.put("1w", DateTimeUnit.WEEK_OF_WEEKYEAR)
.put("day", DateTimeUnit.DAY_OF_MONTH)
.put("1d", DateTimeUnit.DAY_OF_MONTH)
.put("hour", DateTimeUnit.HOUR_OF_DAY)
.put("1h", DateTimeUnit.HOUR_OF_DAY)
.put("minute", DateTimeUnit.MINUTES_OF_HOUR)
.put("1m", DateTimeUnit.MINUTES_OF_HOUR)
.put("second", DateTimeUnit.SECOND_OF_MINUTE)
.put("1s", DateTimeUnit.SECOND_OF_MINUTE)
.immutableMap();
Map<String, DateTimeUnit> dateFieldUnits = new HashMap<>();
dateFieldUnits.put("year", DateTimeUnit.YEAR_OF_CENTURY);
dateFieldUnits.put("1y", DateTimeUnit.YEAR_OF_CENTURY);
dateFieldUnits.put("quarter", DateTimeUnit.QUARTER);
dateFieldUnits.put("1q", DateTimeUnit.QUARTER);
dateFieldUnits.put("month", DateTimeUnit.MONTH_OF_YEAR);
dateFieldUnits.put("1M", DateTimeUnit.MONTH_OF_YEAR);
dateFieldUnits.put("week", DateTimeUnit.WEEK_OF_WEEKYEAR);
dateFieldUnits.put("1w", DateTimeUnit.WEEK_OF_WEEKYEAR);
dateFieldUnits.put("day", DateTimeUnit.DAY_OF_MONTH);
dateFieldUnits.put("1d", DateTimeUnit.DAY_OF_MONTH);
dateFieldUnits.put("hour", DateTimeUnit.HOUR_OF_DAY);
dateFieldUnits.put("1h", DateTimeUnit.HOUR_OF_DAY);
dateFieldUnits.put("minute", DateTimeUnit.MINUTES_OF_HOUR);
dateFieldUnits.put("1m", DateTimeUnit.MINUTES_OF_HOUR);
dateFieldUnits.put("second", DateTimeUnit.SECOND_OF_MINUTE);
dateFieldUnits.put("1s", DateTimeUnit.SECOND_OF_MINUTE);
DATE_FIELD_UNITS = unmodifiableMap(dateFieldUnits);
}
@Override

View File

@ -19,8 +19,6 @@
package org.elasticsearch.tribe;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.support.master.TransportMasterNodeReadAction;
import org.elasticsearch.cluster.ClusterChangedEvent;
@ -38,7 +36,6 @@ import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.IndexRoutingTable;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.regex.Regex;
@ -58,6 +55,8 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import static java.util.Collections.unmodifiableMap;
/**
* The tribe service holds a list of node clients connected to a list of tribe members, and uses their
* cluster state events to update this local node cluster state with the merged view of it.
@ -243,8 +242,9 @@ public class TribeService extends AbstractLifecycleComponent<TribeService> {
for (DiscoveryNode tribe : tribeState.nodes()) {
if (currentState.nodes().get(tribe.id()) == null) {
// a new node, add it, but also add the tribe name to the attributes
ImmutableMap<String, String> tribeAttr = MapBuilder.newMapBuilder(tribe.attributes()).put(TRIBE_NAME, tribeName).immutableMap();
DiscoveryNode discoNode = new DiscoveryNode(tribe.name(), tribe.id(), tribe.getHostName(), tribe.getHostAddress(), tribe.address(), tribeAttr, tribe.version());
Map<String, String> tribeAttr = new HashMap<>(tribe.attributes());
tribeAttr.put(TRIBE_NAME, tribeName);
DiscoveryNode discoNode = new DiscoveryNode(tribe.name(), tribe.id(), tribe.getHostName(), tribe.getHostAddress(), tribe.address(), unmodifiableMap(tribeAttr), tribe.version());
logger.info("[{}] adding node [{}]", tribeName, discoNode);
nodes.put(discoNode);
}