use of com.bonree.brfs.disknode.server.tcp.handler.data.DeleteFileMessage in project BRFS by zhangnianli.
the class DeleteFileMessageHandler method handleMessage.
@Override
public void handleMessage(BaseMessage baseMessage, ResponseWriter<BaseResponse> writer) {
DeleteFileMessage message = ProtoStuffUtils.deserialize(baseMessage.getBody(), DeleteFileMessage.class);
if (message == null) {
writer.write(new BaseResponse(ResponseCode.ERROR_PROTOCOL));
return;
}
try {
String filePath = diskContext.getConcreteFilePath(message.getFilePath());
LOG.info("delete file[{}], force[{}], recursive[{}]", filePath, message.isForce(), message.isRecursive());
File targetFile = new File(filePath);
if (targetFile.isFile()) {
try {
closeFile(targetFile, message.isForce());
writer.write(new BaseResponse(ResponseCode.OK));
} catch (Exception e) {
writer.write(new BaseResponse(ResponseCode.ERROR));
return;
}
} else {
try {
closeDir(targetFile, message.isRecursive(), message.isForce());
writer.write(new BaseResponse(ResponseCode.OK));
} catch (Exception e) {
writer.write(new BaseResponse(ResponseCode.ERROR));
return;
}
}
} catch (Exception e) {
LOG.error("delete message error", e);
writer.write(new BaseResponse(ResponseCode.ERROR));
}
}
use of com.bonree.brfs.disknode.server.tcp.handler.data.DeleteFileMessage in project BRFS by zhangnianli.
the class TcpDiskNodeClient method deleteDir.
@Override
public boolean deleteDir(String path, boolean force, boolean recursive) {
try {
DeleteFileMessage deleteFileMessage = new DeleteFileMessage();
deleteFileMessage.setFilePath(path);
deleteFileMessage.setForce(force);
deleteFileMessage.setRecursive(recursive);
BaseMessage message = new BaseMessage(DataNodeBootStrap.TYPE_DELETE_FILE);
message.setBody(ProtoStuffUtils.serialize(deleteFileMessage));
CompletableFuture<BaseResponse> future = new CompletableFuture<BaseResponse>();
client.sendMessage(message, new ResponseHandler<BaseResponse>() {
@Override
public void handle(BaseResponse response) {
future.complete(response);
}
@Override
public void error(Throwable e) {
future.completeExceptionally(e);
}
});
BaseResponse response = future.get();
if (response != null && response.getCode() == ResponseCode.OK) {
return true;
}
} catch (Exception e) {
LOG.error("delete file [{}] error", path, e);
}
return false;
}
Aggregations