Hi,
Sorry, missed that ...
Point is, that you are probably doing the wrong thing:
On 22.02.2010 12:07, Ulf Dittmer wrote:
> Hello everyone-
>
> I have a ServiceListener that stores a service reference to the ConfigAdmin
> service when that's started, something like this:
>
> public void serviceChanged (ServiceEvent event) {
>
> String[] objectClass = (String[])
> event.getServiceReference().getProperty(Constants.OBJECTCLASS);
>
> if (event.getType() == ServiceEvent.REGISTERED) {
> if (objectClass[0].equals(ConfigurationAdmin.class.getName())) {
The objectClass is an array possibly containing more than one entry. If
the ConfigurationAdmin class name is not the first entry it is missed.
> ServiceReference servRef =
> context.getServiceReference(objectClass[0]);
> ConfigurationAdmin configAdmin = (ConfigurationAdmin)
> context.getService(servRef);
>
> etc.
>
> That worked fine using ConfigAdmin 1.0.10, which causes the listener to be
> called twice, one each for org.apache.felix.cm.PersistenceManager and
> org.osgi.service.cm.ConfigurationAdmin.
Because you dependended on an implementation detail ;-)
>
> But ConfigAdmin 1.2.4 causes it to be called only once for
> org.apache.felix.cm.PersistenceManager, thus causing my app not to be aware
> of the newly installed ConfigAdmin. I'd like the code to be free of
> references to specific Felix classes, so my questions are: Is this a bug? Can
> the previous behavior be restored? Or should the code be doing something
> differently?
If you are interested in the ConfigurationAdmin service, you should
explicitly listen for that service and nothing else:
bundleContext.addServiceListener(listener,
"(objectClass=" + ConfigurationAdmin.class.getName() + ")");
Then the listener is only called for actual ConfigurationAdmin service
instances.
Better yet: use the ServiceTracker:
ServiceTracker st = new ServiceTracker(bundleContext,
ConfigurationAdmin.class.getName(), null);
st.open();
ConfigurationAdmin ca = (ConfigurationAdmin) st.getService();
Yet, you should not assign the ConfigurationAdmin service to an instance
field in this case and instead call the getService() when you need the
service.
Regards
Felix
>
> Thanks,
> Ulf
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]