[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] Possible bug in ServiceTracker

I am not sure what is happening for you.

I wrote the following code:

package sttest;

import org.osgi.framework.*;
import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;

public class Activator implements BundleActivator {
 
        ServiceTracker classTracker;
        ServiceTracker filterTracker;
        BundleContext context;

        public void start(BundleContext context) throws Exception {
                this.context = context;
                classTracker = new ServiceTracker(context, LogService.
class.getName(), new STC("classTracker"));
                Filter filter = context.createFilter("("+Constants.
OBJECTCLASS+"="+LogService.class.getName()+")");
                filterTracker = new ServiceTracker(context, filter, new 
STC("filterTracker"));
                classTracker.open();
                filterTracker.open();
        }

        public void stop(BundleContext context) throws Exception {
                classTracker.close();
                filterTracker.close();
        }

        class STC implements ServiceTrackerCustomizer {
                String name;
 
                STC(String name) {
                        this.name = name;
                }

                public Object addingService(ServiceReference reference) {
                        System.out.println(name+": adding "+reference);
                        return context.getService(reference);
                }

                public void modifiedService(ServiceReference reference, 
Object service) {
                        System.out.println(name+": modified "+reference);
                }

                public void removedService(ServiceReference reference, 
Object service) {
                        System.out.println(name+": removed "+reference);
                        context.ungetService(reference);
                }
        }
}

which worked fine for me:


osgi> ss

Framework is launched.

id      State       Bundle
0       ACTIVE      system.bundle_3.2.0.qualifier
7       ACTIVE      org.eclipse.equinox.common_3.2.0.qualifier
12      ACTIVE      org.eclipse.equinox.log_1.0.0.qualifier
20      ACTIVE      org.eclipse.osgi.services_3.1.100.qualifier
21      ACTIVE      org.eclipse.osgi.util_3.1.100.qualifier
23      ACTIVE      org.eclipse.equinox.supplement_1.0.0.qualifier
24      ACTIVE      org.apache.xerces_2.8.0.v200604170430
25      ACTIVE      org.eclipse.core.contenttype_3.2.0.qualifier
26      ACTIVE      org.eclipse.core.jobs_3.2.0.qualifier
27      ACTIVE      org.eclipse.core.runtime_3.2.0.qualifier
28      ACTIVE      org.eclipse.equinox.preferences_3.2.0.qualifier
29      ACTIVE      org.eclipse.equinox.registry_3.2.0.qualifier
30      RESOLVED    STTest_1.0.0

osgi> start 30
classTracker: adding 
{org.osgi.service.log.LogService}={service.description=OSGi Log Service - 
IBM Implementation, service.pid=org.eclipse.equinox.log.LogServiceImpl, 
service.vendor=IBM, service.id=22}
filterTracker: adding 
{org.osgi.service.log.LogService}={service.description=OSGi Log Service - 
IBM Implementation, service.pid=org.eclipse.equinox.log.LogServiceImpl, 
service.vendor=IBM, service.id=22}

osgi> stop 12
classTracker: removed 
{org.osgi.service.log.LogService}={service.description=OSGi Log Service - 
IBM Implementation, service.pid=org.eclipse.equinox.log.LogServiceImpl, 
service.vendor=IBM, service.id=22}
filterTracker: removed 
{org.osgi.service.log.LogService}={service.description=OSGi Log Service - 
IBM Implementation, service.pid=org.eclipse.equinox.log.LogServiceImpl, 
service.vendor=IBM, service.id=22}

osgi> start 12
classTracker: adding 
{org.osgi.service.log.LogService}={service.description=OSGi Log Service - 
IBM Implementation, service.pid=org.eclipse.equinox.log.LogServiceImpl, 
service.vendor=IBM, service.id=32}
filterTracker: adding 
{org.osgi.service.log.LogService}={service.description=OSGi Log Service - 
IBM Implementation, service.pid=org.eclipse.equinox.log.LogServiceImpl, 
service.vendor=IBM, service.id=32}

osgi> stop 30
classTracker: removed 
{org.osgi.service.log.LogService}={service.description=OSGi Log Service - 
IBM Implementation, service.pid=org.eclipse.equinox.log.LogServiceImpl, 
service.vendor=IBM, service.id=32}
filterTracker: removed 
{org.osgi.service.log.LogService}={service.description=OSGi Log Service - 
IBM Implementation, service.pid=org.eclipse.equinox.log.LogServiceImpl, 
service.vendor=IBM, service.id=32}

osgi> 
BJ Hargrave
Senior Technical Staff Member, IBM
OSGi Fellow and CTO of the OSGi Alliance
hargrave@xxxxxxxxxx
Office: +1 407 849 9117 Mobile: +1 386 848 3788



Niclas Hedhman <niclas@xxxxxxxxxxx> 
Sent by: equinox-dev-bounces@xxxxxxxxxxx
2006-05-22 04:04 AM
Please respond to
Equinox development mailing list <equinox-dev@xxxxxxxxxxx>


To
"Equinox development mailing list" <equinox-dev@xxxxxxxxxxx>
cc

Subject
[equinox-dev] Possible bug in ServiceTracker







Hi,

We are struggling with a ServiceTracker filter problem.

If we do;

String classname = Content.class.getName()
m_serviceTracker = 
    new ServiceTracker( m_bundleContext, classname, m_contentTracking );

tracking work as expected. However, if we change it to

String filterString = 
    "(" + Constants.OBJECTCLASS + "=" +Content.class.getName() + " )";
Filter filter = bundleContext.createFilter( filterString);

m_serviceTracker = 
    new ServiceTracker( m_bundleContext, filter, m_contentTracking );


We don't get any service tracking. We have tried to follow the code in the 

tracker and the associated Event management in framework, and we are not 
capable of following the logic behind the, hrmmm, overly complex code. ;o)
The only thing I think I concluded was that the tracker's EventListener is 
not 
called from the framework at all.


Any idea why this behaviour is observed???



Cheers
Niclas
_______________________________________________
equinox-dev mailing list
equinox-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/equinox-dev