From b2b40834e22430b56f6857f8670a5c5a81900de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Tue, 24 Apr 2012 10:39:12 +0200 Subject: Add protobuf version of Paxos service. --- .../java/com/orbekk/paxos/PaxosServiceImpl.java | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'same/src/main/java/com/orbekk/paxos/PaxosServiceImpl.java') 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 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 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, -- cgit v1.2.3