users@glassfish.java.net

Injecting OSGi service using JCDI [WAS: Re: documentation for osgi extensions?]

From: Sahoo <sahoo_at_sun.com>
Date: Fri, 09 Apr 2010 12:19:51 +0530

Erik,

Very cool idea. Have you tried it yet?

Thanks,
Sahoo

Erik Brakkee wrote:
> I was thinking of integration OSGI in a different way using CDI.
>
> What this involves is creating a WAB with a bundle activator. In the
> start method of the BundleActivator, the BundleContext can be made
> available (static variable) so it can be accessed later. Then I can
> create a managed bean with a producer method
>
> class MyOsgiServiceFactory {
>
> @Produces @ApplicationScoped
> MyServiceFromOsgi createMyServiceFromOsgi() {
>
> BundleContext context = ... retrieve it...
> MyServiceFromOsgi service = .... get osgi service from
> context ....
> return service
> }
> }
>
> After that, I can use @Inject to inject the service.
>
> Also, I don't want to make EJBs available as OSGI services (yet) so
> that's not a problem for me.
>