* string representation of hub info.
*/
public static HubInfo parse(String hubInfoStr) throws InvalidHubInfoException {
// it is not protobuf encoded hub info, it might be generated by ZkTopicManager
if (!hubInfoStr.startsWith("hostname")) {
final HedwigSocketAddress owner;
try {
owner = new HedwigSocketAddress(hubInfoStr);
} catch (Exception e) {
throw new InvalidHubInfoException("Corrupted hub server address : " + hubInfoStr, e);
}
return new HubInfo(owner, 0L);
}
// it is a protobuf encoded hub info.
HubInfoData hubInfoData;
try {
BufferedReader reader = new BufferedReader(
new StringReader(hubInfoStr));
HubInfoData.Builder dataBuilder = HubInfoData.newBuilder();
TextFormat.merge(reader, dataBuilder);
hubInfoData = dataBuilder.build();
} catch (InvalidProtocolBufferException ipbe) {
throw new InvalidHubInfoException("Corrupted hub info : " + hubInfoStr, ipbe);
} catch (IOException ie) {
throw new InvalidHubInfoException("Corrupted hub info : " + hubInfoStr, ie);
}
final HedwigSocketAddress owner;
try {
owner = new HedwigSocketAddress(hubInfoData.getHostname().trim());
} catch (Exception e) {
throw new InvalidHubInfoException("Corrupted hub server address : " + hubInfoData.getHostname(), e);
}
long ownerZxid = hubInfoData.getCzxid();
return new HubInfo(owner, ownerZxid, hubInfoData);