Reputation: 23
I have a problem with splitting application into modules. I found out about OSGi but I'm not sure if it will solve my problem.
Lets say that I have core web application. This application displays list of Dashboards in table (with columns "Owner name", "description", "date created"). When I click on dashboard on list I'm redirected to Dashboard screen.
Now things get complicated. Those dashboards can be of different types (CompanyDashboards, PersonalDashboards etc.). Those types should be optional modules (depending on instance there could be only one type or both or more when they get implemented).
And now: I have core of my application where I want to create list of dashboards without knowing it's types. Do let's say I have some Dashboard interface. I use Dashboard.getName, Dashboard.getDescription, Dashboard.onClick etc. I don't want core to be aware of connected bundles. Now when dashboard is clicked it should load and display dashboard of correct type (CompanyDashboard or PersonalDashboard).
How can I load correct one without core knowing available types. Is OSGi right tool to use?
Upvotes: 1
Views: 55
Reputation: 19626
You can use OSGi service for this. You create a common DashBoard interface in its own bundle. Then you can have several bundles each providing one DashBoard. In each of these bundles you create the DashBoard instance and publish it with the common interface. Then you have one bundle implementing the central view with the list of DashBoard. In this bundle you listen for all services of type DashBoard and list them.
So the trick is to not instantiate the individual instances in the central bundle.
Upvotes: 1