Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is GlassFish an OSGi container?

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!

like image 384
IAmYourFaja Avatar asked Nov 30 '25 10:11

IAmYourFaja


2 Answers

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.

like image 76
Peter Kriens Avatar answered Dec 02 '25 00:12

Peter Kriens


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

like image 24
Istvan Devai Avatar answered Dec 01 '25 23:12

Istvan Devai