for (int i = 0; i < brokerStructs.length; i++) {
Struct broker = (Struct) brokerStructs[i];
int nodeId = broker.getInt(NODE_ID_KEY_NAME);
String host = broker.getString(HOST_KEY_NAME);
int port = broker.getInt(PORT_KEY_NAME);
brokers.put(nodeId, new Node(nodeId, host, port));
}
List<PartitionInfo> partitions = new ArrayList<PartitionInfo>();
Object[] topicInfos = (Object[]) struct.get(TOPIC_METATDATA_KEY_NAME);
for (int i = 0; i < topicInfos.length; i++) {
Struct topicInfo = (Struct) topicInfos[i];
short topicError = topicInfo.getShort(TOPIC_ERROR_CODE_KEY_NAME);
String topic = topicInfo.getString(TOPIC_KEY_NAME);
if (topicError == Errors.NONE.code()) {
Object[] partitionInfos = (Object[]) topicInfo.get(PARTITION_METADATA_KEY_NAME);
for (int j = 0; j < partitionInfos.length; j++) {
Struct partitionInfo = (Struct) partitionInfos[j];
int partition = partitionInfo.getInt(PARTITION_KEY_NAME);
int leader = partitionInfo.getInt(LEADER_KEY_NAME);
Node leaderNode = leader == -1 ? null : brokers.get(leader);
Object[] replicas = (Object[]) partitionInfo.get(REPLICAS_KEY_NAME);
Node[] replicaNodes = new Node[replicas.length];
for (int k = 0; k < replicas.length; k++)
replicaNodes[k] = brokers.get(replicas[k]);
Object[] isr = (Object[]) partitionInfo.get(ISR_KEY_NAME);