Skip to content

Commit

Permalink
#502 Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
nkorange committed Jan 14, 2019
1 parent 93f9446 commit 4cfae1b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
Expand Up @@ -163,7 +163,7 @@ public void signalPublish(String key, String value) throws Exception {
}

try {
RaftCore.OPERATE_LOCK.lock();
OPERATE_LOCK.lock();
long start = System.currentTimeMillis();
final Datum datum = new Datum();
datum.key = key;
Expand Down Expand Up @@ -218,7 +218,7 @@ public STATE onContentWriteCompleted() {
long end = System.currentTimeMillis();
Loggers.RAFT.info("signalPublish cost {} ms, key: {}", (end - start), key);
} finally {
RaftCore.OPERATE_LOCK.unlock();
OPERATE_LOCK.unlock();
}
}

Expand All @@ -236,7 +236,10 @@ public void signalDelete(final String key) throws Exception {
}

JSONObject json = new JSONObject();
json.put("key", key);
// construct datum:
Datum datum = new Datum();
datum.key = key;
json.put("datum", datum);
json.put("source", peers.local());

for (final String server : peers.allServersIncludeMyself()) {
Expand All @@ -263,16 +266,6 @@ public Integer onCompleted(Response response) throws Exception {
}
}

public void onPublish(String key, String value, long timestamp, String source) {

}

public void onPublish(JSONObject json) throws Exception {
Datum datum = JSON.parseObject(json.getString("datum"), Datum.class);
RaftPeer source = JSON.parseObject(json.getString("source"), RaftPeer.class);
onPublish(datum, source);
}

public void onPublish(Datum datum, RaftPeer source) throws Exception {
RaftPeer local = peers.local();
if (StringUtils.isBlank(datum.value)) {
Expand Down Expand Up @@ -323,14 +316,6 @@ public void onPublish(Datum datum, RaftPeer source) throws Exception {

public void onDelete(Datum datum, RaftPeer source) throws Exception {

// RaftPeer source = new RaftPeer();
// source.ip = params.getJSONObject("source").getString("ip");
// source.state = RaftPeer.State.valueOf(params.getJSONObject("source").getString("state"));
// source.term.set(params.getJSONObject("source").getLongValue("term"));
// source.heartbeatDueMs = params.getJSONObject("source").getLongValue("heartbeatDueMs");
// source.leaderDueMs = params.getJSONObject("source").getLongValue("leaderDueMs");
// source.voteFor = params.getJSONObject("source").getString("voteFor");

RaftPeer local = peers.local();

if (!peers.isLeader(source.ip)) {
Expand Down
Expand Up @@ -213,10 +213,6 @@ public String onDelete(HttpServletRequest request, HttpServletResponse response)
return "ok";
}

public void setDomainsManager(ServiceManager domainsManager) {
this.domainsManager = domainsManager;
}

@RequestMapping("/getLeader")
public JSONObject getLeader(HttpServletRequest request, HttpServletResponse response) {

Expand Down

0 comments on commit 4cfae1b

Please sign in to comment.