@Override public void deconstruct() { super.deconstruct(); if (renderingExecutorIsOwned && renderingExecutor instanceof ThreadPoolExecutor) shutdown((ThreadPoolExecutor) renderingExecutor); }
@SuppressWarnings("unchecked") @Override public void render(OutputStream stream, ContentChannel channel, CompletionHandler completionHandler) throws IOException { if (renderer instanceof AsynchronousRenderer) { AsynchronousRenderer asyncRenderer = (AsynchronousRenderer)renderer; asyncRenderer.setNetworkWiring(channel, completionHandler); } renderer.render(stream, processingResponse, execution, processingRequest); // the stream is closed in AsynchronousSectionedRenderer, after all data // has arrived }
@Override public void init() { super.init(); writer = null; }
private boolean renderTrace() throws IOException { if (getExecution().trace().getTraceLevel() == 0) return false; jsonWriter.beginField("trace"); try { getExecution().trace().traceNode().accept(new TraceRenderingVisitor(jsonWriter)); } catch (WrappedIOException e) { throw e.getCause(); } jsonWriter.endField(); return true; }
/** * Returns MIME type of this response */ @Override public String getContentType() { return rendererCopy.getMimeType(); }
/** * Used to create a separate instance for each result to render. */ @Override public Renderer clone() { return (Renderer) super.clone(); }
@Override public String getCharacterEncoding() { return renderer.getEncoding(); }
@Override public final void data(Data data) throws IOException { if (! shouldRender(data)) return; jsonWriter.beginArrayValue(); jsonWriter.beginObject(); jsonWriter.beginField("data"); renderValue(data,jsonWriter); jsonWriter.endField(); jsonWriter.endObject(); jsonWriter.endArrayValue(); }
@Override public void entering(TraceNode node) { try { jsonWriter.beginArray(); } catch (IOException e) { throw new WrappedIOException(e); } }
public ParentOfTopLevel(Request request,DataList trueTopLevel) { super(request); this.trueTopLevel = trueTopLevel; freeze(); }
/** * Create an renderer using the specified executor instead of the default one which should be used for production. * Using a custom executor is useful for tests to avoid creating new threads for each renderer registry. * * @param executor the executor to use or null to use the default executor suitable for production */ public AsynchronousSectionedRenderer(Executor executor) { isInitialized = false; if (executor == null) { renderingExecutor = createExecutor(); renderingExecutorIsOwned = true; } else { renderingExecutor = executor; renderingExecutorIsOwned = false; } }
/** * Initiate rendering before handover to rendering threads. * This is rendering which happens before the Response is returned from the main chain, * caused by freezing of DataLists. * At this point the worker thread still owns the Response, so all this rendering must happen * on the caller thread invoking freeze (that is, on the thread calling this). */ public final ListenableFuture<Boolean> renderBeforeHandover(OutputStream stream, RESPONSE response, Execution execution, Request request) { beforeHandoverMode = true; if ( ! isInitialized) throw new IllegalStateException("render() invoked before init()."); return startRender(stream, response, execution, request); }
@Override public void init() { super.init(); writer = null; }
@Override public String getContentType() { return renderer.getMimeType(); }
@Override public void leaving(TraceNode node) { try { jsonWriter.endArray(); } catch (IOException e) { throw new WrappedIOException(e); } }
@Override public void init() { super.init(); level = 0; }
/** * Initialize mutable, per-result set state here. */ @Override public void init() { long time = System.currentTimeMillis(); super.init(); // Important! The base class needs to initialize itself. heading = "Renderer initialized: " + time; } }
@Override public void init() { super.init(); debugRendering = false; setGenerator(null, debugRendering); renderedChildren = null; timeSource = System::currentTimeMillis; stream = null; }