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

com.hazelcast.cp.internal.raft.impl.persistence.RestoredRaftState Maven / Gradle / Ivy

There is a newer version: 5.5.0
Show newest version
/*
 * Copyright (c) 2008-2023, Hazelcast, Inc. All Rights Reserved.
 *
 * 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 com.hazelcast.cp.internal.raft.impl.persistence;

import com.hazelcast.cp.internal.raft.impl.RaftEndpoint;
import com.hazelcast.cp.internal.raft.impl.RaftNode;
import com.hazelcast.cp.internal.raft.impl.log.LogEntry;
import com.hazelcast.cp.internal.raft.impl.log.SnapshotEntry;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;

/**
 * Contains persisted and restored state of a {@link RaftNode}.
 */
public class RestoredRaftState {

    private final RaftEndpoint localEndpoint;
    private final Collection initialMembers;
    private final int term;
    private final RaftEndpoint votedFor;
    private final SnapshotEntry snapshot;
    private final LogEntry[] entries;

    @SuppressFBWarnings("EI_EXPOSE_REP2")
    public RestoredRaftState(
            @Nonnull RaftEndpoint localEndpoint,
            @Nonnull Collection initialMembers,
            int term,
            @Nullable RaftEndpoint votedFor,
            @Nullable SnapshotEntry snapshot,
            @Nonnull LogEntry[] entries
    ) {
        this.localEndpoint = localEndpoint;
        this.initialMembers = initialMembers;
        this.term = term;
        this.votedFor = votedFor;
        this.snapshot = snapshot;
        this.entries = entries;
    }

    @Nonnull
    public RaftEndpoint localEndpoint() {
        return localEndpoint;
    }

    @Nonnull
    public Collection initialMembers() {
        return initialMembers;
    }

    public int term() {
        return term;
    }

    @Nullable
    public RaftEndpoint votedFor() {
        return votedFor;
    }

    @Nullable
    public SnapshotEntry snapshot() {
        return snapshot;
    }

    @Nonnull
    @SuppressFBWarnings("EI_EXPOSE_REP")
    public LogEntry[] entries() {
        return entries;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy