final JSONObject requestObject = context.getRequestObject();
final long start = RequestObjectHelper.getStartOffset(requestObject);
final long end = RequestObjectHelper.getEndOffset(requestObject);
final ElementIdHandler elementIdHandler = this.getElementIdHandler(context.getRexsterApplicationGraph());
final VertexToFaunusBinary vertexToFaunusBinary = new VertexToFaunusBinary(elementIdHandler);
// help with uniquely identifying incoming requests in logs.
final UUID requestIdentifier = UUID.randomUUID();
final String verticesInSplit = end == Long.MAX_VALUE ? "END" : String.valueOf(end - start);
logger.debug(String.format("Request [%s] split between [%s] and [%s].", requestIdentifier, start, end));
return new ExtensionResponse(Response.ok(new StreamingOutput() {
@Override
public void write(OutputStream out) throws IOException {
long counter = 0;
long vertexCount = 0;
final DataOutputStream dos = new DataOutputStream(out);
final Iterable<Vertex> vertices = graph.getVertices();
for (Vertex vertex : vertices) {
if (counter >= start && counter < end) {
vertexToFaunusBinary.writeVertex(vertex, dos);
if (logger.isDebugEnabled() && counter % WRITE_STATUS_EVERY == 0) {
logger.debug(String.format("Request [%s] at [%s] on the way to [%s].",
requestIdentifier, vertexCount, verticesInSplit));
}