use of org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError in project scout.rt by eclipse.
the class AbstractDesktop method closeInternal.
@Override
public void closeInternal() {
setOpenedInternal(false);
detachGui();
List<IForm> showedForms = new ArrayList<IForm>();
// Remove showed forms
for (IForm form : m_formStore.values()) {
hideForm(form);
showedForms.add(form);
}
// extensions
for (IDesktopExtension ext : getDesktopExtensions()) {
try {
ContributionCommand cc = ext.desktopClosingDelegate();
if (cc == ContributionCommand.Stop) {
break;
}
} catch (RuntimeException | PlatformError t) {
LOG.error("extension {}", ext, t);
}
}
// close messageboxes
for (IMessageBox m : getMessageBoxes()) {
if (m != null) {
try {
m.getUIFacade().setResultFromUI(IMessageBox.CANCEL_OPTION);
} catch (RuntimeException | PlatformError e) {
LOG.error("Exception while closing messagebox", e);
}
}
}
// close filechoosers
for (IFileChooser f : getFileChoosers()) {
if (f != null) {
try {
f.getUIFacade().setResultFromUI(Collections.<BinaryResource>emptyList());
} catch (RuntimeException | PlatformError e) {
LOG.error("Exception while closing filechooser", e);
}
}
}
// close client callbacks
for (ClientCallback<?> c : CollectionUtility.arrayList(m_pendingPositionResponses)) {
if (c != null) {
try {
c.cancel(true);
c.failed(new ThreadInterruptedError("desktop is closing"));
} catch (RuntimeException | PlatformError e) {
LOG.error("Exception while closing client callback", e);
}
}
}
// close open forms
for (IForm form : showedForms) {
if (form != null) {
try {
form.doClose();
} catch (RuntimeException | PlatformError e) {
LOG.error("Exception while closing form", e);
}
}
}
// dispose outlines
for (IOutline outline : getAvailableOutlines()) {
try {
outline.disposeTree();
} catch (RuntimeException | PlatformError e) {
LOG.warn("Exception while disposing outline.", e);
}
}
ActionUtility.disposeActions(getActions());
fireDesktopClosed();
}
use of org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError in project scout.rt by eclipse.
the class WhenDoneScheduleTest method testFunctionFutureState.
@Test
public void testFunctionFutureState() throws InterruptedException {
final BlockingCountDownLatch jobRunningLatch = new BlockingCountDownLatch(1);
final BlockingCountDownLatch functionJobRunningLatch = new BlockingCountDownLatch(1);
// Schedule future
IFuture<Void> future = Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
jobRunningLatch.countDownAndBlock();
}
}, Jobs.newInput().withExecutionHint(JOB_MARKER));
// Schedule function
IFuture<Void> functionFuture = future.whenDoneSchedule(new IBiConsumer<Void, Throwable>() {
@Override
public void accept(Void result, Throwable u) {
try {
functionJobRunningLatch.countDownAndBlock();
} catch (InterruptedException e) {
throw new ThreadInterruptedError("interrupted", e);
}
}
}, Jobs.newInput().withExecutionHint(JOB_MARKER));
assertTrue(jobRunningLatch.await());
assertEquals(JobState.RUNNING, future.getState());
assertEquals(JobState.NEW, functionFuture.getState());
jobRunningLatch.unblock();
assertTrue(functionJobRunningLatch.await());
assertEquals(JobState.DONE, future.getState());
assertEquals(JobState.RUNNING, functionFuture.getState());
functionJobRunningLatch.unblock();
// Wait until the job jobs are done
Jobs.getJobManager().awaitDone(Jobs.newFutureFilterBuilder().andMatchExecutionHint(JOB_MARKER).toFilter(), 5, TimeUnit.SECONDS);
assertEquals(JobState.DONE, functionFuture.getState());
assertEquals(JobState.DONE, future.getState());
}
use of org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError in project scout.rt by eclipse.
the class BlockingConditionInterruptionTest method runTest.
private static void runTest(final List<String> protocol, final WaitMethod waitForMethod, final InterruptionAction interruptionAction) {
final String HINT_BLOCKED = "blocked";
final AtomicReference<Thread> runnerThread = new AtomicReference<>();
final IBlockingCondition bc = Jobs.newBlockingCondition(true);
// Schedule job to enter blocking condition
final IFuture<Void> future = Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
runnerThread.set(Thread.currentThread());
if (InterruptionAction.INTERRUPT_BEFORE_ENTERING.equals(interruptionAction)) {
Thread.currentThread().interrupt();
}
try {
protocol.add("beforeBlockingCondition");
switch(waitForMethod) {
case WAIT_INTERRUPTIBLY:
bc.waitFor(HINT_BLOCKED);
break;
case WAIT_FOR_INTERRUPTIBLY_WITH_TIMEOUT:
bc.waitFor(0, TimeUnit.MILLISECONDS, HINT_BLOCKED);
break;
case WAIT_FOR_UNINTERRUPTIBLY:
bc.waitForUninterruptibly(HINT_BLOCKED);
break;
case WAIT_FOR_UNINTERRUPTIBLY_WITH_TIMEOUT:
bc.waitForUninterruptibly(0, TimeUnit.MILLISECONDS, HINT_BLOCKED);
break;
default:
throw new UnsupportedOperationException();
}
protocol.add("afterBlockingCondition");
} catch (ThreadInterruptedError e) {
protocol.add("InterruptedException");
} catch (TimedOutError e) {
protocol.add("TimeoutException");
}
if (Thread.currentThread().isInterrupted()) {
protocol.add("threadInterrupted");
}
}
}, Jobs.newInput().withName("test job").withExecutionHint(JOB_IDENTIFIER));
// Wait until the job enters blocking condition, or is done.
JobTestUtil.waitForCondition(new ICondition() {
@Override
public boolean isFulfilled() {
return future.containsExecutionHint(HINT_BLOCKED) || future.isDone();
}
});
if (InterruptionAction.INTERRUPT_WHILE_BLOCKING.equals(interruptionAction)) {
runnerThread.get().interrupt();
// Sleep some time so that the runner is interrupted.
// That is because a thread's interruption is asynchronous, meaning that once a thread (a) interrupts another threads
// (b), and in turn thread (a) unblocks the condition which thread (b) is waiting for, it is not ensured that thread
// (b) exists with an {@link InterruptedException}. However, many tests expect exactly that behavior.
SleepUtil.sleepSafe(100, TimeUnit.MILLISECONDS);
}
bc.setBlocking(false);
Jobs.getJobManager().awaitDone(Jobs.newFutureFilterBuilder().andMatchExecutionHint(JOB_IDENTIFIER).toFilter(), 10, TimeUnit.SECONDS);
}
use of org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError in project scout.rt by eclipse.
the class BlockingConditionTest method testHintsUponInterruption.
@Test
public void testHintsUponInterruption() throws Throwable {
final IBlockingCondition blockingCondition = Jobs.newBlockingCondition(true);
final BlockingCountDownLatch setupLatch = new BlockingCountDownLatch(1);
final P_ExceptionCapturer exceptionCapturer = new P_ExceptionCapturer();
IFuture<Void> future = Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
setupLatch.countDown();
try {
blockingCondition.waitFor(10, TimeUnit.SECONDS, "hint-blocking");
fail("ThreadInterruptedError expected");
} catch (ThreadInterruptedError e) {
assertFalse("hint not unset", IFuture.CURRENT.get().containsExecutionHint("hint-blocking"));
}
}
}, Jobs.newInput().withExceptionHandling(exceptionCapturer, true));
setupLatch.await();
future.cancel(true);
future.awaitFinished(10, TimeUnit.SECONDS);
exceptionCapturer.throwOnError();
}
use of org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError in project scout.rt by eclipse.
the class FutureAwaitTest method testAwaitDoneWithTimeout_Interrupted.
@Test(timeout = 5000)
public void testAwaitDoneWithTimeout_Interrupted() 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()));
// Run the test in a separate thread
IFuture<Void> controller = Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
Thread.currentThread().interrupt();
try {
future.awaitDone(10, TimeUnit.SECONDS);
fail("interruption expected");
} catch (ThreadInterruptedError e) {
assertTrue(Thread.currentThread().isInterrupted());
}
}
}, Jobs.newInput());
controller.awaitDoneAndGet(10, TimeUnit.SECONDS);
setupLatch.unblock();
future.awaitDone(10, TimeUnit.SECONDS);
}
Aggregations