use of org.eclipse.scout.rt.platform.holders.Holder in project scout.rt by eclipse.
the class AbstractOutline method findPage.
@Override
public <T extends IPage> T findPage(final Class<T> pageType) {
final Holder<T> result = new Holder<T>(pageType, null);
ITreeVisitor v = new ITreeVisitor() {
@Override
@SuppressWarnings("unchecked")
public boolean visit(ITreeNode node) {
IPage<?> page = (IPage) node;
Class<? extends IPage> pageClass = page.getClass();
if (pageType.isAssignableFrom(pageClass)) {
result.setValue((T) page);
}
return result.getValue() == null;
}
};
visitNode(getRootNode(), v);
return result.getValue();
}
use of org.eclipse.scout.rt.platform.holders.Holder in project scout.rt by eclipse.
the class WhenDoneTest method testError.
@Test
public void testError() throws InterruptedException {
// synchronized because modified/read by different threads.
final List<String> protocol = Collections.synchronizedList(new ArrayList<String>());
final Holder<DoneEvent<String>> eventHolder = new Holder<>();
final ProcessingException pe = new ProcessingException("expected JUnit test exception");
final IFuture<String> future = Jobs.schedule(new Callable<String>() {
@Override
public String call() throws Exception {
protocol.add("1");
throw pe;
}
}, Jobs.newInput().withExceptionHandling(null, false).withExecutionTrigger(Jobs.newExecutionTrigger().withStartIn(1, TimeUnit.SECONDS)));
final BlockingCountDownLatch verifyLatch = new BlockingCountDownLatch(1);
future.whenDone(new IDoneHandler<String>() {
@Override
public void onDone(DoneEvent<String> event) {
protocol.add("2");
if (future.isDone()) {
protocol.add("done");
}
if (future.isCancelled()) {
protocol.add("cancelled");
}
eventHolder.setValue(event);
verifyLatch.countDown();
}
}, RunContexts.copyCurrent());
assertTrue(verifyLatch.await());
assertEquals(CollectionUtility.arrayList("1", "2", "done"), protocol);
assertSame(pe, eventHolder.getValue().getException());
assertNull(eventHolder.getValue().getResult());
assertFalse(eventHolder.getValue().isCancelled());
assertTrue(eventHolder.getValue().isFailed());
}
use of org.eclipse.scout.rt.platform.holders.Holder in project scout.rt by eclipse.
the class WhenDoneTest method testCancel.
@Test
public void testCancel() throws InterruptedException {
// synchronized because modified/read by different threads.
final List<String> protocol = Collections.synchronizedList(new ArrayList<String>());
final Holder<DoneEvent<String>> eventHolder = new Holder<>();
final IFuture<String> future = Jobs.schedule(new Callable<String>() {
@Override
public String call() throws Exception {
protocol.add("1");
return "result";
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExecutionTrigger(Jobs.newExecutionTrigger().withStartIn(1, TimeUnit.SECONDS)));
future.cancel(true);
final BlockingCountDownLatch verifyLatch = new BlockingCountDownLatch(1);
future.whenDone(new IDoneHandler<String>() {
@Override
public void onDone(DoneEvent<String> event) {
protocol.add("2");
if (future.isDone()) {
protocol.add("done");
}
if (future.isCancelled()) {
protocol.add("cancelled");
}
eventHolder.setValue(event);
verifyLatch.countDown();
}
}, RunContexts.copyCurrent());
assertTrue(verifyLatch.await());
assertEquals(CollectionUtility.arrayList("2", "done", "cancelled"), protocol);
assertNull(eventHolder.getValue().getException());
assertNull(eventHolder.getValue().getResult());
assertTrue(eventHolder.getValue().isCancelled());
assertFalse(eventHolder.getValue().isFailed());
}
use of org.eclipse.scout.rt.platform.holders.Holder in project scout.rt by eclipse.
the class WhenDoneTest method testCancelWithJobAlreadyCompleted.
@Test
public void testCancelWithJobAlreadyCompleted() throws InterruptedException {
// synchronized because modified/read by different threads.
final List<String> protocol = Collections.synchronizedList(new ArrayList<String>());
final Holder<DoneEvent<String>> eventHolder = new Holder<>();
final IFuture<String> future = Jobs.schedule(new Callable<String>() {
@Override
public String call() throws Exception {
protocol.add("1");
return "result";
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()));
future.awaitDoneAndGet();
future.cancel(true);
final BlockingCountDownLatch verifyLatch = new BlockingCountDownLatch(1);
future.whenDone(new IDoneHandler<String>() {
@Override
public void onDone(DoneEvent<String> event) {
protocol.add("2");
if (future.isDone()) {
protocol.add("done");
}
if (future.isCancelled()) {
protocol.add("cancelled");
}
eventHolder.setValue(event);
verifyLatch.countDown();
}
}, RunContexts.copyCurrent());
assertTrue(verifyLatch.await());
assertEquals(CollectionUtility.arrayList("1", "2", "done"), protocol);
assertNull(eventHolder.getValue().getException());
assertEquals("result", eventHolder.getValue().getResult());
assertFalse(eventHolder.getValue().isCancelled());
assertFalse(eventHolder.getValue().isFailed());
}
use of org.eclipse.scout.rt.platform.holders.Holder in project scout.rt by eclipse.
the class WhenDoneTest method testErrorWithJobAlreadyCompleted.
@Test
public void testErrorWithJobAlreadyCompleted() throws InterruptedException {
// synchronized because modified/read by different threads.
final List<String> protocol = Collections.synchronizedList(new ArrayList<String>());
final Holder<DoneEvent<String>> eventHolder = new Holder<>();
final Exception error = new ProcessingException("expected JUnit test exception");
final IFuture<String> future = Jobs.schedule(new Callable<String>() {
@Override
public String call() throws Exception {
protocol.add("1");
throw error;
}
}, Jobs.newInput().withExceptionHandling(null, false));
try {
future.awaitDoneAndGet();
fail("exception expected");
} catch (ProcessingException e) {
final BlockingCountDownLatch verifyLatch = new BlockingCountDownLatch(1);
future.whenDone(new IDoneHandler<String>() {
@Override
public void onDone(DoneEvent<String> event) {
protocol.add("2");
if (future.isDone()) {
protocol.add("done");
}
if (future.isCancelled()) {
protocol.add("cancelled");
}
eventHolder.setValue(event);
verifyLatch.countDown();
}
}, RunContexts.copyCurrent());
assertTrue(verifyLatch.await());
assertEquals(CollectionUtility.arrayList("1", "2", "done"), protocol);
assertSame(error, eventHolder.getValue().getException());
assertNull(eventHolder.getValue().getResult());
assertFalse(eventHolder.getValue().isCancelled());
assertTrue(eventHolder.getValue().isFailed());
}
}
Aggregations