Search in sources :

Example 1 with WriteDataList

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

the class HttpDiskNodeClient method writeDatas.

@Override
public WriteResult[] writeDatas(String path, List<byte[]> dataList) throws IOException {
    WriteDataList datas = new WriteDataList();
    WriteData[] dataArray = new WriteData[dataList.size()];
    for (int i = 0; i < dataArray.length; i++) {
        WriteData data = new WriteData();
        data.setBytes(dataList.get(i));
        dataArray[i] = data;
    }
    datas.setDatas(dataArray);
    URI uri = new URIBuilder().setScheme(DEFAULT_SCHEME).setHost(host).setPort(port).setPath(DiskContext.URI_DISK_NODE_ROOT + path).build();
    try {
        LOG.info("write file[{}] with {} datas to {}:{}", path, dataList.size(), host, port);
        HttpResponse response = client.executePost(uri, ProtoStuffUtils.serialize(datas));
        LOG.debug("write file[{}] response[{}]", path, response.getStatusCode());
        if (response.isReponseOK()) {
            WriteResultList resultList = ProtoStuffUtils.deserialize(response.getResponseBody(), WriteResultList.class);
            return resultList.getWriteResults();
        }
    } catch (Exception e) {
        LOG.error("write file[{}] to {}:{} error", path, host, port, e);
    }
    return null;
}
Also used : WriteDataList(com.bonree.brfs.disknode.server.handler.data.WriteDataList) HttpResponse(com.bonree.brfs.common.net.http.client.HttpResponse) URI(java.net.URI) WriteData(com.bonree.brfs.disknode.server.handler.data.WriteData) IOException(java.io.IOException) URIBuilder(com.bonree.brfs.common.net.http.client.URIBuilder)

Aggregations

HttpResponse (com.bonree.brfs.common.net.http.client.HttpResponse)1 URIBuilder (com.bonree.brfs.common.net.http.client.URIBuilder)1 WriteData (com.bonree.brfs.disknode.server.handler.data.WriteData)1 WriteDataList (com.bonree.brfs.disknode.server.handler.data.WriteDataList)1 IOException (java.io.IOException)1 URI (java.net.URI)1