header.setSavedx(Long.toHexString(savetime));
header.setSavedate(SliderUtils.toGMTString(savetime));
header.setRoles(roles);
RoleHistoryRecord record = new RoleHistoryRecord(header);
Schema schema = record.getSchema();
Encoder encoder = EncoderFactory.get().jsonEncoder(schema, out);
writer.write(record, encoder);
long count = 0;
//now for every role history entry, write out its record
Collection<NodeInstance> instances = history.cloneNodemap().values();
for (NodeInstance instance : instances) {
for (int role = 0; role < roles; role++) {
NodeEntry nodeEntry = instance.get(role);
if (nodeEntry != null) {
NodeEntryRecord ner = build(nodeEntry, role, instance.hostname);
record = new RoleHistoryRecord(ner);
writer.write(record, encoder);
count++;
}
}
}
// footer
RoleHistoryFooter footer = new RoleHistoryFooter();
footer.setCount(count);
writer.write(new RoleHistoryRecord(footer), encoder);
encoder.flush();
out.close();
return count;
} finally {
out.close();
}