Search in sources :

Example 1 with HandleResult

use of com.bonree.brfs.disknode.server.handler.HandleResult in project BRFS by zhangnianli.

the class DeleteMessageHandler method handle.

@Override
public void handle(DiskMessage msg, HandleResultCallback callback) {
    HandleResult result = new HandleResult();
    try {
        nodeManager.close(msg.getFilePath());
        File targetFile = new File(msg.getFilePath());
        targetFile.delete();
        result.setSuccess(true);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        callback.completed(result);
    }
}
Also used : HandleResult(com.bonree.brfs.disknode.server.handler.HandleResult) IOException(java.io.IOException) File(java.io.File)

Example 2 with HandleResult

use of com.bonree.brfs.disknode.server.handler.HandleResult in project BRFS by zhangnianli.

the class CloseMessageHandler method handle.

@Override
public void handle(DiskMessage msg, HandleResultCallback callback) {
    HandleResult result = new HandleResult();
    try {
        nodeManager.close(msg.getFilePath());
        result.setSuccess(true);
    } catch (IOException e) {
        result.setSuccess(false);
        result.setCause(e);
    } finally {
        callback.completed(result);
    }
}
Also used : HandleResult(com.bonree.brfs.disknode.server.handler.HandleResult) IOException(java.io.IOException)

Example 3 with HandleResult

use of com.bonree.brfs.disknode.server.handler.HandleResult in project BRFS by zhangnianli.

the class OpenMessageHandler method handle.

@Override
public void handle(DiskMessage msg, HandleResultCallback callback) {
    HandleResult result = new HandleResult();
    String overrideParam = msg.getParams().get(PARAM_OVERRIDE);
    boolean override = overrideParam == null ? false : true;
    try {
        LOG.debug("OPEN [{}] override[{}]", msg.getFilePath(), override);
        nodeManager.buildDiskWriter(msg.getFilePath(), override);
        result.setSuccess(true);
    } catch (IOException e) {
        result.setSuccess(false);
        result.setCause(e);
    } finally {
        callback.completed(result);
    }
}
Also used : HandleResult(com.bonree.brfs.disknode.server.handler.HandleResult) IOException(java.io.IOException)

Example 4 with HandleResult

use of com.bonree.brfs.disknode.server.handler.HandleResult in project BRFS by zhangnianli.

the class ReadMessageHandler method handle.

@Override
public void handle(DiskMessage msg, HandleResultCallback callback) {
    HandleResult result = new HandleResult();
    try {
        String offsetParam = msg.getParams().get(PARAM_READ_OFFSET);
        String lengthParam = msg.getParams().get(PARAM_READ_LENGTH);
        int offset = offsetParam == null ? 0 : Integer.parseInt(offsetParam);
        int length = lengthParam == null ? Integer.MAX_VALUE : Integer.parseInt(lengthParam);
        DiskReader reader = new DiskReader(msg.getFilePath());
        byte[] data = reader.read(offset, length);
        result.setSuccess(true);
        result.setData(data);
    } catch (IOException e) {
        result.setSuccess(false);
        result.setCause(e);
    } finally {
        callback.completed(result);
    }
}
Also used : HandleResult(com.bonree.brfs.disknode.server.handler.HandleResult) IOException(java.io.IOException) DiskReader(com.bonree.brfs.disknode.DiskReader)

Example 5 with HandleResult

use of com.bonree.brfs.disknode.server.handler.HandleResult 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

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