use of org.eclipse.scout.rt.platform.util.concurrent.FutureCancelledError in project scout.rt by eclipse.
the class FutureAwaitTest method testAwaitDoneAndGet_Cancelled.
@Test(timeout = 5000)
public void testAwaitDoneAndGet_Cancelled() throws java.lang.InterruptedException {
final BlockingCountDownLatch setupLatch = new BlockingCountDownLatch(1);
// Init
final IFuture<String> future = Jobs.schedule(new Callable<String>() {
@Override
public String call() throws Exception {
setupLatch.countDownAndBlock();
return "result";
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()));
// Wait until ready
assertTrue(setupLatch.await());
// Run the test and verify
future.cancel(false);
try {
future.awaitDoneAndGet();
fail("cancellation expected");
} catch (FutureCancelledError e) {
assertTrue(future.isCancelled());
}
setupLatch.unblock();
}
use of org.eclipse.scout.rt.platform.util.concurrent.FutureCancelledError in project scout.rt by eclipse.
the class UiSession method processFileUpload.
@Override
public JSONObject processFileUpload(HttpServletRequest req, HttpServletResponse res, final IBinaryResourceConsumer resourceConsumer, final List<BinaryResource> uploadResources, final Map<String, String> uploadProperties) {
final ClientRunContext clientRunContext = ClientRunContexts.copyCurrent().withSession(m_clientSession, true);
m_httpContext.set(req, res);
try {
m_processingJsonRequest = true;
try {
// 1. Process the JSON request.
ModelJobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
resourceConsumer.consumeBinaryResource(uploadResources, uploadProperties);
}
}, createFileUploadModelJobInput(clientRunContext));
// 2. Wait for all model jobs of the session.
BEANS.get(UiJobs.class).awaitModelJobs(m_clientSession, ExceptionHandler.class);
} finally {
// Reset this flag _before_ the "response-to-json" job (#3), because writing to the response while transforming would be unsafe and unreliable.
m_processingJsonRequest = false;
}
// 3. Transform the response to JSON.
final IFuture<JSONObject> future = ModelJobs.schedule(newResponseToJsonTransformer(), ModelJobs.newInput(clientRunContext.copy().withRunMonitor(// separate RunMonitor to not cancel 'response-to-json' job once processing is cancelled
BEANS.get(RunMonitor.class))).withName("Transforming response to JSON").withExecutionHint(UiJobs.EXECUTION_HINT_RESPONSE_TO_JSON).withExceptionHandling(null, // Propagate exception to caller (UIServlet)
false));
try {
return BEANS.get(UiJobs.class).awaitAndGet(future);
} catch (ThreadInterruptedError e) {
// NOSONAR
future.cancel(true);
return null;
} catch (FutureCancelledError e) {
// NOSONAR
return null;
}
} finally {
m_httpContext.clear();
if (m_disposing) {
dispose();
}
}
}
use of org.eclipse.scout.rt.platform.util.concurrent.FutureCancelledError in project scout.rt by eclipse.
the class UiSession method processJsonRequest.
@Override
public JSONObject processJsonRequest(final HttpServletRequest servletRequest, final HttpServletResponse servletResponse, final JsonRequest jsonRequest) {
if (isAlreadyProcessed(jsonRequest)) {
JSONObject response = m_responseHistory.getResponseForRequest(jsonRequest.getSequenceNo());
LOG.debug("Request #{} was already processed. Sending back response from history.", jsonRequest.getSequenceNo());
return response;
}
final ClientRunContext clientRunContext = ClientRunContexts.copyCurrent().withSession(m_clientSession, true);
m_httpContext.set(servletRequest, servletResponse);
m_currentJsonRequest = jsonRequest;
try {
m_processingJsonRequest = true;
try {
// 1. Process the JSON request.
ModelJobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
processJsonRequestInternal();
}
}, createJsonRequestModelJobInput(jsonRequest, clientRunContext));
// 2. Wait for all model jobs of the session.
BEANS.get(UiJobs.class).awaitModelJobs(m_clientSession, ExceptionHandler.class);
} finally {
// Reset this flag _before_ the "response-to-json" job (#3), because writing to the response while transforming would be unsafe and unreliable.
m_processingJsonRequest = false;
}
// 3. Transform the response to JSON.
final IFuture<JSONObject> future = ModelJobs.schedule(newResponseToJsonTransformer(), ModelJobs.newInput(clientRunContext.copy().withRunMonitor(// separate RunMonitor to not cancel 'response-to-json' job once processing is cancelled
BEANS.get(RunMonitor.class))).withName("Transforming response to JSON").withExecutionHint(UiJobs.EXECUTION_HINT_RESPONSE_TO_JSON).withExecutionHint(UiJobs.EXECUTION_HINT_POLL_REQUEST, jsonRequest.getRequestType() == RequestType.POLL_REQUEST).withExceptionHandling(null, // Propagate exception to caller (UIServlet)
false));
try {
return BEANS.get(UiJobs.class).awaitAndGet(future);
} catch (ThreadInterruptedError e) {
// NOSONAR
future.cancel(true);
return null;
} catch (FutureCancelledError e) {
// NOSONAR
return null;
}
} finally {
setRequestProcessed(jsonRequest);
m_httpContext.clear();
m_currentJsonRequest = null;
if (m_disposing) {
dispose();
}
if (LOG.isDebugEnabled()) {
LOG.debug("Adapter count after request: {}", m_jsonAdapterRegistry.size());
}
}
}
Aggregations