tags:

views:

91

answers:

2

The eclipse OSGi Service Activator Toolkit provides a framework that simplifies handling the dependencies between budles.

One can derive from org.eclipse.soda.sat.core.framework.BaseBundleActivator and over-ride (for example) the activate() method to do some spefic initialisation work.

The signature is protected void activate(){}

Which leads to the question: "what are we spposed to do if activate() fails?", suppose for some reason we cannot initialise correctly. I can't throw an exception, the method signatiure won't allow that.

A: 

It's still possible to throw RuntimeException and Error (And Exceptions that inherit these). (Remember that Error indicates serious problems that a reasonable application should not try to catch.)

It would also seems like a good idea to output something to your logging facility.

The alternative you choose is dependent on the situation; what the root cause of the failed activation is. If the cause is something abnormal, that should not happen during normal circumstances, an Error or RuntimeException (and ofcourse loggin) feels right.

Schildmeijer
I agree that emiting some diagnostics is a good idea. I'm not sure about the unchecked exceptions.In general, yes I could throw an unchecked exception. However is this valid in the context of this framework? I would expect the framwork to define the error handling "protocol" by specifying an exception to throw.
djna
+1  A: 

Throwing an RuntimeException or an Error in the activate() method does not help you if you are using Equinox (tested with org.eclipse.osgi_3.5.1.R35x_v20090827). Independent of what you are throwing the bundle will finally end up in state ACTIVE.

I assume that this behavior is specific to Equinox (bug?) because from my understanding this violates the OSGi specs.

Robert
It does seem to be difficult to know exactly what to do in these cases. I believe that the SAT authors should explcitly define what we should do.
djna