registering bundles and listening to new services

So, some very basic stuff.. What is a bundle in OSGI? I was thinking about it as the service that is provided. But having now implemented one and tried to access it through the container it seems that this is another component vs service issue. So I think the bundle is a “component” in that it is a package (i.e. a “bundle”) of classes, code, etc. And it can provide 0-N services (zero or more). So is there some meaning to just providing a bundle without any content? I wouldn’t know so far.. But each bundle must then provide services for others explicitly, this is not done just by installing the bundle, unless the bundle code for activation does the service registration. This happens with BundleContext.registerService() method.

After this it is possible to listen to and react to service events by registering a service listener with BundleContext.addServiceListener(). This is where the initial failure was as I thought this would now give the bundles loaded but oh noes not so.. Also explains why Felix seems to load 3 bundles of its own (at least thats the default at this time, could change later ofc) but a listener reports 10+ services.

And for more spam in one post, when listening to the services with a ServiceListener, the event types are from ServiceEvent.REGISTER_EVENT etc. And to identify which service object it is that was registered the ServiceEvent.getServiceReference() object needs to be queried for a property called Constants.OBJECTCLASS to get the type. I guess this is documented in the spec so maybe I should read that.. lol

Advertisement

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 )

Facebook photo

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

Connecting to %s