You may also ask what happens to my long running service call when:

1) Someone calls System.exit
2) Someone unplugs the computer

:-)

In all these cases someone is withdrawing a resource possibly used by the 
long running service call. If someone uninstalls and refreshes the bundle 
while there is a thread running around in its code, you may well get class 
load errors since the backing store for the old class loader can be 
removed. 

In general these are challenging problems for which fault tolerance is 
important.

In a more controlled environment, like an http server, the http service 
can know how many servlet requests are in flight and the server can (1) 
not processes any future requests and (2) wait until all current requests 
have returned before updating the app. However, any other threads doing 
things are outside the knowledge of the http server.
-- 

BJ Hargrave
Senior Technical Staff Member, IBM
OSGi Fellow and CTO of the OSGi Alliance
[email protected]

office: +1 386 848 1781
mobile: +1 386 848 3788




From:   Raymond Auge <[email protected]>
To:     OSGi Developer Mail List <[email protected]>
Date:   2015/02/13 11:55
Subject:        Re: [osgi-dev] How to cleanly update/uninstall bundles
Sent by:        [email protected]



To my knowledge what you are speaking of is not intentionally supported by 
the dynamics of osgi. This topic comes up all the time, it's funny.

If you must support "in flight" changes, then you have to implement this 
support in your code using concurrency constructs.

Note that unregistering a service is a synchronous operation during 
"shutdown" of a bundle, and so with proper concurrency measures in place, 
a bundle could both be shutting down (meaning it's not reachable by other 
bundles) and also finishing any ongoing work.

Anyone feel free to correct me but this is what I've learned in my short 
experience.

- Ray

On Fri, Feb 13, 2015 at 11:37 AM, Christian Schneider <
[email protected]> wrote:
I had a longer discussion with Guillaume Nodet about how to shut down 
bundles cleanly. The main question was if you can cleanly shut down 
bundles with just the OSGi APIs or if we are missing something.

So the thing to define is: what does clean shutdown mean? Clean would 
refer to the fact that none of the inflight calls the bundle processes are 
disturbed.

Case A
So what could happen. In the simplest case a bundle might simply process a 
long running service call.

1. The call started before the bundle was stopped
2. Then the bundle is stopped
3. The bundle is refreshed or uninstalled
4. At some later point the call finishes

So what happens with the inflight call after 3?
Can the running thread still work normally?

One issue that might arise is that during stop the bundle might have shut 
down some needed resources. This is in control of the developer, so I 
think it should be no big issue.
The question though is what happens to the Classloader of the bundle?
The stop operation should be no problem here but what about refresh, 
update or uninstall? Does this old classloader still work then?
If the classloader does not work anymore how should this case be handled?
Does the bundle have to make sure all inflight processing is done before 
stop is finished?


Case B
This could be even more complex when you have chained service calls.
Service A1 in bundle A calls service B1 in bundle B

1. Service call in A1 starts processing
2 Bundle B is stopped
3. bundle B is uninstalled
3. Service A1 tries to call service B

For blueprint I know that the call to service B will block because of the 
service damping.
What happens in DS here? Normally DS would stop Service A1 when the 
Service B1 disappears but the call to service A1 already started.
I think that in this case Service A1 will still have an instance of B1 
injected. So the call to B1 will probably happen, even if B1 was 
uninstalled in the mean time.
So I think we might have the same classloader issue as in the first case. 
The problem is though that bundle B cannot defer stopping because it does 
not see an inflight call at the point where it stops.

I think one solution to avoid Case B could be to stop bundles according to 
their service dependencies. So you would first stop bundle B then bundle 
A. Is this the recommended solution? Is this already automated in OSGi in 
some way?


Case C
An even more complicated case is when one or more extenders are involved 
that create services on behalf of the bundles. Are there any best 
practices around this?

I have seen that there is the Quiesce API in aries that seems to cover 
shutting down bundles when extenders are involved.
See 
https://github.com/apache/aries/blob/trunk/quiesce/quiesce-api/src/main/java/org/apache/aries/quiesce/participant/QuiesceParticipant.java


The API seems to be aries specific though. Is something like that 
necessary or should plain OSGi APIs offer enough flexibility for this case 
too?

Christian

-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com

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



-- 
Raymond Augé (@rotty3000)
Senior Software Architect Liferay, Inc. (@Liferay)
Board Member & EEG Co-Chair, OSGi Alliance (@OSGiAlliance)
_______________________________________________
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