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

io.zulia.server.index.federator.MasterSlaveNodeRequestFederator Maven / Gradle / Ivy

There is a newer version: 1.6.4
Show newest version
package io.zulia.server.index.federator;

import io.zulia.message.ZuliaBase;
import io.zulia.message.ZuliaBase.Node;
import io.zulia.message.ZuliaServiceOuterClass.IndexRouting;
import io.zulia.server.exceptions.ShardOfflineException;
import io.zulia.server.index.MasterSlaveSelector;
import io.zulia.server.index.ZuliaIndex;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;

public abstract class MasterSlaveNodeRequestFederator extends NodeRequestFederator {

	private Map> nodeToRouting = new HashMap<>();

	public MasterSlaveNodeRequestFederator(Node thisNode, Collection otherNodesActive, ZuliaBase.MasterSlaveSettings masterSlaveSettings,
			ZuliaIndex index, ExecutorService pool) throws ShardOfflineException {
		this(thisNode, otherNodesActive, masterSlaveSettings, Collections.singletonList(index), pool);
	}

	public MasterSlaveNodeRequestFederator(Node thisNode, Collection otherNodesActive, ZuliaBase.MasterSlaveSettings masterSlaveSettings,
			Collection indexes, ExecutorService pool) throws ShardOfflineException {
		super(thisNode, otherNodesActive, pool);

		List nodesAvailable = new ArrayList<>();
		nodesAvailable.add(thisNode);
		nodesAvailable.addAll(otherNodesActive);

		for (ZuliaIndex index : indexes) {
			io.zulia.message.ZuliaIndex.IndexMapping indexMapping = index.getIndexMapping();
			MasterSlaveSelector masterSlaveSelector = new MasterSlaveSelector(masterSlaveSettings, nodesAvailable, indexMapping);

			Map nodesForIndex = masterSlaveSelector.getNodesForIndex();

			for (Node node : nodesForIndex.keySet()) {
				IndexRouting indexRouting = nodesForIndex.get(node).setIndex(index.getIndexName()).build();
				nodeToRouting.computeIfAbsent(node, (k) -> new ArrayList<>()).add(indexRouting);
				nodes.add(node);
			}

		}
	}

	public List getIndexRouting(Node node) {
		return nodeToRouting.get(node);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy