HowTo Build an OSGI Enterprise Server: EJB3 Container

This entry of my blog series „HowTo build an OSGI Enterprise Server“ will talk about the „EJB3 Container“ managed by EasyBeans. EasyBeans uses by default Felix as OSGI Framework – this blog series describes how to use it all under Eclipse Equinox together with Eclipse Riena.

You have to follow some rules how to start the OSGI application: start – levels, start – order, automatic-start … Please read important instructions in chapter „Server starten“. A short overview:

Our OSGI Enterprise application automatically starts a „Server Agent – Bundle“ – this agent contains an OSGI Service Tracker watching if EasyBeans initializes all EJB3 Container to see when all is ready.

We also start our domain-specific „Server Bundles“ which are tracking to see if our ServerService is registered from „Server Agent“ Bundle.

Server – Agent – Bundle and Server – Bundles

Our (domain-specific) „Server – Bundles“ and the „Server – Agent – Bundle“ are started automatically using Default – Start – Level (in our example Level 3).

The „Server – Bundles“ are waiting until a RienaEasyBeansServerService signals, that our Server with Riena- and EasyBeans – Functionality is available.

The most important dependencies of our „Server – Agent“ – Bundle:

The „Server – Agent

  • tracks Services from EasyBeans using an EasybeansServiceTracker
  • registers Remote – „Business – Interfaces“ for Riena – Remoting
  • registers RienaEasyBeansServerService when or server is available

EasybeansServiceTracker – Filter

An OSGI ServiceTracker should only track needed Services – so we have to define a Filter used as Parameter creating a new ServiceTracker. The Filter:

(|(objectClass=org.osgi.service.cm.ManagedServiceFactory)(objectClass=org.ow2.easybeans.api.EZBContainer)(objectClass=org.ow2.easybeans.component.jdbcpool.JDBCPoolComponent)(service.pid=*RemoteManagerI*Bean))

What kind of OSGI Services we’ll get using this Filter ?

ManagedServiceFactory:

EasyBeans registers for each EasyBeans Component a Service of Type ManagedServiceFactory:

{org.osgi.service.cm.ManagedServiceFactory}=
{service.pid=org.ow2.easybeans.component.carol.carolcomponent,..
Registered by bundle:
…easyBeans/bundles/easybeans-component-carol_1.1.0-…jar
Bundles using service:
…/org.eclipse.equinox.cm_1.0.0.v20080509-1800.jar
…/org.ekkehard.server.agent_1.0.0.jar

Tracking these Services we can test if all EasyBeans Components are correct initialized.

EZBContainer:

After successfully processing our „EJB – Bundles“ and „PersistenceContext – Bundles“ from EasyBeans a Service of Type EZBContainer is registered:

{org.ow2.easybeans.api.EZBContainer}={service.id=103}
Registered by bundle: …/org.ekkehard.foo.datamanager.bean_1.0.0.jar
Bundles using service:
…/easybeans-core_1.1.0-M3-SNAPSHOT.jar
…/org.ekkehard.server.agent_1.0.0.jar

Tracking these Services we know, that EasyBeans has created an EJB3Container for our Bundle – and if its a „PersistenceContext – Bundle“ then we also know, that Hibernate has done all the Mapping and Binding.

JDBCPoolComponent:

EasyBeans JDBCPoolComponent registers always after initializing a DataSource an OSGI Service of Type JDBCPoolComponent:

{org.ow2.easybeans.component.api.EZBComponent,
org.ow2.easybeans.component.jdbcpool.JDBCPoolComponent}=
{… jndiName=”foo_data_source_hsql”….

Using the Property jndiName we can test if our DataSource is available.

service.pid:

We also filter Services containing a service.pid of our pattern for Remote – Business – Interfaces: „*RemoteManagerI*Bean“. The pattern depends from your naming schema.

Tracking those Services will give us OSGI Services of Type ManagedService. The we do some additional testing to see if some Properties are set from EasyBeans. If true, we know that its a ManagedService created by EasyBeans for one of our @Remote – „Business – Interfaces“.

Now we can register this @Remote – „Business – Interface“ for Riena Remoting, to provide a Riena Published Endpoint for our Rich Clients.

This is also the reason why the „Server – Agent – Bundle“ needs Package-Import-Dependencies to our „Business – Interface – Bundles“ – if you dont use Riena, then you dont need these dependencies.

RienaEasyBeansServerService

If all tracking was successfully, then our „Server – Agent – Bundle“ registers an RienaEasyBeansServerService as OSGI Service. Because this Service will also be registered as Riena Remote Endpoint, our „Server – Bundles“ and also our „Rich Client – Bundles“ can track if the Server of a specific domain is live and ready-to-go.

When knows the „Server – Agent“ that all was successfully processed ?

  • All EasyBeans Components are initialized
  • All DataSources are avilable
  • All EJB Container are available

There are some special tricks how to track and test and start bundles – but this will be part of the next blog.

There’s an this index of this blog series in the column right beside the blog entries.

blog in german

3 responses

  1. Hi Ekke

    I am having some serious difficulty getting the latest Easybeans release to work (1.1.0-M1). It seems the org.ow2.easybeans.core bundle won’t resolve, though from looking at the manifest it seems to be exporting most of the things that it can’t find.

    Please could you point me in the right direction to get it working. Thanks much!

  2. Ha, how about that, I just got it working. Seems I was missing the org.apache.felix.dependencymanager bundle (even though I’m using Equinox).

  3. just wanted to answer😉
    yes – the felix.dependencymanager is needed

    I’ll provide installation-instructions using EZB 1.1.0M3 and RienaM5 next week – just working to make my 2 eclipse instances (one for modeling, one for osgi-rcp-ezb-riena) running with 3.5M3, because of PDE-support for cyclic dependencies

    I hope that one day EZB will have finished work to unbundle the ezb-core-bundle, which is a monster today😉

    ekke

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: