summaryrefslogtreecommitdiff
path: root/same/src/main/java/com/orbekk/paxos
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-04-24 10:39:12 +0200
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-04-24 10:39:12 +0200
commitb2b40834e22430b56f6857f8670a5c5a81900de4 (patch)
tree914640f8b47e91f412d640a52f910217dd5c71cc /same/src/main/java/com/orbekk/paxos
parent67e3b2d5a0092d41df629e950a38a80743717d81 (diff)
Add protobuf version of Paxos service.
Diffstat (limited to 'same/src/main/java/com/orbekk/paxos')
-rw-r--r--same/src/main/java/com/orbekk/paxos/PaxosServiceImpl.java40
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,