Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OSGi ain't the only way to modularize your apps

 
Sai Hegde
security forum advocate
Ranch Hand
Posts: 212
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use IOC enforcement during your build process.
So, why OSGi then???
 
Richard S. Hall
author
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sai Hegde wrote:You could use IOC enforcement during your build process.
So, why OSGi then???


That is just a programming practice, you get no enforcement. But using IoC is definitely a good practice too.
 
Joachim Rohde
Ranch Hand
Posts: 433
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you've mentioned implicitly you need to rebuild your application. With OSGi you can change - in theory - dependencies during runtime. See also: http://www.osgi.org/About/WhyOSGi
 
Sai Hegde
security forum advocate
Ranch Hand
Posts: 212
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice.
 
Greg Funston
Ranch Hand
Posts: 81
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the link. OSGi looks like an excellent technology.

Cheers,
Greg Funston SCJP
 
Stuart McCulloch
author
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sai Hegde wrote:You could use IOC enforcement during your build process. So, why OSGi then???

Actually I personally believe the best way to use OSGi is with IoC, then you can get the advantages of OSGi but you're not tied to the framework
 
Augusto Sellhorn
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stuart McCulloch wrote:
Sai Hegde wrote:You could use IOC enforcement during your build process. So, why OSGi then???

Actually I personally believe the best way to use OSGi is with IoC, then you can get the advantages of OSGi but you're not tied to the framework


Yes. I use OSGi with Spring. My modules have most of the time, at the code level no dependencies to OSGi (via activators) or even Spring. So I like this approach as these are pretty framework independent POJOs.

I do my OSGi service registration at the Spring level, and bean creation in Spring too.

This also eliminates the needs for Activators in many cases, you can create a Spring bean and mark what method to call at startup.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. I use OSGi with Spring. My modules have most of the time, at the code level no dependencies to OSGi (via activators) or even Spring. So I like this approach as these are pretty framework independent POJOs.


ummh I thought ogsi was a runtime thing meaning no imports in my class.
 
Augusto Sellhorn
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pradeep bhatt wrote:
Yes. I use OSGi with Spring. My modules have most of the time, at the code level no dependencies to OSGi (via activators) or even Spring. So I like this approach as these are pretty framework independent POJOs.


ummh I thought ogsi was a runtime thing meaning no imports in my class.


Not sure what you mean.

But if you use an Activator, and also want to mess around with BundleContext to register a service, you need to import some OSGi specific classes.
 
Stuart McCulloch
author
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pradeep bhatt wrote:
Yes. I use OSGi with Spring. My modules have most of the time, at the code level no dependencies to OSGi (via activators) or even Spring. So I like this approach as these are pretty framework independent POJOs.

ummh I thought ogsi was a runtime thing meaning no imports in my class.

Depending on what parts of OSGi you want to use, and whether you use other abstractions on top of OSGi you may (or may not) need to import OSGi packages. You don't have to add any imports to take advantage of the modularity layer.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I was concerned whether osgi api import is required for modularity.
 
Mike Van
Ranch Hand
Posts: 83
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pradeep bhatt wrote:Thanks. I was concerned whether osgi api import is required for modularity.


Pradeep,

Most of the heavy lifting with OSGi is found in the META-INF/MANIFEST.MF file. Using Maven and the maven-bundle-plugin, this file will be largely created for you without a lot of extra work on your part. When we (OSGi folks) talk about "importing" a class or package inside of an OSGi bundle, what we're usually referring to is the Import-Package directive within the MANIFEST.MF file, not the actual import statements in your code. I can go in more detail about this (using Karaf and Felix) if you'd like.

Think of OSGi modularity like this. A bundle deployed inside of OSGi only knows about the class files, spring, aries, jaxb, etc files that it contains. If your bundle needs to use the functionality provide by another bundle, this needs to be identified in your MANIFEST.MF file. For example, if you have a service that makes JMS available to your OSGi container, and you have a bundle that needs to use JMS, you would grab a reference to that service via Aries or SpringDM, and use IOC to inject the service into your bundle. On a side note, I've found that using Camel along with OSGi is pure win, as it contains camel components for JMS and like services out-of-the-box. All you have to do is set it up in SpringDM or Aries, and BLAMMO, its available to all of your camel routes.

Hope that helps clear things up.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic