Search in sources :

Example 1 with ArithmeticStateMachine

use of org.apache.ratis.examples.arithmetic.ArithmeticStateMachine 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();
}
Also used : StateMachine(org.apache.ratis.statemachine.StateMachine) ArithmeticStateMachine(org.apache.ratis.examples.arithmetic.ArithmeticStateMachine) RaftServer(org.apache.ratis.server.RaftServer) RaftProperties(org.apache.ratis.conf.RaftProperties) ArithmeticStateMachine(org.apache.ratis.examples.arithmetic.ArithmeticStateMachine) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) RaftGroup(org.apache.ratis.protocol.RaftGroup) RaftPeer(org.apache.ratis.protocol.RaftPeer)

Aggregations

RaftProperties (org.apache.ratis.conf.RaftProperties)1 ArithmeticStateMachine (org.apache.ratis.examples.arithmetic.ArithmeticStateMachine)1 RaftGroup (org.apache.ratis.protocol.RaftGroup)1 RaftPeer (org.apache.ratis.protocol.RaftPeer)1 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)1 RaftServer (org.apache.ratis.server.RaftServer)1 StateMachine (org.apache.ratis.statemachine.StateMachine)1