summaryrefslogtreecommitdiff
path: root/same/src/main/java
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-06 15:05:45 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-06 15:05:45 +0100
commit1d2eca2591c5747c65d52cb96f5246632f06d9d0 (patch)
treebc06817155bb2c683b25f608227dd0682d1bf009 /same/src/main/java
parent0ac907ad19d62cc773f6f13f74af52bd75f0b5db (diff)
Fix RpcServlet: Use POST requests.
Diffstat (limited to 'same/src/main/java')
-rw-r--r--same/src/main/java/com/orbekk/net/MyJsonRpcHttpClient.java5
-rw-r--r--same/src/main/java/com/orbekk/paxos/MasterProposer.java21
-rw-r--r--same/src/main/java/com/orbekk/paxos/PaxosService.java4
-rw-r--r--same/src/main/java/com/orbekk/same/http/RpcServlet.java2
4 files changed, 24 insertions, 8 deletions
diff --git a/same/src/main/java/com/orbekk/net/MyJsonRpcHttpClient.java b/same/src/main/java/com/orbekk/net/MyJsonRpcHttpClient.java
index 98de054..237198e 100644
--- a/same/src/main/java/com/orbekk/net/MyJsonRpcHttpClient.java
+++ b/same/src/main/java/com/orbekk/net/MyJsonRpcHttpClient.java
@@ -17,6 +17,8 @@ import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.codehaus.jackson.map.ObjectMapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.googlecode.jsonrpc4j.JsonRpcClient;
import com.googlecode.jsonrpc4j.JsonRpcHttpClient;
@@ -26,7 +28,8 @@ import com.googlecode.jsonrpc4j.JsonRpcHttpClient;
*
* We extend JsonRpcHttpClient but try to override everything it does.
*/
-public class MyJsonRpcHttpClient extends JsonRpcHttpClient {
+public class MyJsonRpcHttpClient extends JsonRpcHttpClient {
+ Logger logger = LoggerFactory.getLogger(getClass());
private URL serviceUrl;
private JsonRpcClient rpcClient;
private HttpClient httpClient;
diff --git a/same/src/main/java/com/orbekk/paxos/MasterProposer.java b/same/src/main/java/com/orbekk/paxos/MasterProposer.java
index f216ff5..effe6df 100644
--- a/same/src/main/java/com/orbekk/paxos/MasterProposer.java
+++ b/same/src/main/java/com/orbekk/paxos/MasterProposer.java
@@ -1,6 +1,7 @@
package com.orbekk.paxos;
import com.orbekk.same.ConnectionManager;
+import static com.orbekk.same.StackTraceUtil.throwableToString;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
@@ -20,11 +21,17 @@ public class MasterProposer {
}
private int internalPropose(int proposalNumber) {
- int bestPromise = proposalNumber;
+ int bestPromise = -proposalNumber;
int promises = 0;
for (String url : paxosUrls) {
PaxosService paxos = connections.getPaxos(url);
- int result = paxos.propose(myUrl, proposalNumber);
+ int result = 0;
+ try {
+ result = paxos.propose(myUrl, proposalNumber);
+ } catch (Exception e) {
+ logger.warn("Exception from {}: {}", url,
+ throwableToString(e));
+ }
if (result == proposalNumber) {
promises += 1;
}
@@ -38,11 +45,17 @@ public class MasterProposer {
}
private int internalAcceptRequest(int proposalNumber) {
- int bestAccepted = proposalNumber;
+ int bestAccepted = -proposalNumber;
int accepts = 0;
for (String url : paxosUrls) {
PaxosService paxos = connections.getPaxos(url);
- int result = paxos.acceptRequest(myUrl, proposalNumber);
+ int result = 0;
+ try {
+ result = paxos.acceptRequest(myUrl, proposalNumber);
+ } catch (Exception e) {
+ logger.warn("Exception from {}: {}", url,
+ throwableToString(e));
+ }
if (result == proposalNumber) {
accepts += 1;
}
diff --git a/same/src/main/java/com/orbekk/paxos/PaxosService.java b/same/src/main/java/com/orbekk/paxos/PaxosService.java
index a92a794..8de02da 100644
--- a/same/src/main/java/com/orbekk/paxos/PaxosService.java
+++ b/same/src/main/java/com/orbekk/paxos/PaxosService.java
@@ -7,6 +7,6 @@ public interface PaxosService {
* -M if another promise already was made, where M is the promise
* highest proposal number.
*/
- int propose(String clientUrl, int proposalNumber);
- int acceptRequest(String clientUrl, int proposalNumber);
+ int propose(String clientUrl, int proposalNumber) throws Exception;
+ int acceptRequest(String clientUrl, int proposalNumber) throws Exception;
}
diff --git a/same/src/main/java/com/orbekk/same/http/RpcServlet.java b/same/src/main/java/com/orbekk/same/http/RpcServlet.java
index 6d73759..9b4f82e 100644
--- a/same/src/main/java/com/orbekk/same/http/RpcServlet.java
+++ b/same/src/main/java/com/orbekk/same/http/RpcServlet.java
@@ -17,7 +17,7 @@ public class RpcServlet extends HttpServlet {
}
@Override
- protected void doGet(HttpServletRequest request,
+ protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws IOException {
rpcServer.handle(request, response);
}