Search in sources :

Example 1 with LeaderTaskClosure

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);
}
Also used : Task(com.alipay.sofa.jraft.entity.Task) BooleanCommand(com.alipay.sofa.jraft.test.atomic.command.BooleanCommand) LeaderTaskClosure(com.alipay.sofa.jraft.test.atomic.server.LeaderTaskClosure) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Task (com.alipay.sofa.jraft.entity.Task)1 BooleanCommand (com.alipay.sofa.jraft.test.atomic.command.BooleanCommand)1 LeaderTaskClosure (com.alipay.sofa.jraft.test.atomic.server.LeaderTaskClosure)1 ByteBuffer (java.nio.ByteBuffer)1