On 3/9/11 11:49, Andrea Zoppello wrote:
Hi All,

Thx for the answers,... very interestin.
It's clear to me that the System.exit( ) is evil, is not a solution....

BTW i want to avoid, because i use equinox within servlet bridge and System.exit() will
cause problem in that situation..

The solution working on startup level seems to be the right way, to do.

Just for info:

1) My "startup bundle" has a start level set to 1
2) Other bundles has a start level set to default

I've just solved the problems that application bundles depends on startup bundle without
acting on startup levels using services.

In particular my startup-bundle if all is ok, publish in the last line of his start method a IStartupService as
follow:

context.registerService(IStartedUpService.class.getName(), new SpagicStartedUpService(), null);

Peter will love your use of a "ready" service...it'll probably bring a tear to his eye...

-> richard


so in other bundles where i'm using DS, i declare for my components ( DS powered ) a mandatory dependency on IStartedUpService. This solve in elegant way the problem of startup dependencies without acting on levels, but on the other side does not stop the framework for failure.

So a mixin of both... start level configuration, and publish of my service is needed.

Andrea

Il 09/03/2011 16:59, Neil Bartlett ha scritto:
Just to add one additional point: I believe that a bundle should never
call System.exit(). As a bundle you don't know whether you are in a
"pure" OSGi runtime, or whether OSGi is embedded inside a larger
application.

Use one of the techniques described by Thomas and Richard to shutdown
the framework, and then let the launcher decide whether to kill the
JVM or do something else.

Neil

On Wed, Mar 9, 2011 at 3:42 PM, Thomas Watson<[email protected]> wrote:
When the framework is launched it is working its way though the start-levels until the beginning start-level is reached. When you stop the system bundle you are basically setting the start-level to 0 which stops all bundles and
then shutsdown the framework.  The specification states the following:

<spec>
If the Framework is currently involved in changing the active start level,
it must first reach the previously requested start level before it is
allowed to continue with a newly requested start level. For example, assume the active start level is 5 and the Framework is requested to transition to start level 3. Before start level 3 is reached, another request is made to transition to start level 7. In this case, the OSGi Framework must first
complete the transition to start level 3 before it transitions to start
level 7.
</spec>

So in this case the framework is being launch and is changing the active start level to the beginning start-level. This beginning start-level must be reached before allowing the next active start-level change (in order to stop the framework). This is why you see all the other bundles attempting
to start.

What you need to do is lower the beginning start-level to be the same value as the start-level of this "start-up" bundle. Then this bundle should set the start-level to the final start-level if it is successful or stop the
system bundle on failure.

Tom

[email protected] wrote: -----

To: OSGi - Dev<[email protected]>
From: Andrea Zoppello<[email protected]>
Sent by: [email protected]
Date: 03/09/2011 09:21AM
Subject: [osgi-dev] Is it possible to stop the framework inside an Activator
start method?

Hi all,

Is it possible to stop the framework inside a bundle activator start method?

I'm asking this, because i need to have a bundle ( that i configure to
start ) with startup
level lower than other that need to do some configuration steps (
setting properties, prepare resources
and so on )

My need is to stop the framework and exit if something goes wrong in
this so called start-up bundle.

1) I've try to do get a reference to the system bundle and to stop by
doing this:

Bundle mainBundle = context.getBundleContext().getBundle(0);
mainBundle.stop();

but this seem don't work ( i seeequinox simple configurator continue to
process the bundle list ).

2) Another thing i try is to call the System.exit(0), it works but i
don't know if it's correct...

Which is the cleanest and right way to proceed in that case??

Andrea

_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev


_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev


_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to