[ignore previous mail, sent before complete]

BJ Hargrave wrote:
> I think this is just a bad example. The async task even if 
> wrapped can't mutate the thread locals of the original thread 
> which seems to be the point of your ContextualService. So even 
> attempting to push some of  that work off to an async task 
> seems wrong. 

What I have in mind for this particular example is actually 
scenarios where the context is permanently migrated, not 
shared, to the async thread. So there is no need for writing
the contextual info back to the original thread. Examples could
include handing over a transaction to be completed in the async
thread.

For cases where it is desired to share writable contextual data 
between the two threads, the very same solution may be used but
with a level of indirection so the ThreadLocal object points to
a shared mutable object.

> > In a startup scenario where all 
> > three bundles have just started, and MyBundle.myMethod() executes, I
> > can't be sure that AsyncTaskService has registered my Hook and thus 
> > started considering the contextual workaround? 
> 
> Well your mymethod bundles cannot even know about the hook since 
> it came from some other bundle. As the hook also is a service from 
> a bundle, that bundle can be stopped at any time (for updating as 
> an example). 

Indeed, my desire is not that MyBundle knows about whether the Hook
has been registered. But my desire is that ContextualService will
not service any bundle that also uses AsyncTaskService until
AsyncTaskService has discovered the Hook.

Thus, I'd like to be able to catch the case where a bundle calling 
into "me" (ContextualService) is also using AsyncTaskService and
AsyncTaskService has not yet taken notice of my Hook service. 
In this case I'd like to wait until AsyncTaskService discovers my 
Hook, or throw an error, or maybe something else.

> > If I want to be sure about this, I guess I need to switch to 
> > explicit registration with AsyncTaskService (not whiteboard), and 
> > delay publishing my ContextualService until I know my Hook has been 
> > registered. Or are there ways to make this work with a whiteboard
design? 
> 
> Well if the ContextualService requires the hook, how is the hook 
> an optional thing (the subject line of this thread)? 

ContextualService may be on a system without the AsyncTaskService
and then ContextualService will not need to register its Hook to
extend AsyncTaskService's behaviour.

When ContextualService is on a system with the AsyncTaskService 
then it does not want to service any other bundles until it knows
AsyncTaskService has discovered its Hook implementation.

So both ContextualService and AsyncTaskService are optional on the
system, but when both are present I want ContextualService to wait
for their hooking before serving other bundles.
And I guess this needs a more explicit registration procedure than
the whiteboard style.

Best regards
Mike

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

Reply via email to