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

io.trino.metadata.InternalNodeManager Maven / Gradle / Ivy

There is a newer version: 465
Show newest version
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.trino.metadata;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.SetMultimap;
import io.trino.spi.connector.CatalogHandle;

import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;

import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;

public interface InternalNodeManager
{
    Set getNodes(NodeState state);

    Set getActiveCatalogNodes(CatalogHandle catalogHandle);

    NodesSnapshot getActiveNodesSnapshot();

    InternalNode getCurrentNode();

    Set getCoordinators();

    AllNodes getAllNodes();

    void refreshNodes();

    void addNodeChangeListener(Consumer listener);

    void removeNodeChangeListener(Consumer listener);

    class NodesSnapshot
    {
        private final Set allNodes;
        private final Optional> connectorNodes;

        public NodesSnapshot(Set allActiveNodes, Optional> activeNodesByCatalogName)
        {
            requireNonNull(allActiveNodes, "allActiveNodes is null");
            requireNonNull(activeNodesByCatalogName, "activeNodesByCatalogName is null");
            this.allNodes = ImmutableSet.copyOf(allActiveNodes);
            this.connectorNodes = activeNodesByCatalogName.map(ImmutableSetMultimap::copyOf);
        }

        public Set getAllNodes()
        {
            return allNodes;
        }

        public Set getConnectorNodes(CatalogHandle catalogHandle)
        {
            return connectorNodes
                    .map(map -> map.get(catalogHandle))
                    .orElse(allNodes);
        }

        @Override
        public String toString()
        {
            return toStringHelper(this)
                    .add("allNodes", allNodes)
                    .add("connectorNodes", connectorNodes.orElse(null))
                    .toString();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy