use of org.finos.legend.pure.m3.exception.PureExecutionStreamingException in project legend-pure by finos.
the class ExecutionManager method execute.
private void execute(CoreInstance function, ListIterable<CoreInstance> parameters, HttpResponseWriter response, HttpInformation httpInformation, boolean canStreamOutput, OutputFormat format) {
long start = System.currentTimeMillis();
try {
CanStreamState.setCanStream(canStreamOutput);
response.setIsStreamingResponse(canStreamOutput);
this.addContentTypeAndDispositionHeaders(response, httpInformation);
response.setHeader("Trailer", "X-Streaming-Error");
// Do not open outputStream in try-with-resources
OutputStream outputStream = response.getOutputStream();
try {
OutputWriter writer = this.functionExecution.newOutputWriter();
if (format == OutputFormat.XLSX) {
writer = new XLSXOutputWriter(writer);
}
this.functionExecution.start(function, parameters, outputStream, writer);
} catch (PureExecutionStreamingException ex) {
}
// outputStream must NOT be closed in case of an uncaught exception
// so the call to close must not be in a finally block or implicit in a try-with-resources
outputStream.close();
} catch (Throwable t) {
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
if (t instanceof Error) {
throw (Error) t;
}
throw new RuntimeException(t);
} finally {
// Reset
CanStreamState.resetCanStream();
}
}
use of org.finos.legend.pure.m3.exception.PureExecutionStreamingException in project legend-pure by finos.
the class FunctionExecutionCompiled method start.
@Override
public void start(CoreInstance func, ListIterable<? extends CoreInstance> arguments, OutputStream outputStream, OutputWriter writer) {
CompiledExecutionSupport executionSupport = new CompiledExecutionSupport(this.javaCompilerEventHandler.getJavaCompileState(), (CompiledProcessorSupport) this.getProcessorSupport(), this.sourceRegistry, this.runtime.getCodeStorage(), this.runtime.getIncrementalCompiler(), this.executionActivityListener, this.consoleCompiled, this.javaCompilerEventHandler.getFunctionCache(), this.javaCompilerEventHandler.getClassCache(), this.metadataCompilerEventHandler, this.extraSupportedTypes, this.runtime.getOptions());
Exception exception = null;
try {
Object result = this.executeFunction(func, arguments, executionSupport);
try {
writer.write(result, outputStream);
} catch (PureExecutionException ex) {
exception = ex;
throw new PureExecutionStreamingException(ex);
} catch (IOException e) {
exception = e;
throw new RuntimeException("Failed to write results to OutputStream", e);
}
} finally {
executionSupport.executionEnd(exception);
}
}
Aggregations