use of com.bonree.brfs.common.net.tcp.file.ReadObject in project BRFS by zhangnianli.
the class TcpClientUtils method getClient.
public static TcpDiskNodeClient getClient(String host, int port, int export, int timeout) throws InterruptedException, IOException {
TcpClient<BaseMessage, BaseResponse> tcpClient = group.createClient(new TcpClientConfig() {
@Override
public SocketAddress remoteAddress() {
return new InetSocketAddress(host, port);
}
@Override
public int connectTimeoutMillis() {
return timeout;
}
});
TcpClient<ReadObject, FileContentPart> readerClient = group2.createClient(new AsyncFileReaderCreateConfig() {
@Override
public SocketAddress remoteAddress() {
return new InetSocketAddress(host, export);
}
@Override
public int connectTimeoutMillis() {
return timeout;
}
@Override
public int maxPendingRead() {
return 0;
}
});
return new TcpDiskNodeClient(tcpClient, readerClient);
}
use of com.bonree.brfs.common.net.tcp.file.ReadObject in project BRFS by zhangnianli.
the class DefaultStorageNameStick method readData.
@Override
public InputItem readData(String fid) throws Exception {
Fid fidObj = FidDecoder.build(fid);
if (fidObj.getStorageNameCode() != storageId) {
throw new IllegalAccessException("Storage name of fid is not legal!");
}
StringBuilder nameBuilder = new StringBuilder(fidObj.getUuid());
String[] serverList = new String[fidObj.getServerIdCount()];
for (int i = 0; i < fidObj.getServerIdCount(); i++) {
String id = fidObj.getServerId(i);
nameBuilder.append('_').append(id);
serverList[i] = id;
}
try {
// 最大尝试副本数个server
for (int i = 0; i < serverList.length; i++) {
ServiceMetaInfo serviceMetaInfo = selector.selectService(fidObj.getUuid(), serverList);
if (serviceMetaInfo.getFirstServer() == null) {
serverList[serviceMetaInfo.getReplicatPot() - 1] = null;
continue;
}
Service service = serviceMetaInfo.getFirstServer();
LOG.info("read service[{}]", service);
ReadConnection fileReader = connectionPool.getConnection(service);
try {
ReadObject readObject = new ReadObject();
readObject.setSn(storageName);
readObject.setIndex(serviceMetaInfo.getReplicatPot());
readObject.setTime(fidObj.getTime());
readObject.setDuration(fidObj.getDuration());
readObject.setFileName(nameBuilder.toString());
// readObject.setFilePath(FilePathBuilder.buildPath(fidObj,
// timeCache.get(new
// TimePair(TimeUtils.prevTimeStamp(fidObj.getTime(),
// fidObj.getDuration()), fidObj.getDuration())),
// storageName, serviceMetaInfo.getReplicatPot()));
readObject.setOffset(fidObj.getOffset());
readObject.setLength((int) fidObj.getSize());
byte[] fileContent = fileReader.read(readObject);
return new InputItem() {
@Override
public byte[] getBytes() {
return fileContent;
}
};
} catch (Exception e) {
// 使用选择的server没有读取到数据,需要进行排除
serverList[serviceMetaInfo.getReplicatPot() - 1] = null;
continue;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Aggregations