use of org.eclipse.scout.rt.platform.context.RunContext in project scout.rt by eclipse.
the class JobsTest method testNewInput.
@Test
public void testNewInput() {
RunContext runContext = RunContexts.empty();
assertSame(runContext, Jobs.newInput().withRunContext(runContext).getRunContext());
assertEquals("scout-thread", Jobs.newInput().getThreadName());
assertNull(Jobs.newInput().getRunContext());
}
use of org.eclipse.scout.rt.platform.context.RunContext in project scout.rt by eclipse.
the class JobCancelTest method testCancelledWithEmptyRunContextAndCancellationOnMonitor.
@Test
public void testCancelledWithEmptyRunContextAndCancellationOnMonitor() {
final BlockingCountDownLatch setupLatch = new BlockingCountDownLatch(1);
final BlockingCountDownLatch assertLatch = new BlockingCountDownLatch(1);
final AtomicBoolean cancelled = new AtomicBoolean();
// Run test within RunContext to ensure a current RunMonitor
RunContexts.empty().run(new IRunnable() {
@Override
public void run() throws Exception {
RunContext emptyRunContext = RunContexts.empty();
Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
setupLatch.countDownAndBlock();
cancelled.set(RunMonitor.CURRENT.get().isCancelled());
assertLatch.countDown();
}
}, Jobs.newInput().withRunContext(emptyRunContext));
setupLatch.await();
emptyRunContext.getRunMonitor().cancel(false);
setupLatch.unblock();
assertLatch.await();
assertTrue("cancellation expected", cancelled.get());
}
});
}
use of org.eclipse.scout.rt.platform.context.RunContext in project scout.rt by eclipse.
the class JobScheduleTest method testScheduleJobWithCancelledRunMonitor.
@Test
public void testScheduleJobWithCancelledRunMonitor() {
// setup run context with already cancelled run monitor
RunContext runContext = RunContexts.empty();
runContext.getRunMonitor().cancel(true);
// schedule job
IFuture<Void> future = Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
fail("job must not be executed");
}
}, Jobs.newInput().withRunContext(runContext));
future.awaitDone();
assertTrue(future.isCancelled());
// future must not be referenced by job manager
assertEquals(0, Jobs.getJobManager().getFutures(Jobs.newFutureFilterBuilder().andMatchFuture(future).toFilter()).size());
}
use of org.eclipse.scout.rt.platform.context.RunContext in project scout.rt by eclipse.
the class JaxWsRunContextLookup method lookup.
/**
* Looks up the {@link RunContext} from the given {@link WebServiceContext}.
*
* @return {@link RunContext}, is never <code>null</code>.
*/
public RunContext lookup(final WebServiceContext webServiceContext) {
final RunContext runContext = lookupRunContext(webServiceContext);
final Subject subject = lookupSubject(webServiceContext, runContext);
final String cid = lookupCorrelationId(webServiceContext, runContext);
final MessageContext messageContext = webServiceContext.getMessageContext();
final JaxWsImplementorSpecifics implementor = BEANS.get(JaxWsImplementorSpecifics.class);
HttpServletRequest request = implementor.getServletRequest(messageContext);
HttpServletResponse response = implementor.getServletResponse(messageContext);
return runContext.withSubject(subject).withCorrelationId(cid).withThreadLocal(IWebServiceContext.CURRENT, webServiceContext).withThreadLocal(IHttpServletRoundtrip.CURRENT_HTTP_SERVLET_REQUEST, request).withThreadLocal(IHttpServletRoundtrip.CURRENT_HTTP_SERVLET_RESPONSE, response).withDiagnostics(BEANS.get(ServletDiagnosticsProviderFactory.class).getProviders(request, response));
}
use of org.eclipse.scout.rt.platform.context.RunContext in project scout.rt by eclipse.
the class AbstractHealthCheckServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
disableCaching(req, resp);
RunContext context;
try {
context = execCreateRunContext();
if (context == null) {
throw new IllegalArgumentException("context must not be null");
}
} catch (Throwable t) {
LOG.error("Creating RunContext failed", t);
throw BEANS.get(ServletExceptionTranslator.class).translate(t);
}
try {
doChecks(context, req, resp);
} catch (Throwable t) {
LOG.error("HealthChecking crashed", t);
throw BEANS.get(ServletExceptionTranslator.class).translate(t);
}
}
Aggregations