org.apache.ratis.protocol.RoutingTable Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.ratis.protocol;
import org.apache.ratis.proto.RaftProtos.RoutingTableProto;
import org.apache.ratis.util.JavaUtils;
import org.apache.ratis.util.Preconditions;
import org.apache.ratis.util.ProtoUtils;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
/**
* A routing table is a directed acyclic graph containing exactly one primary peer such that
* (1) the primary peer is the only starting peer, and
* (2) all the other peers can be reached from the primary peer by exactly one path.
*/
public interface RoutingTable {
/** @return the successor peers of the given peer. */
Set getSuccessors(RaftPeerId peerId);
/** @return the primary peer. */
RaftPeerId getPrimary();
/** @return the proto of this {@link RoutingTable}. */
RoutingTableProto toProto();
/** @return a new builder to build a {@link RoutingTable}. */
static Builder newBuilder() {
return new Builder();
}
/** To build a {@link RoutingTable}. */
final class Builder {
private final AtomicReference
© 2015 - 2025 Weber Informatics LLC | Privacy Policy