[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ecf-dev] IContainerManager or OSGi service tracker?

Hi Remy,

Remy Chi Jian Suen wrote:
Are we supposed to be using IContainerManager to keep track of
created/connected IContainers or are we supposed to use

I'm a little confused by your question. IContainerManager is published as an OSGi service, so you can get at it/use it via calls like:

ServiceReference ref = bundleContext.getServiceReference(IContainerManager.class.getName());
IContainerManager containerManager = (IContainerManager) bundleContext.getService(ref);

or you can use a ServiceTracker to get the IContainerManager service as well:

ServiceTracker serviceTracker = new ServiceTracker(bundleContext,IContainerManager.class.getName(),null);
IContainerManager containerManager = (IContainerManager) serviceTracker.getService();

I prefer and have been using ServiceTrackers for accessing the IContainerManager services and others, as they are much more helpful in doing appropriate cleanup, etc for the use of a service. I think ServiceTrackers are also considered cooler these days for OSGi service access as well :).

In general, though, 'yes' we should be using the IContainerManager service to keep track of IContainer instances (connected or not).

The current UI of having to manually attach listeners
for xmpp collaboration is rather crude. It'd be better if they were
just attached when an IContainer is created/connected.

Yes...it would probably be better to use the IContainerManager service to get the associated container and add listeners (either to the IContainerManager for synchronous notification upon container creation or to the relevant IContainer for synchronous notification upon container connect/disconnect). Then other listeners can be added/removed upon notification of the relevant events (IContainer creation or IContainer connection).