try { while (!Thread.interrupted()) { Message message = chunks.read(); if (message == null) { break;
/** * Start running thread to read result which sent from the tinkerer. */ @Override public void run() { Gson gson = new Gson(); ChunkedInput<String> input = this.response.readEntity(new ChunkObject()); String chunk; OperationSegment operationSegment = new OperationSegment(); long initTime = Calendar.getInstance().getTimeInMillis(); long currentTime; while ((chunk = input.read()) != null) { synchronized (this) { currentTime = Calendar.getInstance().getTimeInMillis(); if (initTime + MAX_BUFFER_IDLE_TIME_MS < currentTime) { logger.warn("Execution time out for operation " + this.operationId); break; } operationSegment = gson.fromJson(chunk, OperationSegment.class); writeDataToFile(operationSegment, this.segmentCount + 1); this.segmentCount++; } } synchronized (this) { this.isCompleted = true; this.exitValue = operationSegment.getExitValue(); logger.info("Streaming success with exit value " + operationSegment.getExitValue() + " for operation " + this.operationId); } }