use of com.bonree.brfs.common.net.tcp.BaseResponse in project BRFS by zhangnianli.
the class TcpDiskNodeClient method recover.
@Override
public boolean recover(String path, long fileLength, List<String> fullstates) {
try {
FileRecoveryMessage recoveryMessage = new FileRecoveryMessage();
recoveryMessage.setFilePath(path);
recoveryMessage.setOffset(fileLength);
String[] states = new String[fullstates.size()];
recoveryMessage.setSources(fullstates.toArray(states));
BaseMessage message = new BaseMessage(DataNodeBootStrap.TYPE_RECOVER_FILE);
message.setBody(ProtoStuffUtils.serialize(recoveryMessage));
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("get meta data from file [{}] error", path, e);
}
return false;
}
use of com.bonree.brfs.common.net.tcp.BaseResponse in project BRFS by zhangnianli.
the class TcpDiskNodeClient method openFile.
@Override
public long openFile(String path, long capacity) {
try {
OpenFileMessage openFileMessage = new OpenFileMessage();
openFileMessage.setFilePath(path);
openFileMessage.setCapacity(capacity);
BaseMessage message = new BaseMessage(DataNodeBootStrap.TYPE_OPEN_FILE);
message.setBody(ProtoStuffUtils.serialize(openFileMessage));
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 Longs.fromByteArray(response.getBody());
}
} catch (Exception e) {
LOG.error("open file error", e);
}
return -1;
}
Aggregations