diff options
Diffstat (limited to 'same/src/main/java/com/orbekk/paxos')
-rw-r--r-- | same/src/main/java/com/orbekk/paxos/PaxosServiceImpl.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/same/src/main/java/com/orbekk/paxos/PaxosServiceImpl.java b/same/src/main/java/com/orbekk/paxos/PaxosServiceImpl.java index 58426bf..6b9dd14 100644 --- a/same/src/main/java/com/orbekk/paxos/PaxosServiceImpl.java +++ b/same/src/main/java/com/orbekk/paxos/PaxosServiceImpl.java @@ -3,6 +3,12 @@ package com.orbekk.paxos; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.protobuf.RpcCallback; +import com.google.protobuf.RpcController; +import com.orbekk.same.Services.Paxos; +import com.orbekk.same.Services.PaxosRequest; +import com.orbekk.same.Services.PaxosResponse; + /** * This class better be thread-safe. */ @@ -11,10 +17,44 @@ public class PaxosServiceImpl implements PaxosService { private int highestPromise = 0; private int highestAcceptedValue = 0; private String tag = ""; + private Paxos service = new ProtobufPaxosServiceImpl(); + + private class ProtobufPaxosServiceImpl extends Paxos { + @Override + public void propose(RpcController controller, PaxosRequest request, + RpcCallback<PaxosResponse> done) { + String clientUrl = request.getClient().getLocation(); + int proposalNumber = request.getProposalNumber(); + int response = + PaxosServiceImpl.this.propose(clientUrl, proposalNumber); + PaxosResponse result = PaxosResponse.newBuilder() + .setResult(response) + .build(); + done.run(result); + } + @Override + public void acceptRequest(RpcController controller, + PaxosRequest request, RpcCallback<PaxosResponse> done) { + String clientUrl = request.getClient().getLocation(); + int proposalNumber = request.getProposalNumber(); + int response = + PaxosServiceImpl.this.acceptRequest(clientUrl, proposalNumber); + PaxosResponse result = PaxosResponse.newBuilder() + .setResult(response) + .build(); + done.run(result); + } + + } + public PaxosServiceImpl(String tag) { this.tag = tag; } + + public Paxos getService() { + return service; + } @Override public synchronized int propose(String clientUrl, |