use of com.bonree.brfs.disknode.client.WriteResult 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);
}
}
use of com.bonree.brfs.disknode.client.WriteResult in project BRFS by zhangnianli.
the class DataEmitter method emit.
public void emit(byte[] data, FileNode fileNode, WriteCallback callback) {
int[] duplicates = fileNode.getDuplicates();
DiskNodeClient[] clients = new DiskNodeClient[duplicates.length];
for (int i = 0; i < duplicates.length; i++) {
if (!clientCaches.containsKey(duplicates[i])) {
DiskNodeClient client = new HttpDiskNodeClient("localhost", 8080);
clientCaches.put(duplicates[i], client);
}
clients[i] = clientCaches.get(duplicates[i]);
}
for (DiskNodeClient client : clients) {
ResultGather gather = new ResultGather(clients.length, callback);
ListenableFuture<WriteResult> f = execs.submit(new WriteTask(client, fileNode, data));
Futures.addCallback(f, gather, execs);
}
}
Aggregations