anathema
anathema

Reputation: 977

OSGI Bundle Structure and communication to other bundles in CQ5

As per my understanding when developing with CQ5, service layer will be located on the OSGI bundle. Does that mean for every service classes that I will create it will be equivalent to one OSGI Bundle? For example if I have 3 services for my CQ5 application namely: Login Service, UserManagement Service, Registration Service does it mean that there will be also 3 OSGI bundles to be deployed? and how does this bundles will communicate with each other?

Upvotes: 1

Views: 631

Answers (2)

Bertrand Delacretaz
Bertrand Delacretaz

Reputation: 6100

Having small, focused bundles is good in my opinion, but it doesn't necessarily mean one bundle per service. In your case, login, user management and registration look sufficiently different to warrant their own bundles. But user management for example might be implemented by several services, all provided by the same bundle.

A good rule of thumb is to design your bundles so that removing one of them disables a consistent unit of functionality. Removing your "user management" bundle for example would disable all user management features, ideally without affecting login or registration.

As for communication, think in services. Using Declarative Services, OSGi components simply declare which services they require (usually using @Reference annotations) and the framework takes care of only starting a component once all the services that it requires are available.

Upvotes: 0

Oleksandr Tarasenko
Oleksandr Tarasenko

Reputation: 1454

Not really. Bundles are more like modules. So you can split your services into bundles basing on their functionality or if you would like to reuse them in other projects. For example you can have next structure:

  • projectname-core: there you can have services, which can be used by other project as well. Like some content feed generators for external services, Log-in service (if it will be useful in other project as well:
  • projectname-ui-beans: there you can have beans, which you will be injecting on your jsp pages;
  • projectname-services: general services, which are specific for this project, like search or registration;
  • projectname-taglib: there you have your own jsp tags implementation;
  • projectname-it-test: bundle with integration tests;
  • projectname-some-specific-stuff: there can be some services which are not dependent on any other bundle, like one-time content manipulation;

Refer this topic for basic structure and Maven archetype for creating it.

Upd1: Communication between bundles can be done in two ways:

  • you can have one of your bundles as a dependency for another bundle. Then, you could just use @Reference to get services from other bundle
  • also you can use events to do communication, see this for details.

Upvotes: 1

Related Questions