use of org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruption.IRestorer in project scout.rt by eclipse.
the class ThreadInterruptionTest method testThreadInterrupted.
@Test
public void testThreadInterrupted() {
Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
Thread.currentThread().interrupt();
assertTrue(Thread.currentThread().isInterrupted());
IRestorer interruption = ThreadInterruption.clear();
assertFalse(Thread.currentThread().isInterrupted());
interruption.restore();
assertTrue(Thread.currentThread().isInterrupted());
}
}, Jobs.newInput().withExceptionHandling(null, false)).awaitDoneAndGet();
}
use of org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruption.IRestorer in project scout.rt by eclipse.
the class ThreadInterruptionTest method testThreadNotInterrupted.
@Test
public void testThreadNotInterrupted() {
Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
assertFalse(Thread.currentThread().isInterrupted());
IRestorer interruption = ThreadInterruption.clear();
assertFalse(Thread.currentThread().isInterrupted());
interruption.restore();
assertFalse(Thread.currentThread().isInterrupted());
}
}, Jobs.newInput().withExceptionHandling(null, false)).awaitDoneAndGet();
}
use of org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruption.IRestorer in project scout.rt by eclipse.
the class ThreadInterruptionTest method testInterruptionAfterClear.
@Test
public void testInterruptionAfterClear() {
Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
assertFalse(Thread.currentThread().isInterrupted());
IRestorer interruption = ThreadInterruption.clear();
assertFalse(Thread.currentThread().isInterrupted());
Thread.currentThread().interrupt();
interruption.restore();
assertTrue(Thread.currentThread().isInterrupted());
}
}, Jobs.newInput().withExceptionHandling(null, false)).awaitDoneAndGet();
}
use of org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruption.IRestorer in project scout.rt by eclipse.
the class ReplyMessageConsumerJob method handleRequest.
/**
* Delegates the request to the listener, and returns the message to be replied.
*/
protected void handleRequest(Message jmsRequest, IMessage<REQUEST> request, String replyId, Destination replyTopic) throws JMSException {
Object transferObject = null;
boolean success = true;
try {
transferObject = m_listener.onRequest(request);
} catch (Throwable t) {
// NOSONAR (Always send a response, even if a PlatformError is thrown. Otherwise the caller might wait forever.)
BEANS.get(ExceptionHandler.class).handle(t);
transferObject = interceptRequestReplyException(t);
success = false;
}
if (IFuture.CURRENT.get().isCancelled()) {
return;
}
// Temporarily clear the thread's interrupted status while sending a message.
IRestorer interruption = ThreadInterruption.clear();
IJmsSessionProvider sessionProvider = m_mom.createSessionProvider();
try {
JmsMessageWriter replyMessageWriter = JmsMessageWriter.newInstance(sessionProvider.getSession(), m_marshaller).writeReplyId(replyId).writeTransferObject(transferObject).writeRequestReplySuccess(success);
m_mom.send(sessionProvider.getProducer(), replyTopic, replyMessageWriter, jmsRequest.getJMSDeliveryMode(), jmsRequest.getJMSPriority(), Message.DEFAULT_TIME_TO_LIVE);
} finally {
sessionProvider.close();
interruption.restore();
}
}
use of org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruption.IRestorer in project scout.rt by eclipse.
the class JmsSessionProvider method close.
@Override
public void close() {
m_closing = true;
// Temporarily clear the thread's interrupted status while closing
IRestorer interruption = ThreadInterruption.clear();
try {
closeImpl();
} catch (JMSException e) {
throw BEANS.get(DefaultRuntimeExceptionTranslator.class).translate(e);
} finally {
interruption.restore();
}
}
Aggregations