Search in sources :

Example 1 with InputResult

use of com.bonree.brfs.disknode.InputResult in project BRFS by zhangnianli.

the class WriteMessageHandler method handle.

@Override
public void handle(DiskMessage msg, HandleResultCallback callback) {
    HandleResult handleResult = new HandleResult();
    try {
        LOG.debug("WRITE [{}], data length[{}]", msg.getFilePath(), msg.getData().length);
        nodeManager.writeAsync(msg.getFilePath(), msg.getData(), new InputEventCallback() {

            @Override
            public void completeError(Throwable t) {
                handleResult.setSuccess(false);
                handleResult.setCause(t);
                callback.completed(handleResult);
            }

            @Override
            public void complete(InputResult result) {
                handleResult.setSuccess(true);
                WriteResult writeResult = new WriteResult();
                writeResult.setOffset(result.getOffset());
                writeResult.setSize(result.getSize());
                try {
                    handleResult.setData(ProtoStuffUtils.serialize(writeResult));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                callback.completed(handleResult);
            }
        });
    } catch (Exception e) {
        handleResult.setSuccess(false);
        handleResult.setCause(e);
        callback.completed(handleResult);
    }
}
Also used : InputResult(com.bonree.brfs.disknode.InputResult) WriteResult(com.bonree.brfs.disknode.client.WriteResult) InputEventCallback(com.bonree.brfs.disknode.InputEventCallback) HandleResult(com.bonree.brfs.disknode.server.handler.HandleResult) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

InputEventCallback (com.bonree.brfs.disknode.InputEventCallback)1 InputResult (com.bonree.brfs.disknode.InputResult)1 WriteResult (com.bonree.brfs.disknode.client.WriteResult)1 HandleResult (com.bonree.brfs.disknode.server.handler.HandleResult)1 IOException (java.io.IOException)1