diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java index 5ac72d70b9c..908a25a9abe 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodeInfo.java @@ -42,9 +42,8 @@ import java.util.Map; * Node information (static, does not change over time). */ public class NodeInfo extends BaseNodeResponse { - @Nullable - private ImmutableMap serviceAttributes; + private Map serviceAttributes; private Version version; private Build build; @@ -119,7 +118,7 @@ public class NodeInfo extends BaseNodeResponse { * The service attributes of the node. */ @Nullable - public ImmutableMap getServiceAttributes() { + public Map getServiceAttributes() { return this.serviceAttributes; } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/TransportNodesSnapshotsStatus.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/TransportNodesSnapshotsStatus.java index 5de9603485e..2ecd4fbbe0d 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/TransportNodesSnapshotsStatus.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/TransportNodesSnapshotsStatus.java @@ -20,6 +20,7 @@ package org.elasticsearch.action.admin.cluster.snapshots.status; import com.google.common.collect.ImmutableMap; + import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.FailedNodeException; @@ -46,10 +47,13 @@ import org.elasticsearch.transport.TransportService; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicReferenceArray; +import static java.util.Collections.unmodifiableMap; + /** * Transport client that collects snapshot shard statuses from data nodes */ @@ -104,7 +108,7 @@ public class TransportNodesSnapshotsStatus extends TransportNodesAction> snapshotMapBuilder = ImmutableMap.builder(); + Map> snapshotMapBuilder = new HashMap<>(); try { String nodeId = clusterService.localNode().id(); for (SnapshotId snapshotId : request.snapshotIds) { @@ -112,7 +116,7 @@ public class TransportNodesSnapshotsStatus extends TransportNodesAction shardMapBuilder = ImmutableMap.builder(); + Map shardMapBuilder = new HashMap<>(); for (Map.Entry shardEntry : shardsStatus.entrySet()) { SnapshotIndexShardStatus shardStatus; IndexShardSnapshotStatus.Stage stage = shardEntry.getValue().stage(); @@ -124,9 +128,9 @@ public class TransportNodesSnapshotsStatus extends TransportNodesAction> status; + private Map> status; NodeSnapshotStatus() { } - public NodeSnapshotStatus(DiscoveryNode node, ImmutableMap> status) { + public NodeSnapshotStatus(DiscoveryNode node, Map> status) { super(node); this.status = status; } - public ImmutableMap> status() { + public Map> status() { return status; } @@ -259,19 +263,19 @@ public class TransportNodesSnapshotsStatus extends TransportNodesAction> snapshotMapBuilder = ImmutableMap.builder(); + Map> snapshotMapBuilder = new HashMap<>(numberOfSnapshots); for (int i = 0; i < numberOfSnapshots; i++) { SnapshotId snapshotId = SnapshotId.readSnapshotId(in); - ImmutableMap.Builder shardMapBuilder = ImmutableMap.builder(); int numberOfShards = in.readVInt(); + Map shardMapBuilder = new HashMap<>(numberOfShards); for (int j = 0; j < numberOfShards; j++) { ShardId shardId = ShardId.readShardId(in); SnapshotIndexShardStatus status = SnapshotIndexShardStatus.readShardSnapshotStatus(in); shardMapBuilder.put(shardId, status); } - snapshotMapBuilder.put(snapshotId, shardMapBuilder.build()); + snapshotMapBuilder.put(snapshotId, unmodifiableMap(shardMapBuilder)); } - status = snapshotMapBuilder.build(); + status = unmodifiableMap(snapshotMapBuilder); } @Override @@ -279,10 +283,10 @@ public class TransportNodesSnapshotsStatus extends TransportNodesAction> entry : status.entrySet()) { + for (Map.Entry> entry : status.entrySet()) { entry.getKey().writeTo(out); out.writeVInt(entry.getValue().size()); - for (ImmutableMap.Entry shardEntry : entry.getValue().entrySet()) { + for (Map.Entry shardEntry : entry.getValue().entrySet()) { shardEntry.getKey().writeTo(out); shardEntry.getValue().writeTo(out); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java index fb4448303ca..5af92dcd42e 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java @@ -157,7 +157,7 @@ public class TransportSnapshotsStatusAction extends TransportMasterNodeAction shardStatues = nodeStatus.status().get(entry.snapshotId()); + Map shardStatues = nodeStatus.status().get(entry.snapshotId()); if (shardStatues != null) { SnapshotIndexShardStatus shardStatus = shardStatues.get(shardEntry.getKey()); if (shardStatus != null) { @@ -204,7 +204,7 @@ public class TransportSnapshotsStatusAction extends TransportMasterNodeAction shardStatusBuilder = new ArrayList<>(); if (snapshot.state().completed()) { - ImmutableMap shardStatues = snapshotsService.snapshotShards(snapshotId); + Map shardStatues = snapshotsService.snapshotShards(snapshotId); for (ImmutableMap.Entry shardStatus : shardStatues.entrySet()) { shardStatusBuilder.add(new SnapshotIndexShardStatus(shardStatus.getKey(), shardStatus.getValue())); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java index b92e60de712..24820ba083d 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java @@ -20,6 +20,7 @@ package org.elasticsearch.action.admin.indices.mapping.get; import com.google.common.collect.ImmutableMap; + import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -31,14 +32,17 @@ import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.index.mapper.Mapper; import java.io.IOException; +import java.util.HashMap; import java.util.Map; +import static java.util.Collections.unmodifiableMap; + /** Response object for {@link GetFieldMappingsRequest} API */ public class GetFieldMappingsResponse extends ActionResponse implements ToXContent { - private ImmutableMap>> mappings = ImmutableMap.of(); + private Map>> mappings = ImmutableMap.of(); - GetFieldMappingsResponse(ImmutableMap>> mappings) { + GetFieldMappingsResponse(Map>> mappings) { this.mappings = mappings; } @@ -46,7 +50,7 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte } /** returns the retrieved field mapping. The return map keys are index, type, field (as specified in the request). */ - public ImmutableMap>> mappings() { + public Map>> mappings() { return mappings; } @@ -57,11 +61,11 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte * @return FieldMappingMetaData for the requested field or null if not found. */ public FieldMappingMetaData fieldMappings(String index, String type, String field) { - ImmutableMap> indexMapping = mappings.get(index); + Map> indexMapping = mappings.get(index); if (indexMapping == null) { return null; } - ImmutableMap typeMapping = indexMapping.get(type); + Map typeMapping = indexMapping.get(type); if (typeMapping == null) { return null; } @@ -70,10 +74,10 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - for (Map.Entry>> indexEntry : mappings.entrySet()) { + for (Map.Entry>> indexEntry : mappings.entrySet()) { builder.startObject(indexEntry.getKey(), XContentBuilder.FieldCaseConversion.NONE); builder.startObject("mappings"); - for (Map.Entry> typeEntry : indexEntry.getValue().entrySet()) { + for (Map.Entry> typeEntry : indexEntry.getValue().entrySet()) { builder.startObject(typeEntry.getKey(), XContentBuilder.FieldCaseConversion.NONE); for (Map.Entry fieldEntry : typeEntry.getValue().entrySet()) { builder.startObject(fieldEntry.getKey()); @@ -128,33 +132,33 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte public void readFrom(StreamInput in) throws IOException { super.readFrom(in); int size = in.readVInt(); - ImmutableMap.Builder>> indexMapBuilder = ImmutableMap.builder(); + Map>> indexMapBuilder = new HashMap<>(size); for (int i = 0; i < size; i++) { String index = in.readString(); int typesSize = in.readVInt(); - ImmutableMap.Builder> typeMapBuilder = ImmutableMap.builder(); + Map> typeMapBuilder = new HashMap<>(typesSize); for (int j = 0; j < typesSize; j++) { String type = in.readString(); - ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); int fieldSize = in.readVInt(); + Map fieldMapBuilder = new HashMap<>(fieldSize); for (int k = 0; k < fieldSize; k++) { fieldMapBuilder.put(in.readString(), new FieldMappingMetaData(in.readString(), in.readBytesReference())); } - typeMapBuilder.put(type, fieldMapBuilder.build()); + typeMapBuilder.put(type, unmodifiableMap(fieldMapBuilder)); } - indexMapBuilder.put(index, typeMapBuilder.build()); + indexMapBuilder.put(index, unmodifiableMap(typeMapBuilder)); } - mappings = indexMapBuilder.build(); + mappings = unmodifiableMap(indexMapBuilder); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeVInt(mappings.size()); - for (Map.Entry>> indexEntry : mappings.entrySet()) { + for (Map.Entry>> indexEntry : mappings.entrySet()) { out.writeString(indexEntry.getKey()); out.writeVInt(indexEntry.getValue().size()); - for (Map.Entry> typeEntry : indexEntry.getValue().entrySet()) { + for (Map.Entry> typeEntry : indexEntry.getValue().entrySet()) { out.writeString(typeEntry.getKey()); out.writeVInt(typeEntry.getValue().size()); for (Map.Entry fieldEntry : typeEntry.getValue().entrySet()) { diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsAction.java index 19f1ec33d7c..060d94ad181 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsAction.java @@ -19,7 +19,6 @@ package org.elasticsearch.action.admin.indices.mapping.get; -import com.google.common.collect.ImmutableMap; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.HandledTransportAction; @@ -32,6 +31,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; +import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReferenceArray; @@ -88,7 +88,7 @@ public class TransportGetFieldMappingsAction extends HandledTransportAction indexResponses) { - MapBuilder>> mergedResponses = MapBuilder.newMapBuilder(); + MapBuilder>> mergedResponses = MapBuilder.newMapBuilder(); for (int i = 0; i < indexResponses.length(); i++) { Object element = indexResponses.get(i); if (element instanceof GetFieldMappingsResponse) { diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsIndexAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsIndexAction.java index 62183a06d11..a7b780a17c3 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsIndexAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetFieldMappingsIndexAction.java @@ -20,6 +20,7 @@ package org.elasticsearch.action.admin.indices.mapping.get; import com.google.common.collect.ImmutableMap; + import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetaData; import org.elasticsearch.action.support.ActionFilters; @@ -52,6 +53,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.Map; import java.util.stream.Collectors; import static org.elasticsearch.common.util.CollectionUtils.newLinkedList; @@ -105,7 +107,7 @@ public class TransportGetFieldMappingsIndexAction extends TransportSingleShardAc } } - MapBuilder> typeMappings = new MapBuilder<>(); + MapBuilder> typeMappings = new MapBuilder<>(); for (String type : typeIntersection) { DocumentMapper documentMapper = indexService.mapperService().documentMapper(type); ImmutableMap fieldMapping = findFieldMappingsByType(documentMapper, request); diff --git a/core/src/main/java/org/elasticsearch/cluster/DiffableUtils.java b/core/src/main/java/org/elasticsearch/cluster/DiffableUtils.java index ce583e312c9..84e0021ee00 100644 --- a/core/src/main/java/org/elasticsearch/cluster/DiffableUtils.java +++ b/core/src/main/java/org/elasticsearch/cluster/DiffableUtils.java @@ -21,7 +21,7 @@ package org.elasticsearch.cluster; import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; -import com.google.common.collect.ImmutableMap; + import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -45,11 +45,11 @@ public final class DiffableUtils { } /** - * Calculates diff between two ImmutableMaps of Diffable objects + * Calculates diff between two Maps of Diffable objects. */ - public static > Diff> diff(ImmutableMap before, ImmutableMap after) { + public static > Diff> diff(Map before, Map after) { assert after != null && before != null; - return new ImmutableMapDiff<>(before, after); + return new JdkMapDiff<>(before, after); } /** @@ -60,10 +60,10 @@ public final class DiffableUtils { } /** - * Loads an object that represents difference between two ImmutableMaps + * Loads an object that represents difference between two Maps. */ - public static > Diff> readImmutableMapDiff(StreamInput in, KeyedReader keyedReader) throws IOException { - return new ImmutableMapDiff<>(in, keyedReader); + public static > Diff> readJdkMapDiff(StreamInput in, KeyedReader keyedReader) throws IOException { + return new JdkMapDiff<>(in, keyedReader); } /** @@ -74,10 +74,10 @@ public final class DiffableUtils { } /** - * Loads an object that represents difference between two ImmutableMaps + * Loads an object that represents difference between two Maps. */ - public static > Diff> readImmutableMapDiff(StreamInput in, T proto) throws IOException { - return new ImmutableMapDiff<>(in, new PrototypeReader<>(proto)); + public static > Diff> readJdkMapDiff(StreamInput in, T proto) throws IOException { + return new JdkMapDiff<>(in, new PrototypeReader<>(proto)); } /** @@ -121,24 +121,24 @@ public final class DiffableUtils { } /** - * Represents differences between two ImmutableMaps of diffable objects + * Represents differences between two Maps of Diffable objects. * * @param the diffable object */ - private static class ImmutableMapDiff> extends MapDiff> { + private static class JdkMapDiff> extends MapDiff> { - protected ImmutableMapDiff(StreamInput in, KeyedReader reader) throws IOException { + protected JdkMapDiff(StreamInput in, KeyedReader reader) throws IOException { super(in, reader); } - public ImmutableMapDiff(ImmutableMap before, ImmutableMap after) { + public JdkMapDiff(Map before, Map after) { assert after != null && before != null; for (String key : before.keySet()) { if (!after.containsKey(key)) { deletes.add(key); } } - for (ImmutableMap.Entry partIter : after.entrySet()) { + for (Map.Entry partIter : after.entrySet()) { T beforePart = before.get(partIter.getKey()); if (beforePart == null) { adds.put(partIter.getKey(), partIter.getValue()); @@ -149,8 +149,8 @@ public final class DiffableUtils { } @Override - public ImmutableMap apply(ImmutableMap map) { - HashMap builder = new HashMap<>(); + public Map apply(Map map) { + Map builder = new HashMap<>(); builder.putAll(map); for (String part : deletes) { @@ -164,7 +164,7 @@ public final class DiffableUtils { for (Map.Entry additon : adds.entrySet()) { builder.put(additon.getKey(), additon.getValue()); } - return ImmutableMap.copyOf(builder); + return builder; } } diff --git a/core/src/main/java/org/elasticsearch/cluster/RestoreInProgress.java b/core/src/main/java/org/elasticsearch/cluster/RestoreInProgress.java index 5776fe698d9..82ba28de62a 100644 --- a/core/src/main/java/org/elasticsearch/cluster/RestoreInProgress.java +++ b/core/src/main/java/org/elasticsearch/cluster/RestoreInProgress.java @@ -112,7 +112,7 @@ public class RestoreInProgress extends AbstractDiffable implements Custo public static class Entry { private final State state; private final SnapshotId snapshotId; - private final ImmutableMap shards; + private final Map shards; private final List indices; /** @@ -148,7 +148,7 @@ public class RestoreInProgress extends AbstractDiffable implements Custo * * @return list of shards */ - public ImmutableMap shards() { + public Map shards() { return this.shards; } diff --git a/core/src/main/java/org/elasticsearch/cluster/SnapshotsInProgress.java b/core/src/main/java/org/elasticsearch/cluster/SnapshotsInProgress.java index 3385cfc6f6b..83c663aa0d3 100644 --- a/core/src/main/java/org/elasticsearch/cluster/SnapshotsInProgress.java +++ b/core/src/main/java/org/elasticsearch/cluster/SnapshotsInProgress.java @@ -38,6 +38,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static java.util.Collections.unmodifiableMap; + /** * Meta data about snapshots that are currently executing */ @@ -67,12 +69,12 @@ public class SnapshotsInProgress extends AbstractDiffable implements Cus private final State state; private final SnapshotId snapshotId; private final boolean includeGlobalState; - private final ImmutableMap shards; + private final Map shards; private final List indices; - private final ImmutableMap> waitingIndices; + private final Map> waitingIndices; private final long startTime; - public Entry(SnapshotId snapshotId, boolean includeGlobalState, State state, List indices, long startTime, ImmutableMap shards) { + public Entry(SnapshotId snapshotId, boolean includeGlobalState, State state, List indices, long startTime, Map shards) { this.state = state; this.snapshotId = snapshotId; this.includeGlobalState = includeGlobalState; @@ -82,16 +84,16 @@ public class SnapshotsInProgress extends AbstractDiffable implements Cus this.shards = ImmutableMap.of(); this.waitingIndices = ImmutableMap.of(); } else { - this.shards = shards; + this.shards = unmodifiableMap(shards); this.waitingIndices = findWaitingIndices(shards); } } - public Entry(Entry entry, State state, ImmutableMap shards) { + public Entry(Entry entry, State state, Map shards) { this(entry.snapshotId, entry.includeGlobalState, state, entry.indices, entry.startTime, shards); } - public Entry(Entry entry, ImmutableMap shards) { + public Entry(Entry entry, Map shards) { this(entry, entry.state, shards); } @@ -99,7 +101,7 @@ public class SnapshotsInProgress extends AbstractDiffable implements Cus return this.snapshotId; } - public ImmutableMap shards() { + public Map shards() { return this.shards; } @@ -111,7 +113,7 @@ public class SnapshotsInProgress extends AbstractDiffable implements Cus return indices; } - public ImmutableMap> waitingIndices() { + public Map> waitingIndices() { return waitingIndices; } @@ -153,7 +155,7 @@ public class SnapshotsInProgress extends AbstractDiffable implements Cus return result; } - private ImmutableMap> findWaitingIndices(ImmutableMap shards) { + private ImmutableMap> findWaitingIndices(Map shards) { Map> waitingIndicesMap = new HashMap<>(); for (ImmutableMap.Entry entry : shards.entrySet()) { if (entry.getValue().state() == State.WAITING) { diff --git a/core/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java b/core/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java index 8d902f678c0..2352a363a42 100644 --- a/core/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java +++ b/core/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java @@ -45,11 +45,11 @@ public class ClusterBlocks extends AbstractDiffable { private final ImmutableSet global; - private final ImmutableMap> indicesBlocks; + private final Map> indicesBlocks; private final ImmutableLevelHolder[] levelHolders; - ClusterBlocks(ImmutableSet global, ImmutableMap> indicesBlocks) { + ClusterBlocks(ImmutableSet global, Map> indicesBlocks) { this.global = global; this.indicesBlocks = indicesBlocks; @@ -83,7 +83,7 @@ public class ClusterBlocks extends AbstractDiffable { return global; } - public ImmutableMap> indices() { + public Map> indices() { return indicesBlocks; } @@ -91,7 +91,7 @@ public class ClusterBlocks extends AbstractDiffable { return levelHolders[level.id()].global(); } - public ImmutableMap> indices(ClusterBlockLevel level) { + public Map> indices(ClusterBlockLevel level) { return levelHolders[level.id()].indices(); } diff --git a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java index ca1ccbd9549..ebf1bcb4f13 100644 --- a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -100,7 +100,7 @@ public class DiscoveryNode implements Streamable, ToXContent { private String hostName; private String hostAddress; private TransportAddress address; - private ImmutableMap attributes; + private Map attributes; private Version version = Version.CURRENT; DiscoveryNode() { @@ -120,7 +120,7 @@ public class DiscoveryNode implements Streamable, ToXContent { * @param version the version of the node. */ public DiscoveryNode(String nodeId, TransportAddress address, Version version) { - this("", nodeId, address, ImmutableMap.of(), version); + this("", nodeId, address, Collections.emptyMap(), version); } /** @@ -230,14 +230,14 @@ public class DiscoveryNode implements Streamable, ToXContent { /** * The node attributes. */ - public ImmutableMap attributes() { + public Map attributes() { return this.attributes; } /** * The node attributes. */ - public ImmutableMap getAttributes() { + public Map getAttributes() { return attributes(); } diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java index 32c50b3fd1f..7a8c33ed70f 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java @@ -21,6 +21,7 @@ package org.elasticsearch.cluster.routing; import com.carrotsearch.hppc.IntSet; import com.google.common.collect.ImmutableMap; + import org.elasticsearch.cluster.Diff; import org.elasticsearch.cluster.Diffable; import org.elasticsearch.cluster.DiffableUtils; @@ -32,9 +33,16 @@ import org.elasticsearch.common.util.iterable.Iterables; import org.elasticsearch.index.IndexNotFoundException; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.function.Predicate; +import static java.util.Collections.unmodifiableMap; + /** * Represents a global cluster-wide routing table for all indices including the * version of the current routing state. @@ -50,11 +58,11 @@ public class RoutingTable implements Iterable, Diffable indicesRouting; + private final Map indicesRouting; RoutingTable(long version, Map indicesRouting) { this.version = version; - this.indicesRouting = ImmutableMap.copyOf(indicesRouting); + this.indicesRouting = unmodifiableMap(indicesRouting); } /** @@ -304,7 +312,7 @@ public class RoutingTable implements Iterable, Diffable> indicesRouting; + private final Diff> indicesRouting; public RoutingTableDiff(RoutingTable before, RoutingTable after) { version = after.version; @@ -313,7 +321,7 @@ public class RoutingTable implements Iterable, Diffable, Object> exposedKeysToSources; + private Map, Object> exposedKeysToSources; private Injector injector; public PrivateElementsImpl(Object source) { diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java index bf8c1a83c92..ad3b9c9be9c 100644 --- a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java +++ b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java @@ -49,8 +49,8 @@ public class BlobStoreIndexShardSnapshots implements Iterable, To public static final BlobStoreIndexShardSnapshots PROTO = new BlobStoreIndexShardSnapshots(); private final List shardSnapshots; - private final ImmutableMap files; - private final ImmutableMap> physicalFiles; + private final Map files; + private final Map> physicalFiles; public BlobStoreIndexShardSnapshots(List shardSnapshots) { this.shardSnapshots = Collections.unmodifiableList(new ArrayList<>(shardSnapshots)); @@ -108,8 +108,8 @@ public class BlobStoreIndexShardSnapshots implements Iterable, To private BlobStoreIndexShardSnapshots() { shardSnapshots = Collections.emptyList(); - files = ImmutableMap.of(); - physicalFiles = ImmutableMap.of(); + files = Collections.emptyMap(); + physicalFiles = Collections.emptyMap(); } diff --git a/core/src/main/java/org/elasticsearch/index/store/Store.java b/core/src/main/java/org/elasticsearch/index/store/Store.java index 09f8ec23adc..0136c739761 100644 --- a/core/src/main/java/org/elasticsearch/index/store/Store.java +++ b/core/src/main/java/org/elasticsearch/index/store/Store.java @@ -737,7 +737,7 @@ public class Store extends AbstractIndexShardComponent implements Closeable, Ref public static final MetadataSnapshot EMPTY = new MetadataSnapshot(); - private final ImmutableMap commitUserData; + private final Map commitUserData; private final long numDocs; diff --git a/core/src/main/java/org/elasticsearch/monitor/jvm/DeadlockAnalyzer.java b/core/src/main/java/org/elasticsearch/monitor/jvm/DeadlockAnalyzer.java index fe3cbc1d15c..58e71896c68 100644 --- a/core/src/main/java/org/elasticsearch/monitor/jvm/DeadlockAnalyzer.java +++ b/core/src/main/java/org/elasticsearch/monitor/jvm/DeadlockAnalyzer.java @@ -70,7 +70,7 @@ public class DeadlockAnalyzer { } - private Set> calculateCycles(ImmutableMap threadInfoMap) { + private Set> calculateCycles(Map threadInfoMap) { Set> cycles = new HashSet<>(); for (Map.Entry entry : threadInfoMap.entrySet()) { LinkedHashSet cycle = new LinkedHashSet<>(); diff --git a/core/src/main/java/org/elasticsearch/node/service/NodeService.java b/core/src/main/java/org/elasticsearch/node/service/NodeService.java index 19647539b61..369f7e084bf 100644 --- a/core/src/main/java/org/elasticsearch/node/service/NodeService.java +++ b/core/src/main/java/org/elasticsearch/node/service/NodeService.java @@ -20,6 +20,7 @@ package org.elasticsearch.node.service; import com.google.common.collect.ImmutableMap; + import org.elasticsearch.Build; import org.elasticsearch.Version; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; @@ -41,6 +42,7 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import java.io.IOException; +import java.util.Map; /** */ @@ -101,7 +103,7 @@ public class NodeService extends AbstractComponent { /** * Attributes different services in the node can add to be reported as part of the node info (for example). */ - public ImmutableMap attributes() { + public Map attributes() { return this.serviceAttributes; } diff --git a/core/src/main/java/org/elasticsearch/repositories/RepositoriesService.java b/core/src/main/java/org/elasticsearch/repositories/RepositoriesService.java index 9cea2e90ee1..d485e472763 100644 --- a/core/src/main/java/org/elasticsearch/repositories/RepositoriesService.java +++ b/core/src/main/java/org/elasticsearch/repositories/RepositoriesService.java @@ -58,7 +58,7 @@ public class RepositoriesService extends AbstractComponent implements ClusterSta private final VerifyNodeRepositoryAction verifyAction; - private volatile ImmutableMap repositories = ImmutableMap.of(); + private volatile Map repositories = ImmutableMap.of(); @Inject public RepositoriesService(Settings settings, ClusterService clusterService, TransportService transportService, RepositoryTypesRegistry typesRegistry, Injector injector) { diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetFieldMappingAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetFieldMappingAction.java index eb53129b5d0..7594a097c94 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetFieldMappingAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetFieldMappingAction.java @@ -19,7 +19,6 @@ package org.elasticsearch.rest.action.admin.indices.mapping.get; -import com.google.common.collect.ImmutableMap; import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest; import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse; import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetaData; @@ -29,7 +28,13 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.rest.*; +import org.elasticsearch.rest.BaseRestHandler; +import org.elasticsearch.rest.BytesRestResponse; +import org.elasticsearch.rest.RestChannel; +import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestResponse; +import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.support.RestBuilderListener; import java.io.IOException; @@ -64,11 +69,9 @@ public class RestGetFieldMappingAction extends BaseRestHandler { getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions())); getMappingsRequest.local(request.paramAsBoolean("local", getMappingsRequest.local())); client.admin().indices().getFieldMappings(getMappingsRequest, new RestBuilderListener(channel) { - - @SuppressWarnings("unchecked") @Override public RestResponse buildResponse(GetFieldMappingsResponse response, XContentBuilder builder) throws Exception { - ImmutableMap>> mappingsByIndex = response.mappings(); + Map>> mappingsByIndex = response.mappings(); boolean isPossibleSingleFieldRequest = indices.length == 1 && types.length == 1 && fields.length == 1; if (isPossibleSingleFieldRequest && isFieldMappingMissingField(mappingsByIndex)) { @@ -91,13 +94,13 @@ public class RestGetFieldMappingAction extends BaseRestHandler { * Helper method to find out if the only included fieldmapping metadata is typed NULL, which means * that type and index exist, but the field did not */ - private boolean isFieldMappingMissingField(ImmutableMap>> mappingsByIndex) throws IOException { + private boolean isFieldMappingMissingField(Map>> mappingsByIndex) throws IOException { if (mappingsByIndex.size() != 1) { return false; } - for (ImmutableMap> value : mappingsByIndex.values()) { - for (ImmutableMap fieldValue : value.values()) { + for (Map> value : mappingsByIndex.values()) { + for (Map fieldValue : value.values()) { for (Map.Entry fieldMappingMetaDataEntry : fieldValue.entrySet()) { if (fieldMappingMetaDataEntry.getValue().isNull()) { return true; diff --git a/core/src/main/java/org/elasticsearch/rest/action/cat/RestNodeAttrsAction.java b/core/src/main/java/org/elasticsearch/rest/action/cat/RestNodeAttrsAction.java index c9d3a2dcd62..4193208a363 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/cat/RestNodeAttrsAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/cat/RestNodeAttrsAction.java @@ -18,7 +18,6 @@ */ package org.elasticsearch.rest.action.cat; -import com.google.common.collect.ImmutableMap; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; @@ -34,11 +33,16 @@ import org.elasticsearch.common.Table; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; -import org.elasticsearch.rest.*; +import org.elasticsearch.rest.RestChannel; +import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.support.RestActionListener; import org.elasticsearch.rest.action.support.RestResponseListener; import org.elasticsearch.rest.action.support.RestTable; +import java.util.Map; + import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestNodeAttrsAction extends AbstractCatAction { @@ -107,7 +111,7 @@ public class RestNodeAttrsAction extends AbstractCatAction { for (DiscoveryNode node : nodes) { NodeInfo info = nodesInfo.getNodesMap().get(node.id()); - ImmutableMap attrs = node.getAttributes(); + Map attrs = node.getAttributes(); for(String att : attrs.keySet()) { table.startRow(); table.addCell(node.name()); diff --git a/core/src/main/java/org/elasticsearch/search/fetch/matchedqueries/MatchedQueriesFetchSubPhase.java b/core/src/main/java/org/elasticsearch/search/fetch/matchedqueries/MatchedQueriesFetchSubPhase.java index 87965321af4..2824bc17e30 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/matchedqueries/MatchedQueriesFetchSubPhase.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/matchedqueries/MatchedQueriesFetchSubPhase.java @@ -79,7 +79,7 @@ public class MatchedQueriesFetchSubPhase implements FetchSubPhase { hitContext.hit().matchedQueries(matchedQueries.toArray(new String[matchedQueries.size()])); } - private void addMatchedQueries(HitContext hitContext, ImmutableMap namedQueries, List matchedQueries) throws IOException { + private void addMatchedQueries(HitContext hitContext, Map namedQueries, List matchedQueries) throws IOException { for (Map.Entry entry : namedQueries.entrySet()) { String name = entry.getKey(); Query filter = entry.getValue(); diff --git a/core/src/main/java/org/elasticsearch/search/lookup/LeafSearchLookup.java b/core/src/main/java/org/elasticsearch/search/lookup/LeafSearchLookup.java index 6f976a5ccb1..5e411546622 100644 --- a/core/src/main/java/org/elasticsearch/search/lookup/LeafSearchLookup.java +++ b/core/src/main/java/org/elasticsearch/search/lookup/LeafSearchLookup.java @@ -19,12 +19,13 @@ package org.elasticsearch.search.lookup; -import com.google.common.collect.ImmutableMap; - import org.apache.lucene.index.LeafReaderContext; +import java.util.HashMap; import java.util.Map; +import static java.util.Collections.unmodifiableMap; + /** * Per-segment version of {@link SearchLookup}. */ @@ -35,7 +36,7 @@ public class LeafSearchLookup { final SourceLookup sourceLookup; final LeafFieldsLookup fieldsLookup; final LeafIndexLookup indexLookup; - final ImmutableMap asMap; + final Map asMap; public LeafSearchLookup(LeafReaderContext ctx, LeafDocLookup docMap, SourceLookup sourceLookup, LeafFieldsLookup fieldsLookup, LeafIndexLookup indexLookup, Map topLevelMap) { @@ -45,17 +46,17 @@ public class LeafSearchLookup { this.fieldsLookup = fieldsLookup; this.indexLookup = indexLookup; - ImmutableMap.Builder builder = ImmutableMap.builder(); - builder.putAll(topLevelMap); - builder.put("doc", docMap); - builder.put("_doc", docMap); - builder.put("_source", sourceLookup); - builder.put("_fields", fieldsLookup); - builder.put("_index", indexLookup); - asMap = builder.build(); + Map asMap = new HashMap<>(topLevelMap.size() + 5); + asMap.putAll(topLevelMap); + asMap.put("doc", docMap); + asMap.put("_doc", docMap); + asMap.put("_source", sourceLookup); + asMap.put("_fields", fieldsLookup); + asMap.put("_index", indexLookup); + this.asMap = unmodifiableMap(asMap); } - public ImmutableMap asMap() { + public Map asMap() { return this.asMap; } diff --git a/core/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java b/core/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java index 58a98c30d7a..3502916aae3 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java +++ b/core/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java @@ -91,7 +91,7 @@ public class SnapshotShardsService extends AbstractLifecycleComponent shardSnapshots = ImmutableMap.of(); + private volatile Map shardSnapshots = ImmutableMap.of(); private final BlockingQueue updatedSnapshotStateQueue = ConcurrentCollections.newBlockingQueue(); @@ -368,7 +368,7 @@ public class SnapshotShardsService extends AbstractLifecycleComponent localShards = currentSnapshotShards(snapshot.snapshotId()); if (localShards != null) { - ImmutableMap masterShards = snapshot.shards(); + Map masterShards = snapshot.shards(); for(Map.Entry localShard : localShards.entrySet()) { ShardId shardId = localShard.getKey(); IndexShardSnapshotStatus localShardStatus = localShard.getValue(); diff --git a/core/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java b/core/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java index 947ca2fa071..d89d26015c2 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java +++ b/core/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java @@ -596,7 +596,7 @@ public class SnapshotsService extends AbstractLifecycleComponent shards = processWaitingShards(snapshot.shards(), routingTable); + Map shards = processWaitingShards(snapshot.shards(), routingTable); if (shards != null) { changed = true; if (!snapshot.state().completed() && completed(shards.values())) { @@ -625,7 +625,7 @@ public class SnapshotsService extends AbstractLifecycleComponent processWaitingShards(ImmutableMap snapshotShards, RoutingTable routingTable) { + private Map processWaitingShards(Map snapshotShards, RoutingTable routingTable) { boolean snapshotChanged = false; ImmutableMap.Builder shards = ImmutableMap.builder(); for (ImmutableMap.Entry shardEntry : snapshotShards.entrySet()) { @@ -716,10 +716,10 @@ public class SnapshotsService extends AbstractLifecycleComponent, Set> indicesWithMissingShards(ImmutableMap shards, MetaData metaData) { + private Tuple, Set> indicesWithMissingShards(Map shards, MetaData metaData) { Set missing = new HashSet<>(); Set closed = new HashSet<>(); - for (ImmutableMap.Entry entry : shards.entrySet()) { + for (Map.Entry entry : shards.entrySet()) { if (entry.getValue().state() == State.MISSING) { if (metaData.hasIndex(entry.getKey().getIndex()) && metaData.index(entry.getKey().getIndex()).getState() == IndexMetaData.State.CLOSE) { closed.add(entry.getKey().getIndex()); @@ -864,7 +864,7 @@ public class SnapshotsService extends AbstractLifecycleComponent shards; + Map shards; if (snapshot.state() == State.STARTED && snapshot.shards() != null) { // snapshot is currently running - stop started shards ImmutableMap.Builder shardsBuilder = ImmutableMap.builder(); diff --git a/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java b/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java index 107a6034135..85de5f6ec06 100644 --- a/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java +++ b/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java @@ -91,7 +91,7 @@ public class ThreadPool extends AbstractComponent { private volatile ImmutableMap executors; - private final ImmutableMap defaultExecutorTypeSettings; + private final Map defaultExecutorTypeSettings; private final Queue retiredExecutors = new ConcurrentLinkedQueue<>(); diff --git a/core/src/main/java/org/elasticsearch/transport/TransportService.java b/core/src/main/java/org/elasticsearch/transport/TransportService.java index 172a34e7e43..507e02d5298 100644 --- a/core/src/main/java/org/elasticsearch/transport/TransportService.java +++ b/core/src/main/java/org/elasticsearch/transport/TransportService.java @@ -67,7 +67,7 @@ public class TransportService extends AbstractLifecycleComponent requestHandlers = ImmutableMap.of(); + volatile Map requestHandlers = Collections.emptyMap(); final Object requestHandlerMutex = new Object(); final ConcurrentMapLong clientHandlers = ConcurrentCollections.newConcurrentMapLongWithAggressiveConcurrency(); diff --git a/core/src/test/java/org/elasticsearch/benchmark/common/recycler/RecyclerBenchmark.java b/core/src/test/java/org/elasticsearch/benchmark/common/recycler/RecyclerBenchmark.java index 97113a6d1c5..9710605aa6d 100644 --- a/core/src/test/java/org/elasticsearch/benchmark/common/recycler/RecyclerBenchmark.java +++ b/core/src/test/java/org/elasticsearch/benchmark/common/recycler/RecyclerBenchmark.java @@ -19,17 +19,22 @@ package org.elasticsearch.benchmark.common.recycler; -import com.google.common.collect.ImmutableMap; import org.elasticsearch.common.recycler.AbstractRecyclerC; import org.elasticsearch.common.recycler.Recycler; +import java.util.HashMap; import java.util.Map; import java.util.Random; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; -import static org.elasticsearch.common.recycler.Recyclers.*; +import static org.elasticsearch.common.recycler.Recyclers.concurrent; +import static org.elasticsearch.common.recycler.Recyclers.concurrentDeque; +import static org.elasticsearch.common.recycler.Recyclers.deque; +import static org.elasticsearch.common.recycler.Recyclers.dequeFactory; +import static org.elasticsearch.common.recycler.Recyclers.locked; +import static org.elasticsearch.common.recycler.Recyclers.none; /** Benchmark that tries to measure the overhead of object recycling depending on concurrent access. */ public class RecyclerBenchmark { @@ -89,11 +94,11 @@ public class RecyclerBenchmark { } }; - final ImmutableMap> recyclers = ImmutableMap.>builder() - .put("none", none(c)) - .put("concurrent-queue", concurrentDeque(c, limit)) - .put("locked", locked(deque(c, limit))) - .put("concurrent", concurrent(dequeFactory(c, limit), Runtime.getRuntime().availableProcessors())).build(); + Map> recyclers = new HashMap<>(); + recyclers.put("none", none(c)); + recyclers.put("concurrent-queue", concurrentDeque(c, limit)); + recyclers.put("locked", locked(deque(c, limit))); + recyclers.put("concurrent", concurrent(dequeFactory(c, limit), Runtime.getRuntime().availableProcessors())); // warmup final long start = System.nanoTime(); diff --git a/core/src/test/java/org/elasticsearch/cluster/serialization/DiffableTests.java b/core/src/test/java/org/elasticsearch/cluster/serialization/DiffableTests.java index b7029bfc736..fe782f12a75 100644 --- a/core/src/test/java/org/elasticsearch/cluster/serialization/DiffableTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/serialization/DiffableTests.java @@ -41,7 +41,7 @@ import static org.hamcrest.CoreMatchers.equalTo; public class DiffableTests extends ESTestCase { @Test - public void testImmutableMapDiff() throws IOException { + public void testJdkMapDiff() throws IOException { ImmutableMap.Builder builder = ImmutableMap.builder(); builder.put("foo", new TestDiffable("1")); builder.put("bar", new TestDiffable("2")); @@ -57,7 +57,7 @@ public class DiffableTests extends ESTestCase { BytesStreamOutput out = new BytesStreamOutput(); diff.writeTo(out); StreamInput in = StreamInput.wrap(out.bytes()); - ImmutableMap serialized = DiffableUtils.readImmutableMapDiff(in, TestDiffable.PROTO).apply(before); + Map serialized = DiffableUtils.readJdkMapDiff(in, TestDiffable.PROTO).apply(before); assertThat(serialized.size(), equalTo(3)); assertThat(serialized.get("foo").value(), equalTo("1")); assertThat(serialized.get("baz").value(), equalTo("4")); diff --git a/dev-tools/src/main/resources/forbidden/all-signatures.txt b/dev-tools/src/main/resources/forbidden/all-signatures.txt index de168dc1b5f..60a07c0c0da 100644 --- a/dev-tools/src/main/resources/forbidden/all-signatures.txt +++ b/dev-tools/src/main/resources/forbidden/all-signatures.txt @@ -127,6 +127,7 @@ com.google.common.collect.HashMultimap com.google.common.collect.FluentIterable com.google.common.io.Files com.google.common.primitives.Ints +com.google.common.collect.ImmutableMap#entrySet() @defaultMessage Do not violate java's access system java.lang.reflect.AccessibleObject#setAccessible(boolean)