Browse Source

Fix type inference issue in eclipse (#44212)

Explicitely type lister, since Eclipses compiler is not able to correctly infer
the function type otherwise.
Christoph Büscher 6 years ago
parent
commit
a4d1a99378

+ 4 - 1
server/src/main/java/org/elasticsearch/action/admin/indices/shards/TransportIndicesShardStoresAction.java

@@ -45,6 +45,7 @@ import org.elasticsearch.common.collect.ImmutableOpenMap;
 import org.elasticsearch.common.inject.Inject;
 import org.elasticsearch.common.util.concurrent.CountDown;
 import org.elasticsearch.gateway.AsyncShardFetch;
+import org.elasticsearch.gateway.AsyncShardFetch.Lister;
 import org.elasticsearch.gateway.TransportNodesListGatewayStartedShards;
 import org.elasticsearch.gateway.TransportNodesListGatewayStartedShards.NodeGatewayStartedShards;
 import org.elasticsearch.index.shard.ShardId;
@@ -148,8 +149,10 @@ public class TransportIndicesShardStoresAction
             if (shardIds.isEmpty()) {
                 listener.onResponse(new IndicesShardStoresResponse());
             } else {
+                // explicitely type lister, some IDEs (Eclipse) are not able to correctly infer the function type
+                Lister<BaseNodesResponse<NodeGatewayStartedShards>, NodeGatewayStartedShards> lister = this::listStartedShards;
                 for (ShardId shardId : shardIds) {
-                    InternalAsyncFetch fetch = new InternalAsyncFetch(logger, "shard_stores", shardId, this::listStartedShards);
+                    InternalAsyncFetch fetch = new InternalAsyncFetch(logger, "shard_stores", shardId, lister);
                     fetch.fetchData(nodes, Collections.<String>emptySet());
                 }
             }

+ 8 - 4
server/src/main/java/org/elasticsearch/gateway/GatewayAllocator.java

@@ -36,6 +36,7 @@ import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
 import org.elasticsearch.common.inject.Inject;
 import org.elasticsearch.common.lease.Releasables;
 import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
+import org.elasticsearch.gateway.AsyncShardFetch.Lister;
 import org.elasticsearch.gateway.TransportNodesListGatewayStartedShards.NodeGatewayStartedShards;
 import org.elasticsearch.index.shard.ShardId;
 import org.elasticsearch.indices.store.TransportNodesListShardStoreMetaData;
@@ -157,9 +158,11 @@ public class GatewayAllocator {
 
         @Override
         protected AsyncShardFetch.FetchResult<NodeGatewayStartedShards> fetchData(ShardRouting shard, RoutingAllocation allocation) {
+            // explicitely type lister, some IDEs (Eclipse) are not able to correctly infer the function type
+            Lister<BaseNodesResponse<NodeGatewayStartedShards>, NodeGatewayStartedShards> lister = this::listStartedShards;
             AsyncShardFetch<NodeGatewayStartedShards> fetch =
                 asyncFetchStarted.computeIfAbsent(shard.shardId(),
-                    shardId -> new InternalAsyncFetch<>(logger, "shard_started", shardId, this::listStartedShards));
+                            shardId -> new InternalAsyncFetch<>(logger, "shard_started", shardId, lister));
             AsyncShardFetch.FetchResult<NodeGatewayStartedShards> shardState =
                     fetch.fetchData(allocation.nodes(), allocation.getIgnoreNodes(shard.shardId()));
 
@@ -188,9 +191,10 @@ public class GatewayAllocator {
         @Override
         protected AsyncShardFetch.FetchResult<NodeStoreFilesMetaData>
                                                                         fetchData(ShardRouting shard, RoutingAllocation allocation) {
-            AsyncShardFetch<NodeStoreFilesMetaData> fetch =
-                asyncFetchStore.computeIfAbsent(shard.shardId(),
-                    shardId -> new InternalAsyncFetch<>(logger, "shard_store", shard.shardId(), this::listStoreFilesMetaData));
+            // explicitely type lister, some IDEs (Eclipse) are not able to correctly infer the function type
+            Lister<BaseNodesResponse<NodeStoreFilesMetaData>, NodeStoreFilesMetaData> lister = this::listStoreFilesMetaData;
+            AsyncShardFetch<NodeStoreFilesMetaData> fetch = asyncFetchStore.computeIfAbsent(shard.shardId(),
+                    shardId -> new InternalAsyncFetch<>(logger, "shard_store", shard.shardId(), lister));
             AsyncShardFetch.FetchResult<NodeStoreFilesMetaData> shardStores =
                     fetch.fetchData(allocation.nodes(), allocation.getIgnoreNodes(shard.shardId()));
             if (shardStores.hasData()) {