private <T> Map getDefaultSettings(ElasticsearchPersistentEntity<T> persistentEntity) { if (persistentEntity.isUseServerConfiguration()) return new HashMap(); return new MapBuilder<String, String>().put("index.number_of_shards", String.valueOf(persistentEntity.getShards())) .put("index.number_of_replicas", String.valueOf(persistentEntity.getReplicas())) .put("index.refresh_interval", persistentEntity.getRefreshInterval()) .put("index.store.type", persistentEntity.getIndexStoreType()).map(); }
private StatsHolder typeStats(String type) { StatsHolder stats = typesStats.get(type); if (stats == null) { synchronized (this) { stats = typesStats.get(type); if (stats == null) { stats = new StatsHolder(); typesStats = MapBuilder.newMapBuilder(typesStats).put(type, stats).immutableMap(); } } } return stats; }
private StatsHolder groupStats(String group) { StatsHolder stats = groupsStats.get(group); if (stats == null) { synchronized (this) { stats = groupsStats.get(group); if (stats == null) { stats = new StatsHolder(); groupsStats = MapBuilder.newMapBuilder(groupsStats).put(group, stats).immutableMap(); } } } return stats; }
private AttributesRoutings getActiveAttribute(AttributesKey key, DiscoveryNodes nodes) { AttributesRoutings shardRoutings = activeShardsByAttributes.get(key); if (shardRoutings == null) { synchronized (shardsByAttributeMutex) { ArrayList<ShardRouting> from = new ArrayList<>(activeShards); List<ShardRouting> to = collectAttributeShards(key, nodes, from); shardRoutings = new AttributesRoutings(to, Collections.unmodifiableList(from)); activeShardsByAttributes = MapBuilder.newMapBuilder(activeShardsByAttributes).put(key, shardRoutings).immutableMap(); } } return shardRoutings; }
public CodecService(@Nullable MapperService mapperService, Logger logger) { final MapBuilder<String, Codec> codecs = MapBuilder.<String, Codec>newMapBuilder(); if (mapperService == null) { codecs.put(DEFAULT_CODEC, new Lucene70Codec()); codecs.put(BEST_COMPRESSION_CODEC, new Lucene70Codec(Mode.BEST_COMPRESSION)); } else { codecs.put(DEFAULT_CODEC, new PerFieldMappingPostingFormatCodec(Mode.BEST_SPEED, mapperService, logger)); codecs.put(BEST_COMPRESSION_CODEC, new PerFieldMappingPostingFormatCodec(Mode.BEST_COMPRESSION, mapperService, logger)); } codecs.put(LUCENE_DEFAULT_CODEC, Codec.getDefault()); for (String codec : Codec.availableCodecs()) { codecs.put(codec, Codec.forName(codec)); } this.codecs = codecs.immutableMap(); }
private AttributesRoutings getInitializingAttribute(AttributesKey key, DiscoveryNodes nodes) { AttributesRoutings shardRoutings = initializingShardsByAttributes.get(key); if (shardRoutings == null) { synchronized (shardsByAttributeMutex) { ArrayList<ShardRouting> from = new ArrayList<>(allInitializingShards); List<ShardRouting> to = collectAttributeShards(key, nodes, from); shardRoutings = new AttributesRoutings(to, Collections.unmodifiableList(from)); initializingShardsByAttributes = MapBuilder.newMapBuilder(initializingShardsByAttributes).put(key, shardRoutings).immutableMap(); } } return shardRoutings; }
public void clear() { totalStats.clear(); synchronized (this) { if (!groupsStats.isEmpty()) { MapBuilder<String, StatsHolder> typesStatsBuilder = MapBuilder.newMapBuilder(); for (Map.Entry<String, StatsHolder> typeStats : groupsStats.entrySet()) { if (typeStats.getValue().totalCurrent() > 0) { typeStats.getValue().clear(); typesStatsBuilder.put(typeStats.getKey(), typeStats.getValue()); } } groupsStats = typesStatsBuilder.immutableMap(); } } }
@Override public synchronized <Request extends TransportRequest> void registerRequestHandler(RequestHandlerRegistry<Request> reg) { if (requestHandlers.containsKey(reg.getAction())) { throw new IllegalArgumentException("transport handlers for action " + reg.getAction() + " is already registered"); } requestHandlers = MapBuilder.newMapBuilder(requestHandlers).put(reg.getAction(), reg).immutableMap(); }
/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source */ @SuppressWarnings("unchecked") public CreateIndexRequest mapping(String type, Map source) { if (mappings.containsKey(type)) { throw new IllegalStateException("mappings for type \"" + type + "\" were already defined"); } // wrap it in a type map if its not if (source.size() != 1 || !source.containsKey(type)) { source = MapBuilder.<String, Object>newMapBuilder().put(type, source).map(); } try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); return mapping(type, builder); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } }
/** * Adds mapping that will be added when the index gets created. * * @param type The mapping type * @param source The mapping source */ public PutIndexTemplateRequest mapping(String type, Map<String, Object> source) { // wrap it in a type map if its not if (source.size() != 1 || !source.containsKey(type)) { source = MapBuilder.<String, Object>newMapBuilder().put(type, source).map(); } try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); return mapping(type, builder); } catch (IOException e) { throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e); } }
@Override public void readFrom(StreamInput in) throws IOException { MapBuilder<String, String> builder = MapBuilder.newMapBuilder(); for (int i = in.readVInt(); i > 0; i--) { builder.put(in.readString(), in.readString()); } userData = builder.immutableMap(); generation = in.readLong(); id = in.readOptionalString(); numDocs = in.readInt(); }
try { indexService.getIndexEventListener().afterIndexCreated(indexService); indices = newMapBuilder(indices).put(index.getUUID(), indexService).immutableMap(); success = true; return indexService;
String mappingType = currentFieldName; Map<String, Object> mappingSource = MapBuilder.<String, Object>newMapBuilder().put(mappingType, parser.mapOrdered()).map(); builder.putMapping(mappingType, Strings.toString(XContentFactory.jsonBuilder().map(mappingSource)));
eventListener.indexShardStateChanged(indexShard, null, indexShard.state(), "shard created"); eventListener.afterIndexShardCreated(indexShard); shards = newMapBuilder(shards).put(shardId.id(), indexShard).immutableMap(); success = true; return indexShard;
String mappingType = currentFieldName; Map<String, Object> mappingSource = MapBuilder.<String, Object>newMapBuilder().put(mappingType, parser.mapOrdered()).map(); builder.putMapping(new MappingMetaData(mappingType, mappingSource)); } else {
private AttributesRoutings getActiveAttribute(AttributesKey key, DiscoveryNodes nodes) { AttributesRoutings shardRoutings = activeShardsByAttributes.get(key); if (shardRoutings == null) { synchronized (shardsByAttributeMutex) { ArrayList<ShardRouting> from = new ArrayList<>(activeShards); List<ShardRouting> to = collectAttributeShards(key, nodes, from); shardRoutings = new AttributesRoutings(to, Collections.unmodifiableList(from)); activeShardsByAttributes = MapBuilder.newMapBuilder(activeShardsByAttributes).put(key, shardRoutings).immutableMap(); } } return shardRoutings; }
private AttributesRoutings getInitializingAttribute(AttributesKey key, DiscoveryNodes nodes) { AttributesRoutings shardRoutings = initializingShardsByAttributes.get(key); if (shardRoutings == null) { synchronized (shardsByAttributeMutex) { ArrayList<ShardRouting> from = new ArrayList<>(allInitializingShards); List<ShardRouting> to = collectAttributeShards(key, nodes, from); shardRoutings = new AttributesRoutings(to, Collections.unmodifiableList(from)); initializingShardsByAttributes = MapBuilder.newMapBuilder(initializingShardsByAttributes).put(key, shardRoutings).immutableMap(); } } return shardRoutings; }
private AttributesRoutings getInitializingAttribute(AttributesKey key, DiscoveryNodes nodes) { AttributesRoutings shardRoutings = initializingShardsByAttributes.get(key); if (shardRoutings == null) { synchronized (shardsByAttributeMutex) { ArrayList<ShardRouting> from = new ArrayList<>(allInitializingShards); List<ShardRouting> to = collectAttributeShards(key, nodes, from); shardRoutings = new AttributesRoutings(to, Collections.unmodifiableList(from)); initializingShardsByAttributes = MapBuilder.newMapBuilder(initializingShardsByAttributes).put(key, shardRoutings).immutableMap(); } } return shardRoutings; }
private AttributesRoutings getActiveAttribute(AttributesKey key, DiscoveryNodes nodes) { AttributesRoutings shardRoutings = activeShardsByAttributes.get(key); if (shardRoutings == null) { synchronized (shardsByAttributeMutex) { ArrayList<ShardRouting> from = new ArrayList<>(activeShards); List<ShardRouting> to = collectAttributeShards(key, nodes, from); shardRoutings = new AttributesRoutings(to, Collections.unmodifiableList(from)); activeShardsByAttributes = MapBuilder.newMapBuilder(activeShardsByAttributes).put(key, shardRoutings).immutableMap(); } } return shardRoutings; }
private <Request extends TransportRequest> void registerRequestHandler(RequestHandlerRegistry<Request> reg) { synchronized (requestHandlerMutex) { if (requestHandlers.containsKey(reg.getAction())) { throw new IllegalArgumentException("transport handlers for action " + reg.getAction() + " is already registered"); } requestHandlers = MapBuilder.newMapBuilder(requestHandlers).put(reg.getAction(), reg).immutableMap(); } }