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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations