<NME> ExampleServiceImpl.java
<BEF> package com.github.wenweihu86.raft.example.server.service.impl;

import com.baidu.brpc.client.BrpcProxy;
import com.github.wenweihu86.raft.example.server.service.Example;
import com.github.wenweihu86.raft.example.server.service.ExampleService;
import com.github.wenweihu86.raft.RaftNode;

/**
 * Created by wenweihu86 on 2017/5/9.
 */
public class ExampleServiceImpl implements ExampleService {

    private RaftNode raftNode;
    private ExampleStateMachine stateMachine;

public class ExampleServiceImpl implements ExampleService {

    private static final Logger LOG = LoggerFactory.getLogger(ExampleServiceImpl.class);
    private static JsonFormat jsonFormat = new JsonFormat();

    private RaftNode raftNode;
    private ExampleStateMachine stateMachine;
    private int leaderId = -1;
        boolean success = raftNode.replicate(data);
        Example.SetResponse response = Example.SetResponse.newBuilder()
                .setSuccess(success).build();
        return response;
    }

    @Override
    public Example.GetResponse get(Example.GetRequest request) {
        return stateMachine.get(request);
    }

}
        }
    }

    @Override
    public ExampleProto.SetResponse set(ExampleProto.SetRequest request) {
        ExampleProto.SetResponse.Builder responseBuilder = ExampleProto.SetResponse.newBuilder();
        // 如果自己不是leader，将写请求转发给leader
        if (raftNode.getLeaderId() <= 0) {
            responseBuilder.setSuccess(false);
        } else if (raftNode.getLeaderId() != raftNode.getLocalServer().getServerId()) {
            onLeaderChangeEvent();
            ExampleService exampleService = BrpcProxy.getProxy(leaderRpcClient, ExampleService.class);
            ExampleProto.SetResponse responseFromLeader = exampleService.set(request);
            responseBuilder.mergeFrom(responseFromLeader);
        } else {
            // 数据同步写入raft集群
            byte[] data = request.toByteArray();
            boolean success = raftNode.replicate(data, RaftProto.EntryType.ENTRY_TYPE_DATA);
            responseBuilder.setSuccess(success);
        }

        ExampleProto.SetResponse response = responseBuilder.build();
        LOG.info("set request, request={}, response={}", jsonFormat.printToString(request),
                jsonFormat.printToString(response));
        return response;
    }

    @Override
    public ExampleProto.GetResponse get(ExampleProto.GetRequest request) {
        ExampleProto.GetResponse response = stateMachine.get(request);
        LOG.info("get request, request={}, response={}", jsonFormat.printToString(request),
                jsonFormat.printToString(response));
        return response;
    }

}

<MSG> fix snapshot bugs

<DFF> @@ -4,12 +4,19 @@ import com.github.wenweihu86.raft.example.server.ExampleStateMachine;
 import com.github.wenweihu86.raft.example.server.service.Example;
 import com.github.wenweihu86.raft.example.server.service.ExampleService;
 import com.github.wenweihu86.raft.RaftNode;
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.google.protobuf.util.JsonFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Created by wenweihu86 on 2017/5/9.
  */
 public class ExampleServiceImpl implements ExampleService {
 
+    private static final Logger LOG = LoggerFactory.getLogger(ExampleServiceImpl.class);
+    private static JsonFormat.Printer printer = JsonFormat.printer().omittingInsignificantWhitespace();
+
     private RaftNode raftNode;
     private ExampleStateMachine stateMachine;
 
@@ -24,12 +31,26 @@ public class ExampleServiceImpl implements ExampleService {
         boolean success = raftNode.replicate(data);
         Example.SetResponse response = Example.SetResponse.newBuilder()
                 .setSuccess(success).build();
+        try {
+            LOG.info("set request, request={}, response={}", printer.print(request),
+                    printer.print(response));
+        } catch (InvalidProtocolBufferException ex) {
+            ex.printStackTrace();
+        }
+
         return response;
     }
 
     @Override
     public Example.GetResponse get(Example.GetRequest request) {
-        return stateMachine.get(request);
+        Example.GetResponse response = stateMachine.get(request);
+        try {
+            LOG.info("get request, request={}, response={}", printer.print(request),
+                    printer.print(response));
+        } catch (InvalidProtocolBufferException ex) {
+            ex.printStackTrace();
+        }
+        return response;
     }
 
 }

fix snapshot bugs