use of org.eclipse.scout.rt.platform.util.concurrent.FutureCancelledError in project scout.rt by eclipse.
the class AbstractPageWithTable method loadChildrenImpl.
/**
* load tree children<br>
* this method delegates to the table reload<br>
* when the table is loaded and this node is not a leaf node then the table rows are mirrored in child nodes
*/
@Override
protected final void loadChildrenImpl() {
ITree tree = getTree();
try {
if (tree != null) {
tree.setTreeChanging(true);
}
//
// backup currently selected tree node and its path to root
boolean oldSelectionOwned = false;
int oldSelectionDirectChildIndex = -1;
ITreeNode oldSelectedNode = null;
if (tree != null) {
oldSelectedNode = tree.getSelectedNode();
}
List<Object> oldSelectedRowKeys = null;
if (oldSelectedNode != null) {
ITreeNode t = oldSelectedNode;
while (t != null && t.getParentNode() != null) {
if (t.getParentNode() == this) {
oldSelectionOwned = true;
oldSelectedRowKeys = getTableRowFor(t).getKeyValues();
oldSelectionDirectChildIndex = t.getChildNodeIndex();
break;
}
t = t.getParentNode();
}
}
//
setChildrenLoaded(false);
fireBeforeDataLoaded();
try {
loadTableDataImpl();
} catch (ThreadInterruptedError | FutureCancelledError e) {
// NOSONAR
// NOOP
} finally {
fireAfterDataLoaded();
}
setChildrenLoaded(true);
setChildrenDirty(false);
// table events will handle automatic tree changes in case table is mirrored in tree.
// restore currently selected tree node when it was owned by our table rows.
// in case selection was lost, try to select similar index as before
T table = getTable();
if (tree != null && table != null && oldSelectionOwned && tree.getSelectedNode() == null) {
ITreeNode newSelectedNode = null;
ITableRow row = table.getSelectedRow();
if (row != null) {
newSelectedNode = getTreeNodeFor(row);
} else {
row = table.findRowByKey(oldSelectedRowKeys);
if (row != null) {
newSelectedNode = getTreeNodeFor(row);
} else if (oldSelectedNode != null && oldSelectedNode.getTree() == tree) {
// NOSONAR
newSelectedNode = oldSelectedNode;
} else {
int index = Math.max(-1, Math.min(oldSelectionDirectChildIndex, getChildNodeCount() - 1));
if (index >= 0 && index < getChildNodeCount()) {
newSelectedNode = getChildNode(index);
} else {
newSelectedNode = this;
}
}
}
if (newSelectedNode != null) {
tree.selectNode(newSelectedNode);
}
}
} finally {
if (tree != null) {
tree.setTreeChanging(false);
}
}
IDesktop desktop = ClientSessionProvider.currentSession().getDesktop();
if (desktop != null) {
desktop.afterTablePageLoaded(this);
}
}
use of org.eclipse.scout.rt.platform.util.concurrent.FutureCancelledError in project scout.rt by eclipse.
the class BasicTransaction method cancel.
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
synchronized (m_memberMapLock) {
if (m_commitPhase) {
return false;
}
if (m_cancelled) {
return true;
}
m_cancelled = true;
addFailure(new FutureCancelledError("Transaction cancelled"));
}
for (ITransactionMember mem : getMembers()) {
try {
mem.cancel();
} catch (Throwable t) {
LOG.error("cancel member {}", mem, t);
}
}
return true;
}
use of org.eclipse.scout.rt.platform.util.concurrent.FutureCancelledError in project scout.rt by eclipse.
the class HttpServiceTunnel method tunnel.
@Override
protected ServiceTunnelResponse tunnel(final ServiceTunnelRequest serviceRequest) {
final long requestSequence = serviceRequest.getRequestSequence();
// Create the Callable to be given to the job manager for execution.
final RemoteServiceInvocationCallable remoteInvocationCallable = createRemoteServiceInvocationCallable(serviceRequest);
// Register the execution monitor as child monitor of the current monitor so that the service request is cancelled once the current monitor gets cancelled.
// Invoke the service operation asynchronously (to enable cancellation) and wait until completed or cancelled.
final IFuture<ServiceTunnelResponse> future = Jobs.schedule(remoteInvocationCallable, Jobs.newInput().withRunContext(RunContext.CURRENT.get().copy()).withName(createServiceRequestName(requestSequence)).withExceptionHandling(null, // do not handle uncaught exceptions because typically invoked from within a model job (might cause a deadlock, because ClientExceptionHandler schedules and waits for a model job to visualize the exception).
false)).whenDone(new IDoneHandler<ServiceTunnelResponse>() {
@Override
public void onDone(DoneEvent<ServiceTunnelResponse> event) {
if (event.isCancelled()) {
remoteInvocationCallable.cancel();
}
}
}, RunContext.CURRENT.get().copy().withRunMonitor(// separate monitor to not cancel this cancellation action.
BEANS.get(RunMonitor.class)));
try {
return future.awaitDoneAndGet();
} catch (ThreadInterruptedError e) {
// NOSONAR
// Ensure the monitor to be cancelled once this thread is interrupted to cancel the remote call.
future.cancel(true);
// Interruption has precedence over computation result or computation error.
return new ServiceTunnelResponse(new ThreadInterruptedError(TEXTS.get("UserInterrupted")));
} catch (FutureCancelledError e) {
// Cancellation has precedence over computation result or computation error.
return new ServiceTunnelResponse(new FutureCancelledError(TEXTS.get("UserInterrupted")));
}
}
use of org.eclipse.scout.rt.platform.util.concurrent.FutureCancelledError in project scout.rt by eclipse.
the class RemoteServiceInvocationCallable method call.
/**
* Invokes the remote service operation.
*
* @return {@link IServiceTunnelResponse}; is never <code>null</code>.
*/
@Override
public ServiceTunnelResponse call() throws Exception {
long nBytes = 0;
final long tStart = LOG.isDebugEnabled() ? System.nanoTime() : 0L;
try {
// Create the request.
final ByteArrayOutputStream requestMessage = new ByteArrayOutputStream();
m_tunnel.getContentHandler().writeRequest(requestMessage, m_serviceRequest);
requestMessage.close();
final byte[] requestData = requestMessage.toByteArray();
nBytes = requestData.length;
// Send the request to the server.
HttpResponse resp = m_tunnel.executeRequest(m_serviceRequest, requestData);
// Receive the response.
m_tunnel.interceptHttpResponse(resp, m_serviceRequest);
if (resp.getStatusCode() != 0 && (resp.getStatusCode() < 200 || resp.getStatusCode() > 299)) {
// request failed
return new ServiceTunnelResponse(new HttpException(resp.getStatusCode()));
}
try (InputStream in = resp.getContent()) {
return m_tunnel.getContentHandler().readResponse(in);
}
} catch (IOException e) {
if (Thread.currentThread().isInterrupted()) {
LOG.debug("Ignoring IOException for interrupted thread.", e);
return new ServiceTunnelResponse(new ThreadInterruptedError("Thread is interrupted.", e));
} else if (RunMonitor.CURRENT.get().isCancelled()) {
LOG.debug("Ignoring IOException for cancelled thread.", e);
return new ServiceTunnelResponse(new FutureCancelledError("RunMonitor is cancelled.", e));
}
throw e;
} finally {
if (LOG.isDebugEnabled()) {
final long elapsedMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - tStart);
LOG.debug("TIME {}.{} {}ms {} bytes", m_serviceRequest.getServiceInterfaceClassName(), m_serviceRequest.getOperation(), elapsedMillis, nBytes);
}
}
}
use of org.eclipse.scout.rt.platform.util.concurrent.FutureCancelledError in project scout.rt by eclipse.
the class JobExceptionTranslationTest method testWithNullExceptionTranslator.
@Test
public void testWithNullExceptionTranslator() throws Throwable {
final FutureCancelledError cancellationException = new FutureCancelledError("expected JUnit test exception");
IFuture<Void> future = Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
throw cancellationException;
}
}, Jobs.newInput());
try {
future.awaitDoneAndGet(NullExceptionTranslator.class);
fail("ExecutionException expected");
} catch (FutureCancelledError e) {
fail("ExecutionException expected");
} catch (ExecutionException e) {
assertFalse(future.isCancelled());
assertSame(cancellationException, e.getCause());
}
}
Aggregations