Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How to start E4Application with ApplicationDescriptor.launch?
How to start E4Application with ApplicationDescriptor.launch? [message #915609] Mon, 17 September 2012 12:22 Go to next message
Karl Weber is currently offline Karl Weber
Messages: 63
Registered: September 2010
Member
I would like to start an OSGI framework that does not start the E4Application right away. Rather, I would like to start it later with ApplicationDescriptor.launch(...).

Currently I am running a product with
-Dosgi.noShutdown=true -Declipse.application.launchDefault=false -Declipse.allowAppRelaunch=true
and
-console
in the workbench. With these options I can start the E4Application from the console by typing
osgi> startApp org.eclipse.e4.ui.workbench.swt.E4Application
and things work as expected.

However, when I get the ApplicationDescriptor in some OSGi service and try to launch the E4Application with
ApplicationDesciptor.launch(null)
I get the following exception
org.osgi.service.application.ApplicationException: The main thread is not available to launch the application: org.eclipse.e4.ui.workbench.swt.E4Application.0


What am I missing here?
Re: How to start E4Application with ApplicationDescriptor.launch? [message #915631 is a reply to message #915609] Mon, 17 September 2012 13:00 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5014
Registered: July 2009
Senior Member
[resending because of thunderbird crazyness]

well how is your main application launched? My guess is that your
initial application is also launched on the main-Thread hence it is not
available for your launch.

So you can:
a) make your base osgi-application launch on any-Thread instead
b) execute the launch in a worker thread

On the JavaFX front we are currently working on a similar thing because
we want to launch the application through maven-tycho and then run
Jemmy-UI-Tests on it.

You can see my way of launching an e4 application in this code parts:
https://github.com/tomsontom/e-fx-clipse/blob/master/at.bestsolution.efxclipse.runtime.jemmy/src/at/bestsolution/efxclipse/runtime/jemmy/OSGiJemmyBootstrapTestCase.java

Tom

Am 17.09.12 18:22, schrieb Karl Weber:
> I would like to start an OSGI framework that does not start the
> E4Application right away. Rather, I would like to start it later with
> ApplicationDescriptor.launch(...).
>
> Currently I am running a product with -Dosgi.noShutdown=true
> -Declipse.application.launchDefault=false
> -Declipse.allowAppRelaunch=trueand -console in the workbench. With these
> options I can start the E4Application from the console by typing
>
> osgi> startApp org.eclipse.e4.ui.workbench.swt.E4Applicationand things
> work as expected.
>
> However, when I get the ApplicationDescriptor in some OSGi service and
> try to launch the E4Application with ApplicationDesciptor.launch(null)I
> get the following exception
> org.osgi.service.application.ApplicationException: The main thread is
> not available to launch the application:
> org.eclipse.e4.ui.workbench.swt.E4Application.0
>
> What am I missing here?
>
Re: How to start E4Application with ApplicationDescriptor.launch? [message #915946 is a reply to message #915631] Tue, 18 September 2012 05:16 Go to previous messageGo to next message
Karl Weber is currently offline Karl Weber
Messages: 63
Registered: September 2010
Member
Thomas Schindl wrote on Mon, 17 September 2012 19:00

well how is your main application launched? My guess is that your
initial application is also launched on the main-Thread hence it is not
available for your launch.

So you can:
a) make your base osgi-application launch on any-Thread instead
b) execute the launch in a worker thread


Well, at the beginning no application is launched, because I set the property
-Declipse.application.launchDefault=false
I have just an OSGi (component) service running, that is trying to start one (the first) application. I checked that: There is no service registered for the ApplicationHandle.class. Furthermore, it does not matter whether I try to launch the application in a worker thread or not, it does not make any difference. The property
-Declipse.allowAppRelaunch=true
does not make any difference either.

I do not understand your suggestion (a). The E4Application is singleton-global, so it cannot be run, when another application is already running, no matter on which thread.

How is your example working? I mean, is there another application running in your case when the method
OSGiJemmyBootstrapTestCase.setUp
is called? And what it the
Thread.sleep(..)
for?
Re: How to start E4Application with ApplicationDescriptor.launch? [message #915964 is a reply to message #915946] Tue, 18 September 2012 05:59 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5014
Registered: July 2009
Senior Member
Am 18.09.12 11:16, schrieb Karl Weber:
> Thomas Schindl wrote on Mon, 17 September 2012 19:00
>> well how is your main application launched? My guess is that your
>> initial application is also launched on the main-Thread hence it is not
>> available for your launch.
>>
>> So you can:
>> a) make your base osgi-application launch on any-Thread instead
>> b) execute the launch in a worker thread
>
>
> Well, at the beginning no application is launched, because I set the
> property-Declipse.application.launchDefault=false I have just an OSGi
> (component) service running, that is trying to start one (the first)
> application. I checked that: There is no service registered for the
> ApplicationHandle.class. Furthermore, it does not matter whether I try
> to launch the application in a worker thread or not, it does not make
> any difference. The property -Declipse.allowAppRelaunch=true does not
> make any difference either.
>
> I do not understand your suggestion (a). The E4Application is
> singleton-global, so it cannot be run, when another application is

I thought you are launching 2 OSGi-Applications hence the comment on the
any-Thread.

> already running, no matter on which thread.
> How is your example working? I mean, is there another application

I'm running 2 applications:
* headless junit application
* javafx e4 OSGi-Application

The JavaFX one which is not defined as a singleton application ;-) - not
sure why the SWT one is defined this way. I'd say we should not require
it to be a singleton.

> running in your case when the method OSGiJemmyBootstrapTestCase.setUp is
> called? And what it the Thread.sleep(..) for?

well I need to sleep to wait until the initial window is really shown.
Re: How to start E4Application with ApplicationDescriptor.launch? [message #915970 is a reply to message #915964] Tue, 18 September 2012 06:22 Go to previous messageGo to next message
Karl Weber is currently offline Karl Weber
Messages: 63
Registered: September 2010
Member
I seem to get closer. Since it worked in debugging mode(!) there must be an issue with some dependency. So I added a Thread.sleep(..) in front of ApplicationDescriptor.launch(..) and -- it works if I wait long enough. So, what is my dependency? For what do I have to wait?

Re: How to start E4Application with ApplicationDescriptor.launch? [message #915978 is a reply to message #915609] Tue, 18 September 2012 06:43 Go to previous messageGo to next message
Karl Weber is currently offline Karl Weber
Messages: 63
Registered: September 2010
Member
Maybe I got it: When I make my service component (the one which launches an application) dependent on the service
org.eclipse.osgi.service.runnable.ApplicationLauncher

it works. So I have to wait for the ApplicationLauncher service to be available -- which seems to make sence.
Re: How to start E4Application with ApplicationDescriptor.launch? [message #935802 is a reply to message #915964] Sun, 07 October 2012 06:32 Go to previous message
Karl Weber is currently offline Karl Weber
Messages: 63
Registered: September 2010
Member
Thomas Schindl wrote on Tue, 18 September 2012 11:59

[...]
The JavaFX one which is not defined as a singleton application Wink - not
sure why the SWT one is defined this way. I'd say we should not require
it to be a singleton.
[...]


The E4Application is singleton-global and not publicly visible (i.e. in an internal package). I think this is a bad combination which should be improved, i.e. by making E4Application publicly visible.

I filed a bug about this:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=391313

Previous Topic:Can we put one component inside another XWT composite
Next Topic:How to make the Part Stack tabs movable by mouse?
Goto Forum:
  


Current Time: Sat Apr 19 16:10:30 EDT 2014

Powered by FUDForum. Page generated in 0.01727 seconds