So the main problem is that when you inject a blueprint proxy into a bean,
the bean does not know if the real service is available or not.
If the reference is mandatory, the service that depends on that reference
(the command in our case) won't be registered until the dependencies is
satisfied.  If the reference is optional, the service will be registered
anyway, but in both cases, the bean that is injected has no way to know if
the service is available or not and the calls will wait until the service
is available or throw an exception when the timeout is elapsed.
That means that either the commands won't be available, or the commands
will block.
If you look at the existing commands, for example the OBR commands, they
will throw an exception if the service is not available without waiting for
the timeout and the user will immediately know with a message printed in
the console.
I think that's a good behavior and I think we should keep it.  It also
seems that some commands don't behave that way (the admin commands for
example) and I think they should rather be refactored to be able to fail
fast the same way the OBR commands do.

One way would be to make sure the timeout on the reference has a timeout of
0 (need to check if that means infinite or really zero) and catch the
ServiceNotAvailable exception and rethrow a more meaningful exception to
display to the user.  Not sure if that will make things cleaner though.
Another way is to use blueprint listeners so that the beans can know when
the services come and go, but it complexity the code a bit too.

Now, if you find a better and cleaner way to do that, I don't have any
problems.

On Mon, May 14, 2012 at 2:36 PM, Guillaume Nodet <[email protected]> wrote:

> I'm don't think it's a good idea because of the way blueprint proxies
> work.  I'll  to provide mire information later but I'm at the airport.
>  Please hold on until we can discuss that further.
>
> On Friday, July 8, 2011, Christian Schneider (JIRA) wrote:
>
>> Refactor Actions to get services injected instead of fetching them
>> ------------------------------------------------------------------
>>
>>                 Key: KARAF-717
>>                 URL: https://issues.apache.org/jira/browse/KARAF-717
>>             Project: Karaf
>>          Issue Type: Improvement
>>            Reporter: Christian Schneider
>>            Assignee: Christian Schneider
>>            Priority: Minor
>>
>>
>> Currently we use abstract classes like ObrCommandSupport and
>> OsgiCommandSupport to handle the bundleContext and service references.
>> This makes the code harder to test and mixes technical and business code.
>> By business I mean the stuff the class is meant to do by technical I mean
>> other domains like osgi services.
>>
>> So I propose to inject the services we need using blueprint so in the
>> Action there is only the interface to the service and a setter.
>> Additionally I would even skip the AbstractAction as it is not good to
>> store the CommandSession in a class attribute as this makes the code non
>> reentrant.
>>
>> I have done a sample refactoring in
>> http://svn.apache.org/viewvc?view=revision&revision=1144288
>>
>> It shows how to change the ListCommand of the Obr to not need any
>> abstract support classes to handle the RepositoryAdmin service.
>>
>> This issue is a marker that we should do the refactoring and should be
>> split into smaller tasks when we start the refactoring.
>>
>>
>> --
>> This message is automatically generated by JIRA.
>> For more information on JIRA, see: http://www.atlassian.com/software/jira
>>
>>
>>
>
> --
> ------------------------
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
> ------------------------
> FuseSource, Integration everywhere
> http://fusesource.com
>



-- 
------------------------
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
FuseSource, Integration everywhere
http://fusesource.com

Reply via email to