use of com.bonree.brfs.common.write.data.DataItem in project BRFS by zhangnianli.
the class WriteDataMessageHandler method handle.
@Override
public void handle(HttpMessage msg, HandleResultCallback callback) {
WriteDataMessage writeMsg;
try {
writeMsg = ProtoStuffUtils.deserializeThrowable(msg.getContent(), WriteDataMessage.class);
DataItem[] items = writeMsg.getItems();
LOG.debug("Writing DataItem[{}]", items.length);
if (items == null || items.length == 0) {
callback.completed(new HandleResult(true));
return;
}
writer.write(writeMsg.getStorageNameId(), items, new DataWriteCallback(callback));
} catch (Exception e) {
LOG.error("handle write data message error", e);
callback.completed(new HandleResult(false));
}
}
use of com.bonree.brfs.common.write.data.DataItem in project BRFS by zhangnianli.
the class DefaultStorageNameStick method writeData.
@Override
public String[] writeData(InputItem[] itemArrays) {
WriteDataMessage dataMessage = new WriteDataMessage();
dataMessage.setStorageNameId(storageId);
DataItem[] dataItems = new DataItem[itemArrays.length];
for (int i = 0; i < dataItems.length; i++) {
dataItems[i] = new DataItem();
dataItems[i].setBytes(itemArrays[i].getBytes());
}
dataMessage.setItems(dataItems);
try {
Service[] serviceList = regionNodeSelector.select(regionNodeSelector.serviceNum());
if (serviceList.length == 0) {
throw new BRFSException("none disknode!!!");
}
for (Service service : serviceList) {
URI uri = new URIBuilder().setScheme(config.getUrlSchema()).setHost(service.getHost()).setPort(service.getPort()).setPath(config.getDuplicateUrlRoot() + "/").build();
HttpResponse response = null;
try {
response = client.executePost(uri, defaultHeaders, ProtoStuffUtils.serialize(dataMessage));
} catch (Exception e) {
LOG.warn("write data http request failed", e);
continue;
}
if (response == null) {
throw new Exception("can not get response for writeData!");
}
if (response.isReponseOK()) {
List<String> results = JSON.parseArray(BrStringUtils.fromUtf8Bytes(response.getResponseBody()), String.class);
String[] fids = new String[results.size()];
return results.toArray(fids);
}
}
} catch (Exception e) {
LOG.error("write data error", e);
}
return null;
}
Aggregations