This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 304361 - [app] enhance the eclipse application container to allow for async application results
Summary: [app] enhance the eclipse application container to allow for async applicatio...
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Compendium (show other bugs)
Version: 3.6   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.6 M6   Edit
Assignee: Thomas Watson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-02 09:50 EST by Thomas Watson CLA
Modified: 2010-07-30 13:33 EDT (History)
2 users (show)

See Also:


Attachments
patch + tests (16.62 KB, patch)
2010-03-02 09:54 EST, Thomas Watson CLA
no flags Details | Diff
patch + tests (18.52 KB, patch)
2010-03-02 16:53 EST, Thomas Watson CLA
no flags Details | Diff
update patch + tests (22.80 KB, text/plain)
2010-03-02 18:14 EST, Thomas Watson CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Watson CLA 2010-03-02 09:50:09 EST
The current eclipse application container expects an application to execute in a single thread and block on the thread until it has finished and has returned an application result from IApplication.start(...).  The IApplication.start(...) method is expected to block on the current thread until the application has finished and it returns an exit result.

There are cases where this is not desired.  Imagine an application that wants to share the SWT Display which is running the UI event loop on the main thread.  Such an application has no use for blocking on the current thread to run the UI event loop itself.  It would be nice if such an application could return from IApplication.start(...) and deliver the exit result later asynchronously.

This way the IApplication.start(...) method could hook into the Display running on the main thread and then return immediately and not waste an extra thread blocking.  Later when the application has exited it could deliver the exit result to the application container to indicate that the application has finished.
Comment 1 Thomas Watson CLA 2010-03-02 09:54:52 EST
Created attachment 160621 [details]
patch + tests

Here is a patch that adds the following API to IApplicationContext:

/**
 * Exit object that indicates the application result will be delivered asynchronously.
 * This object must be returned by the method {@link IApplication#start(IApplicationContext)}
 * for applications which deliver a result asynchronously with the method
 * {@link IApplicationContext#setResult(Object)}.
 * @since 1.3
 */
public static final Object EXIT_ASYNC_RESULT = new Object();

/**
 * Sets the result of the application asynchronously.  This method can only be used
 * after the application's {@link IApplication#start(IApplicationContext) start} 
 * method has returned the value of {@link IApplicationContext#EXIT_ASYNC_RESULT}.
 * @since 1.3
 * @throws IllegalStateException if {@link IApplicationContext#EXIT_ASYNC_RESULT} was
 * not returned by the application's {@link IApplication#start(IApplicationContext) start}
 * method or if the result has already been set for this application context.
 */
public void setResult(Object result);
Comment 2 Thomas Watson CLA 2010-03-02 16:53:03 EST
Created attachment 160695 [details]
patch + tests

More javadoc updates to IApplication.start(...)
Comment 3 Thomas Watson CLA 2010-03-02 18:14:31 EST
Created attachment 160711 [details]
update patch + tests

There is a concern with the previous API for IApplicationContext.setResult(...) because it could allow any random code to set the result of an application context.  We should really only allow the IApplication instance to set the result of an application context.

This patch adds an additional parameter for passing the IApplication instance when setting the result.  This instance must be the same instance of IApplication that is associated with the application context; otherwise an IllegalArgumentException is thrown.  This provides an implicit token (the application instance) that must be used to allow a caller to set the result.  Application instances are not typically shared outside of the context of the IApplication implementation.  This will provide us with a level of protection by preventing unwanted calls to setResult.
Comment 4 Thomas Watson CLA 2010-03-02 18:15:46 EST
I released this patch to head.
Comment 5 Alex CLA 2010-07-29 19:52:08 EDT
I am seeing an unfortunate change in behavior of eclipsec.exe exit codes, I think I tracked it down to this change.

Prior to this (specifically with org.eclipse.equinox.app_1.3.0.v20100108) an application throwing an exception resulted with e.g. eclipsec.exe exiting with exit code 13. (Looks like this is a standard behavior of EclipseStarter#run, in case 'eclipse.exitcode' is left null.) Now the exit code is 0. 

Specific use case is running of an org.eclipse.ant.core.antRunner with ant script that fails (exception thrown by one of the tasks) - it used to be possible to detect the failure based on the non-zero exit code.

It seems to be related to that prior to this fix EclipseAppHandle#run was not setting the eclipse.exitcode in case of exception - Activator#setProperty was after the 'finally' block. Now it is in the 'finally' block, via setInternalResult.  And the logic there appears to translate null into 0, vs EclipseStarter#run null -> 13.

Observed on Windows 7 64 bit, Eclipse 3.6.
Comment 6 Thomas Watson CLA 2010-07-29 22:52:46 EDT
(In reply to comment #5)
> I am seeing an unfortunate change in behavior of eclipsec.exe exit codes, I
> think I tracked it down to this change.

I suggest you open a new bug to track this issue.
Comment 7 Alex CLA 2010-07-30 13:33:00 EDT
(In reply to comment #6)
> (In reply to comment #5)
> > I am seeing an unfortunate change in behavior of eclipsec.exe exit codes, I
> > think I tracked it down to this change.
> 
> I suggest you open a new bug to track this issue.

Done, bug 321386.