use of com.bonree.brfs.disknode.server.tcp.handler.data.WriteFileData in project BRFS by zhangnianli.
the class TcpDiskNodeClient method writeData.
@Override
public WriteResult writeData(String path, byte[] bytes) throws IOException {
try {
WriteFileData data = new WriteFileData();
data.setData(bytes);
WriteFileMessage writeFileMessage = new WriteFileMessage();
writeFileMessage.setFilePath(path);
writeFileMessage.setDatas(new WriteFileData[] { data });
BaseMessage message = new BaseMessage(DataNodeBootStrap.TYPE_WRITE_FILE);
message.setBody(ProtoStuffUtils.serialize(writeFileMessage));
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) {
WriteResultList resultList = ProtoStuffUtils.deserialize(response.getBody(), WriteResultList.class);
WriteResult[] results = resultList.getWriteResults();
if (results.length == 1) {
return results[0];
}
}
} catch (Exception e) {
LOG.error("write file error", e);
}
return null;
}
use of com.bonree.brfs.disknode.server.tcp.handler.data.WriteFileData in project BRFS by zhangnianli.
the class TcpDiskNodeClient method writeDatas.
@Override
public WriteResult[] writeDatas(String path, List<byte[]> dataList) throws IOException {
try {
WriteFileData[] datas = new WriteFileData[dataList.size()];
for (int i = 0; i < datas.length; i++) {
WriteFileData data = new WriteFileData();
data.setData(dataList.get(i));
datas[i] = data;
}
WriteFileMessage writeFileMessage = new WriteFileMessage();
writeFileMessage.setFilePath(path);
writeFileMessage.setDatas(datas);
BaseMessage message = new BaseMessage(DataNodeBootStrap.TYPE_WRITE_FILE);
message.setBody(ProtoStuffUtils.serialize(writeFileMessage));
CompletableFuture<BaseResponse> future = new CompletableFuture<BaseResponse>();
LOG.debug("write [{}] datas to data node in file[{}]", dataList.size(), path);
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) {
WriteResultList resultList = ProtoStuffUtils.deserialize(response.getBody(), WriteResultList.class);
return resultList.getWriteResults();
}
} catch (Exception e) {
LOG.error("write file error", e);
}
return null;
}
Aggregations