use of org.apache.ratis.server.RaftServer in project incubator-ratis by apache.
the class Server method run.
@Override
public void run() throws Exception {
RaftPeerId peerId = RaftPeerId.valueOf(id);
RaftProperties properties = new RaftProperties();
RaftPeer[] peers = getPeers();
final int port = NetUtils.createSocketAddr(getPeer(peerId).getAddress()).getPort();
GrpcConfigKeys.Server.setPort(properties, port);
properties.setInt(GrpcConfigKeys.OutputStream.RETRY_TIMES_KEY, Integer.MAX_VALUE);
RaftServerConfigKeys.setStorageDir(properties, storageDir);
StateMachine stateMachine = new ArithmeticStateMachine();
RaftGroup raftGroup = new RaftGroup(RaftGroupId.valueOf(ByteString.copyFromUtf8(raftGroupId)), peers);
RaftServer raftServer = RaftServer.newBuilder().setServerId(RaftPeerId.valueOf(id)).setStateMachine(stateMachine).setProperties(properties).setGroup(raftGroup).build();
raftServer.start();
}
Aggregations