Looking at your picture 2 (http://i23.photobucket.com/albums/b352/grnemo/Screenshot2.jpg) you can see that the log service has NOT been started when your bundle is started. Your bundle has a start ordering dependency which is a bad thing.
Your idea to use a ServiceListener is on the right track, but the dymanics of services and coding the use of ServiceListeners is HARD. I would instead suggest that you use a ServiceTracker (see http://www2.osgi.org/javadoc/r4/org/osgi/util/tracker/package-summary.html) The you activator code would look something like: public class Activator implements BundleActivator { private final static String clazz="org.osgi.service.log.LogService"; private ServiceTracker logTracker; public static BundleContext bc = null; public void start(final BundleContext bc) throws Exception { Activator.bc = bc; logTracker = new ServiceTracker(bc, clazz, null); logTracker.open(); } public void stop(BundleContext context) throws Exception { logTracker.close(); System.out.println("Goodbye World"); } } Then, in your thread, whenever you want to use the log servicer, call logTracker.getService(). If you get null, then there is no service available. You can also call logTracker.waitForService(long timeout) and you will block until a service is available. But in general, you should never store the service object in a static or instance variable. Whenever you need the service object, always call the tracker to the object. Then you will never be caught holding a stale service object. Read section 701 in the OSGi Service Compendium specification (r4.cmpn.pdf) for more details and examples. You can download the spec at http://www.osgi.org/osgi_technology/download_specs.asp BJ Hargrave Senior Technical Staff Member, IBM OSGi Fellow and CTO of the OSGi Alliance [EMAIL PROTECTED] office: +1 386 848 1781 mobile: +1 386 848 3788 _______________________________________________ OSGi Developer Mail List [email protected] http://www2.osgi.org/mailman/listinfo/osgi-dev
