/** * Returns a new multi-Raft protocol builder. * * @param group the partition group * @return the multi-Raft protocol builder */ public static MultiRaftProtocolBuilder builder(String group) { return new MultiRaftProtocolBuilder(new MultiRaftProtocolConfig().setGroup(group)); }
@Override public ProxyProtocol newProtocol() { return MultiRaftProtocol.builder(name) .withRecoveryStrategy(Recovery.RECOVER) .withMaxRetries(5) .build(); }
/** * Returns an instance of the multi-Raft protocol with the default configuration. * * @return an instance of the multi-Raft protocol with the default configuration */ public static MultiRaftProtocol instance() { return new MultiRaftProtocol(new MultiRaftProtocolConfig()); }
private RaftClient newRaftClient(RaftClientProtocol protocol) { return RaftClient.builder() .withClientId(partition.name()) .withPartitionId(partition.id()) .withMemberId(localMemberId) .withProtocol(protocol) .withThreadContextFactory(threadContextFactory) .build(); } }
/** * Returns a new multi-Raft protocol builder. * * @return a new multi-Raft protocol builder */ public static MultiRaftProtocolBuilder builder() { return new MultiRaftProtocolBuilder(new MultiRaftProtocolConfig()); }
/** * Closes the server and exits the partition. * * @return future that is completed when the operation is complete */ public CompletableFuture<Void> leave() { return server.leave(); }
/** * Returns whether the server is the leader. * * @return whether the server is the leader */ default boolean isLeader() { return getRole() == Role.LEADER; }
/** * Creates a new exception for the error. * * @return The error exception. */ public PrimitiveException createException() { return type.createException(message); }
/** * Sets the minimum session timeout. * * @param minTimeout the minimum session timeout * @return the Raft protocol builder */ public MultiRaftProtocolBuilder withMinTimeout(Duration minTimeout) { config.setMinTimeout(minTimeout); return this; }
/** * Sets the communication strategy. * * @param communicationStrategy the communication strategy * @return the Raft protocol builder */ public MultiRaftProtocolBuilder withCommunicationStrategy(CommunicationStrategy communicationStrategy) { config.setCommunicationStrategy(communicationStrategy); return this; }
/** * Sets the maximum number of retries before an operation can be failed. * * @param maxRetries the maximum number of retries before an operation can be failed * @return the proxy builder */ public MultiRaftProtocolBuilder withMaxRetries(int maxRetries) { config.setMaxRetries(maxRetries); return this; }
/** * Returns the partition term. * * @return the partition term */ public long term() { return client != null ? client.term() : 0; }
/** * Sets the recovery strategy. * * @param recoveryStrategy the recovery strategy * @return the Raft protocol builder */ public MultiRaftProtocolBuilder withRecoveryStrategy(Recovery recoveryStrategy) { config.setRecoveryStrategy(recoveryStrategy); return this; }
/** * Returns the partition leader. * * @return the partition leader */ public MemberId leader() { return client != null ? client.leader() : null; }
/** * Sets the protocol partitioner. * * @param partitioner the protocol partitioner * @return the protocol builder */ public MultiRaftProtocolBuilder withPartitioner(Partitioner<String> partitioner) { config.setPartitioner(partitioner); return this; }
/** * Sets the maximum session timeout. * * @param maxTimeout the maximum session timeout * @return the Raft protocol builder */ public MultiRaftProtocolBuilder withMaxTimeout(Duration maxTimeout) { config.setMaxTimeout(maxTimeout); return this; }
/** * Sets the read consistency level. * * @param readConsistency the read consistency level * @return the Raft protocol builder */ public MultiRaftProtocolBuilder withReadConsistency(ReadConsistency readConsistency) { config.setReadConsistency(readConsistency); return this; }
/** * Takes a snapshot of the partition server. * * @return a future to be completed once the snapshot has been taken */ public CompletableFuture<Void> snapshot() { return server.compact(); }
/** * Returns the set of known members in the cluster. * * @return The set of known members in the cluster. */ default Collection<MemberId> getServers() { return getMembers(); }
/** * Returns whether the server is a follower. * * @return whether the server is a follower */ default boolean isFollower() { return getRole() == Role.FOLLOWER; }