3

In researching OSGi and OSGi containers, I stumbled across this SO question mentioning GlassFish as an OSGi container, and I have to say I'm quite baffled.

How is this possible?!?!

My understanding was that OGS - a Java-compliant app server - has 2 containers:

  • Web Container: where you deploy WAR files for web apps and services
  • App Container: where you deploy EJBs for business logic

Where do OSGi bundles fit into this paradigm?!? Does OGS allow you to deploy an OSGi bundle to the app container and treat it like an EJB or something? And if I'm mistaken about how OGS works please correct me! Thanks in advance!

Community
  • 1
  • 1
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
  • The basic questions would be -- 1) Is OSGi the runtime for the various OGS stuff? and 2) Is an OSGi container also exposed for user/developers to add bundle modules that can be reached by their other J2EE components? – chad Jul 18 '12 at 16:31
  • @chad - I appreciate your input but unfortauntely your comment has confused me more than I was originally; can you please elaborate or post a more verbose answer? – IAmYourFaja Jul 18 '12 at 16:44
  • It looks like the other folks have provided more thorough answers. I would suggest that OSGi is the kind of thing that can appear simple enough, if you just read the literature and buzz, but it's use case is actually quite challenging. A powertool for the very experienced architect, myself excluded. – chad Jul 19 '12 at 19:07
  • http://www.youtube.com/playlist?list=PL82463F107D47B8B6 – Douglas G. Allen Jun 06 '13 at 15:21
  • http://www.youtube.com/watch?v=FwOycoTgTvY – Douglas G. Allen Jun 06 '13 at 17:23
  • Your question shows up with this as a criteria for a search. osgi bundles glassfish You'll find lots of information there too. – Douglas G. Allen Nov 02 '13 at 04:25

3 Answers3

5

OSGi is a module system that allows to add/remove/upgrade different bundles, handles dependencies, provides runtime information on the status, etc.

When it comes to GlassFish (which has an Apache Felix OSGi container in it), the different features of the application server (eg HTTP server, JMS server, etc.) are implemented as bundles. There is console and web based interface for the OSGi container where you can start, install, remove services (see the PDF below)

As far as Java EE applications go, they can interact with the OSGI container too. For example, an EJB can be exported as an OSGi service and also the EJB can consume an OSGi service itself.

For more info, see http://glassfish.java.net/public/GF-OSGi-Features.pdf

Istvan Devai
  • 3,962
  • 23
  • 21
  • Thanks @Istvan (+1) - is there a way to make an OOSGi bundle and deploy it on GlassFish? If so, how? – IAmYourFaja Jul 18 '12 at 22:01
  • First, learn to create a bundle for Apache Felix http://felix.apache.org/site/apache-felix-osgi-tutorial.html and then try to create a specific one for Glassfish, see here http://java.dzone.com/news/from-osgi-glassfish-5-steps – Istvan Devai Jul 19 '12 at 05:54
  • pnongrata: You didn't read the pdf file referenced by Istvan. Go check that out first. – sahoo Jul 26 '12 at 00:39
  • https://glassfish.java.net/public/GF-OSGi-Features.pdf https://wikis.oracle.com/display/GlassFish/OSGi https://blogs.oracle.com/theaquarium/entry/osgi_glassfish_the_definitive_guide https://blogs.oracle.com/arungupta/entry/osgi_application_development_using_glassfish https://blogs.oracle.com/arungupta/resource/osgi-gf-econ-2011-docs.pdf – Douglas G. Allen Jun 06 '13 at 14:34
5

Hmm, a rather total misunderstanding of what OSGi is ...

OSGi is a framework that allows you to organize your code so that you can built it from reusable components that can then collaborate through the service layer (no more Class.forName or XML!).

OSGi frameworks can run standalone, they run inside an application, the can run in a WAR file, and they can run inside an application server. And you can even run OSGi inside OSGi inside OSGi since it does not rely on statics anywhere.

The OSGi Alliance specifies a format for the modules (bundles) so that modules can specify their dependencies. The Alliance also specifies an API to install and manage modules. And last, it specifies a large number of interfaces that are useful when you develop applications.

Websphere, Glassfish, JBoss, Jonas, all support deploying OSGi bundles.

Peter Kriens
  • 15,196
  • 1
  • 37
  • 55
  • Thanks @Peter Kriens (+1) - but if I'm not mistaken, a bundle is just a JAR with a different internal structure and some metadata, yes? If so, and if it can be deployed to OGS, then some kind of container inside OGS *must* be serving the deployed bundle, yes? This is the root of my question: **does OGS have a 3rd container, an "OSGi container", for serving OSGi bundles, or does it serve OSGi through WARs/EJBs somehow?** – IAmYourFaja Jul 19 '12 at 15:04
  • OSGi is not an all encompassing container ... OSGi runs inside WARs, it can even run inside another OSGi fw, many App servers are based on OSGi. Since OSGi does not use statics (as everybody else seems to do in Java, even though they were told in kindergarten not to use global variables). If you do not use statics, you get flexibility. So OSGi can run side by side with an App server or the app server is built upon OSGi. So GF has a way to get your bundles installed, then playing side by side with WARs: http://www.slideshare.net/wwwsahoo/osgi-java-ee-in-glassfish-3553192 – Peter Kriens Jul 18 '13 at 08:27
  • Inside the glassfish docs you might find the link for the base architecture of glassfish. http://felix.apache.org/ – Douglas G. Allen Nov 02 '13 at 04:29
  • JBoss EAP 7.x does not support OSGi – Francisco Melo junior Apr 09 '20 at 22:51
0

Glassfish internally uses OSGi to provide the features you mentioned. Besides that you can deploy your own OSGi bundles on it. See https://wikis.oracle.com/display/GlassFish/OSGi There is no real connection between OSGi and Java EE though. You can not yet use JavaEE in OSGi bundles on Glassfish. For this case there are first initiatives like Weld on OSGi: http://www.slideshare.net/TrevorReznik/weldosgi-injecting-easiness-in-osgi They are not really production ready though.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
  • 2
    That's not true. One can use Java EE and OSGi together. GlassFish supports it and so does WebSphere. Read http://glassfish.java.net/public/GF-OSGi-Features.pdf. -- Sahoo – sahoo Jul 26 '12 at 00:38
  • Sounds good. I did not see this before. Will have to test it soon :-) – Christian Schneider Jul 26 '12 at 19:20