Search code examples
javaosgimodular

OSGi structure for a project


I want to develop a system in order to manage readings from a text file. The main structure is based on 4 bundles:

  • one to provide a timestamp for the log
  • one to generate/provide the data
  • one to keep a log (add the timestampand the values to a file)
  • one to visualize the generated file with the timestampand the readings

My question is: How should each bundle be organized? I'm not 100% familiar with the OSGiway of work, it's something I'm working on. My current structure is as follows:

enter image description here

  • the *Interface files are where I have the services to be provided
  • the *Activator files are the bundle activators, where I register the services
  • the *Impl files are used to implement the interfaces, although I'm not sure I'm supposed to implement there within the same package

Is it correct? Thanks in advance.


Solution

  • You're right to separate the interfaces into different packages to the implementations. Generally you'll want each bundle to export the packages containing the interfaces, but not the implementation packages. This will help to minimise the coupling between the bundles.

    It looks like you have all your services in one project which would result in them all being in the same OSGi bundle. You should probably separate each one out into its own project with its own manifest file. That way the services can be developed and deployed independently and communicate through the service interfaces.