use of com.alipay.sofa.jraft.test.atomic.server.LeaderTaskClosure in project sofa-jraft by sofastack.
the class BaseAsyncUserProcessor method createTask.
private Task createTask(RpcContext asyncCtx, T request, CommandType cmdType) {
final LeaderTaskClosure closure = new LeaderTaskClosure();
closure.setCmd(request);
closure.setCmdType(cmdType);
closure.setDone(status -> {
if (status.isOk()) {
asyncCtx.sendResponse(closure.getResponse());
} else {
asyncCtx.sendResponse(new BooleanCommand(false, status.getErrorMsg()));
}
});
final byte[] cmdBytes = CommandCodec.encodeCommand(request);
final ByteBuffer data = ByteBuffer.allocate(cmdBytes.length + 1);
data.put(cmdType.toByte());
data.put(cmdBytes);
data.flip();
return new Task(data, closure);
}
Aggregations