Search in sources :

Example 1 with IRestorer

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();
}
Also used : IRestorer(org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruption.IRestorer) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) Test(org.junit.Test)

Example 2 with IRestorer

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();
}
Also used : IRestorer(org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruption.IRestorer) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) Test(org.junit.Test)

Example 3 with IRestorer

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();
}
Also used : IRestorer(org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruption.IRestorer) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) Test(org.junit.Test)

Example 4 with IRestorer

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();
    }
}
Also used : IRestorer(org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruption.IRestorer)

Example 5 with IRestorer

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();
    }
}
Also used : IRestorer(org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruption.IRestorer) JMSException(javax.jms.JMSException)

Aggregations

IRestorer (org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruption.IRestorer)6 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)3 Test (org.junit.Test)3 EOFException (java.io.EOFException)1 JMSException (javax.jms.JMSException)1