Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Gemini » Programmly register Bean and expose as service
Programmly register Bean and expose as service [message #693583] Wed, 06 July 2011 19:44 Go to next message
Norman Maurer is currently offline Norman MaurerFriend
Messages: 8
Registered: June 2011
Junior Member
Hi there,

I need to build up some "BundleTracker" which scan started bundles for a given class. If its found it need to register it in the BeanDefinitionRegistry and also expose it as osgi service. What would be my best bet ?

Using the OsgiServiceFactoryBean ?
Re: Programmly register Bean and expose as service [message #694100 is a reply to message #693583] Thu, 07 July 2011 19:39 Go to previous messageGo to next message
Norman Maurer is currently offline Norman MaurerFriend
Messages: 8
Registered: June 2011
Junior Member
And again to close the loop Wink

I managed todo it with the OsgiServicefactoryBean and the BeanDefinitionRegistry. I registered a BundleListener which will look for a specific implemented interface. If its found in the bundle it tires do lookop the ApplicationContext ofits comtext via the OSGI registry. if noneis foundI just create one for it.

Then I use the BeanFactory of the bundles ApplicationContext to register the BeanDefinition in it. Last I use the OsgiServiceFactory bean to register it as OSGI Service..

Not sure if there is a better solution, but at least it works...

I can link the code here if someone need some more infos...

bye
norman
Re: Programmly register Bean and expose as service [message #694288 is a reply to message #694100] Fri, 08 July 2011 09:22 Go to previous message
Costin Leau is currently offline Costin LeauFriend
Messages: 45
Registered: February 2010
Member
You're basically talking about the extender pattern. Gemini Blueprint doesn't export any dedicated functionality for this since it's highly dependent on what you want to achieve. You can use as inspiration the extender bundle in particular the ContextLoaderListener.
Typically one listens for bundle events (when new bundles are started), performs the scanning (GB helps with that through its IO package) and then performs the export.

However this is the low level approach without blueprint - you can simplify greatly by adding a simple configuration for the bundles you want to scan. This way when the bundles get deployed, automatically Blueprint will intercept them and trigger the context creation.
Inside of it you can use a BeanFactoryPostProcess (Spring class) that performs the scanning - if you have a custom setup. For 80% of the cases however the component-scan gets you there without having to write any code.
Basically it registers automatically the annotated classes as beans.
So the only thing you have to do is create a factory that automatically exports all these as services - with the BeanFactoryPostProcessor approach you can simply create the osgi:service definitions for them.

That is, all you need to do is fill in the last gap of the classes discovered to be automatically exported as services.
Previous Topic:CommonAnnotationBeanPostProcessor not work
Next Topic:[PATCH] @Resource annotation via OSGI lookup
Goto Forum:
  


Current Time: Tue Mar 19 04:58:10 GMT 2024

Powered by FUDForum. Page generated in 0.02359 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top