All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opensearch.gateway.ShardBatchResponseFactory Maven / Gradle / Ivy

There is a newer version: 2.18.0
Show newest version
/*
 * SPDX-License-Identifier: Apache-2.0
 *
 * The OpenSearch Contributors require contributions made to
 * this file be licensed under the Apache-2.0 license or a
 * compatible open source license.
 */

package org.opensearch.gateway;

import org.opensearch.action.support.nodes.BaseNodeResponse;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.core.index.shard.ShardId;
import org.opensearch.gateway.TransportNodesGatewayStartedShardHelper.GatewayStartedShard;
import org.opensearch.gateway.TransportNodesListGatewayStartedShardsBatch.NodeGatewayStartedShardsBatch;
import org.opensearch.indices.store.TransportNodesListShardStoreMetadataBatch.NodeStoreFilesMetadata;
import org.opensearch.indices.store.TransportNodesListShardStoreMetadataBatch.NodeStoreFilesMetadataBatch;

import java.util.Map;

/**
 * A factory class to create new responses of batch transport actions like
 * {@link TransportNodesListGatewayStartedShardsBatch} or {@link org.opensearch.indices.store.TransportNodesListShardStoreMetadataBatch}
 *
 * @param  Node level response returned by batch transport actions.
 * @param  Shard level metadata returned by batch transport actions.
 */
public class ShardBatchResponseFactory {
    private final boolean primary;

    public ShardBatchResponseFactory(boolean primary) {
        this.primary = primary;
    }

    public T getNewResponse(DiscoveryNode node, Map shardData) {
        if (primary) {
            return (T) new NodeGatewayStartedShardsBatch(node, (Map) shardData);
        } else {
            return (T) new NodeStoreFilesMetadataBatch(node, (Map) shardData);
        }
    }

    public Map getShardBatchData(T response) {
        if (primary) {
            return (Map) ((NodeGatewayStartedShardsBatch) response).getNodeGatewayStartedShardsBatch();
        } else {
            return (Map) ((NodeStoreFilesMetadataBatch) response).getNodeStoreFilesMetadataBatch();
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy