finish
This commit is contained in:
parent
02b4722799
commit
911a7883ce
|
@ -54,10 +54,15 @@ public class Server {
|
|||
|
||||
@Autowired
|
||||
public static Node node;
|
||||
public static RaftClosure done;
|
||||
|
||||
public static Node GetNode() {
|
||||
return node;
|
||||
}
|
||||
|
||||
public static RaftClosure GetDone() {
|
||||
return done;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
@ -92,12 +97,13 @@ public class Server {
|
|||
|
||||
RaftGroupService cluster = new RaftGroupService(groupId, serverId, nodeOptions);
|
||||
node = cluster.start();
|
||||
done = new RaftClosure();
|
||||
|
||||
System.setProperty("server.port", sprPort);
|
||||
SpringApplication.run(Server.class, args);
|
||||
|
||||
|
||||
Closure done = new RaftClosure();
|
||||
node.shutdown(done);
|
||||
|
||||
// node.shutdown(done);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,34 +20,38 @@ import org.springframework.stereotype.Controller;
|
|||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import com.alipay.sofa.jraft.Node;
|
||||
|
||||
@Controller
|
||||
public class TaskLog {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TaskLog.class);
|
||||
private static Node node = Server.GetNode();
|
||||
|
||||
@GetMapping(path = "/test")
|
||||
public ResponseEntity<JsonObject> greeting() {
|
||||
public ResponseEntity<String> greeting() {
|
||||
|
||||
Task task = new Task();
|
||||
Closure done = new RaftClosure();
|
||||
task.setData(ByteBuffer.wrap("hello".getBytes()));
|
||||
task.setDone( done);
|
||||
LOG.info( done.toString());
|
||||
LOG.info(Server.GetNode().toString());
|
||||
JsonObject response = new JsonObject();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
LOG.error(node.toString());
|
||||
|
||||
|
||||
if (Server.GetNode() == null) {
|
||||
return new ResponseEntity<JsonObject>(response, HttpStatus.OK);
|
||||
}
|
||||
Server.GetNode()
|
||||
.apply(task);
|
||||
|
||||
RaftClosure done = new RaftClosure();
|
||||
task.setData(ByteBuffer.wrap("hello".getBytes()));
|
||||
task.setDone(done);
|
||||
Server.GetNode().apply(task);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
JsonObject response = new JsonObject();
|
||||
response.addProperty("status", "success");
|
||||
response.addProperty("apply", "hello");
|
||||
return new ResponseEntity<JsonObject>(response, HttpStatus.OK);
|
||||
return new ResponseEntity<String>(response.toString(), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ public class RaftClosure implements Closure {
|
|||
LOG.info("Task completed with status"+status.getCode());
|
||||
LOG.info("Task completed with "+status.getErrorMsg());
|
||||
LOG.info("Task completed with "+status.getRaftError());
|
||||
|
||||
}
|
||||
|
||||
// @Override
|
||||
|
|
|
@ -57,10 +57,11 @@ public class StateMachine extends StateMachineAdapter {
|
|||
// This task is applied by this node, get value from closure to avoid additional
|
||||
// parsing.
|
||||
|
||||
LOG.debug("done:%s",iter.getData().toString());
|
||||
LOG.error("done:%1$s",iter.getData().toString());
|
||||
|
||||
} else {
|
||||
// Have to parse FetchAddRequest from this user log.
|
||||
LOG.debug("null:%s",iter.getData().toString());
|
||||
LOG.error("null:%1$s",iter.getData().toString());
|
||||
}
|
||||
|
||||
iter.next();
|
||||
|
|
Loading…
Reference in New Issue
Block a user