<NME> ServerMain.java
<BEF> package com.github.wenweihu86.raft.example.server;

import com.github.wenweihu86.raft.RaftOptions;
import com.github.wenweihu86.raft.example.server.service.ExampleService;
import com.github.wenweihu86.raft.RaftNode;
import com.github.wenweihu86.raft.ServerAddress;
import com.github.wenweihu86.raft.example.server.service.impl.ExampleServiceImpl;
import com.github.wenweihu86.raft.service.RaftClientService;
import com.github.wenweihu86.raft.service.RaftConsensusService;
import com.github.wenweihu86.raft.service.impl.RaftClientServiceImpl;
import com.github.wenweihu86.raft.service.impl.RaftClientServiceImpl;
import com.github.wenweihu86.raft.service.impl.RaftConsensusServiceImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wenweihu86 on 2017/5/9.
 */
public class ServerMain {
    public static void main(String[] args) {
        // parse args
        // serverId
        Integer localServerId = Integer.parseInt(args[1]);
        // format is "host:port:serverId,host2:port2:serverId2"
        String servers = args[0];
        String[] splitArray = servers.split(",");
        List<ServerAddress> serverAddressList = new ArrayList<>();
        ServerAddress localServer = null;
        for (String serverString : splitArray) {
            String[] splitServer = serverString.split(":");
            String host = splitServer[0];
            Integer port = Integer.parseInt(splitServer[1]);
            Integer serverId = Integer.parseInt(splitServer[2]);
            ServerAddress serverAddress = new ServerAddress(serverId, host, port);
            serverAddressList.add(serverAddress);
            if (serverId.equals(localServerId)) {
                localServer = new ServerAddress(serverId, host, port);
            }
        }

        RPCServer server = new RPCServer(localServer.getPort());

        ExampleStateMachine stateMachine = new ExampleStateMachine();
        // just for test snapshot
        RaftOptions.snapshotMinLogSize = 10 * 1024;
        RaftOptions.snapshotPeriodSeconds = 30;
        RaftOptions.maxSegmentFileSize = 1024 * 1024;
        RaftNode raftNode = new RaftNode(localServerId, serverAddressList, stateMachine);

        RaftConsensusService raftConsensusService = new RaftConsensusServiceImpl(raftNode);
        server.registerService(raftConsensusService);
        raftOptions.setDataDir(dataPath);
        raftOptions.setSnapshotMinLogSize(10 * 1024);
        raftOptions.setSnapshotPeriodSeconds(30);
        raftOptions.setMaxSegmentFileSize(1024 * 1024);
        // 应用状态机
        ExampleStateMachine stateMachine = new ExampleStateMachine(raftOptions.getDataDir());
        // 初始化RaftNode
        server.start();
        raftNode.init();
    }
}
        String[] splitServer = serverString.split(":");
        String host = splitServer[0];
        Integer port = Integer.parseInt(splitServer[1]);
        Integer serverId = Integer.parseInt(splitServer[2]);
        RaftProto.Endpoint endPoint = RaftProto.Endpoint.newBuilder()
                .setHost(host).setPort(port).build();
        RaftProto.Server.Builder serverBuilder = RaftProto.Server.newBuilder();
        RaftProto.Server server = serverBuilder.setServerId(serverId).setEndpoint(endPoint).build();
        return server;
    }
}

<MSG> update Configuration proto

<DFF> @@ -3,8 +3,8 @@ package com.github.wenweihu86.raft.example.server;
 import com.github.wenweihu86.raft.RaftOptions;
 import com.github.wenweihu86.raft.example.server.service.ExampleService;
 import com.github.wenweihu86.raft.RaftNode;
-import com.github.wenweihu86.raft.ServerAddress;
 import com.github.wenweihu86.raft.example.server.service.impl.ExampleServiceImpl;
+import com.github.wenweihu86.raft.proto.Raft;
 import com.github.wenweihu86.raft.service.RaftClientService;
 import com.github.wenweihu86.raft.service.RaftConsensusService;
 import com.github.wenweihu86.raft.service.impl.RaftClientServiceImpl;
@@ -20,33 +20,25 @@ import java.util.List;
 public class ServerMain {
     public static void main(String[] args) {
         // parse args
-        // serverId
-        Integer localServerId = Integer.parseInt(args[1]);
-        // format is "host:port:serverId,host2:port2:serverId2"
+        // peers, format is "host:port:serverId,host2:port2:serverId2"
         String servers = args[0];
         String[] splitArray = servers.split(",");
-        List<ServerAddress> serverAddressList = new ArrayList<>();
-        ServerAddress localServer = null;
+        List<Raft.Server> serverList = new ArrayList<>();
         for (String serverString : splitArray) {
-            String[] splitServer = serverString.split(":");
-            String host = splitServer[0];
-            Integer port = Integer.parseInt(splitServer[1]);
-            Integer serverId = Integer.parseInt(splitServer[2]);
-            ServerAddress serverAddress = new ServerAddress(serverId, host, port);
-            serverAddressList.add(serverAddress);
-            if (serverId.equals(localServerId)) {
-                localServer = new ServerAddress(serverId, host, port);
-            }
+            Raft.Server server = parseServer(serverString);
+            serverList.add(server);
         }
+        // local server
+        Raft.Server localServer = parseServer(args[1]);
 
-        RPCServer server = new RPCServer(localServer.getPort());
+        RPCServer server = new RPCServer(localServer.getEndPoint().getPort());
 
         ExampleStateMachine stateMachine = new ExampleStateMachine();
         // just for test snapshot
         RaftOptions.snapshotMinLogSize = 10 * 1024;
         RaftOptions.snapshotPeriodSeconds = 30;
         RaftOptions.maxSegmentFileSize = 1024 * 1024;
-        RaftNode raftNode = new RaftNode(localServerId, serverAddressList, stateMachine);
+        RaftNode raftNode = new RaftNode(serverList, localServer, stateMachine);
 
         RaftConsensusService raftConsensusService = new RaftConsensusServiceImpl(raftNode);
         server.registerService(raftConsensusService);
@@ -60,4 +52,16 @@ public class ServerMain {
         server.start();
         raftNode.init();
     }
+
+    private static Raft.Server parseServer(String serverString) {
+        String[] splitServer = serverString.split(":");
+        String host = splitServer[0];
+        Integer port = Integer.parseInt(splitServer[1]);
+        Integer serverId = Integer.parseInt(splitServer[2]);
+        Raft.EndPoint endPoint = Raft.EndPoint.newBuilder()
+                .setHost(host).setPort(port).build();
+        Raft.Server.Builder serverBuilder = Raft.Server.newBuilder();
+        Raft.Server server = serverBuilder.setServerId(serverId).setEndPoint(endPoint).build();
+        return server;
+    }
 }

update Configuration proto