This is a usecase for registering a ServiceFactory. A ServiceFactory allows for a service implementation to know which bundle is getting and using their service implementations with the org.osgi.framework.ServiceFactory.getService(Bundle, ServiceRegistration) method. The framework will call this method and pass the Bundle object which is getting the service. The service implementation can then use this information to log error messages against the bundle that got the service.
So Bundle Y would register a ServiceFactory for each service it offered and then would be informed of Bundle X using its service and can react properly when Bundle X gets a service and uses it incorrectly. HTH Tom |------------> | From: | |------------> >-----------------------------------------------------------------------------------------------------------------------------------------------| |Igmar Palsenberg <[email protected]> | >-----------------------------------------------------------------------------------------------------------------------------------------------| |------------> | To: | |------------> >-----------------------------------------------------------------------------------------------------------------------------------------------| |OSGi Developer Mail List <[email protected]> | >-----------------------------------------------------------------------------------------------------------------------------------------------| |------------> | Date: | |------------> >-----------------------------------------------------------------------------------------------------------------------------------------------| |11/01/2010 10:05 PM | >-----------------------------------------------------------------------------------------------------------------------------------------------| |------------> | Subject: | |------------> >-----------------------------------------------------------------------------------------------------------------------------------------------| |Re: [osgi-dev] Logging from within OSGi services and bundles | >-----------------------------------------------------------------------------------------------------------------------------------------------| Hi Neil, > If bundle Y wants to know its immediate caller then it can call > Thread.currentThread.getStackTrace(). The problem is, this will not > tell you from which bundle you were called -- the only way to get that > kind of information is to register a ServiceFactory. > > What is the purpose of bundle Y? It just seems to be getting in the > way. Why not call the LogService directly from bundle X? Bundle Y is a utility bundle, of a library, dependent on how you define those terms. Y doesn't do anything itself : It's just a big collection of useful stuff. X is a application that uses Y, so we want problems in Y to be put in logfiles of bundle X, which is the caller. We now have no idea who called services in Y, since problems can also be caused by something in X (bad call sequence, runtime exception, etc). X is just one of it's kind : In the realworld, there a dozens of bundles on the same level as X which all use services from bundle Y. In order to filter messages in the appropriate logfiles of the X-level bundles, we need to know the caller of services in bundle Y. I hope the above makes things clear, and why we need to know the caller. Regards, Igmar _______________________________________________ OSGi Developer Mail List [email protected] https://mail.osgi.org/mailman/listinfo/osgi-dev
<<inline: graycol.gif>>
<<inline: ecblank.gif>>
_______________________________________________ OSGi Developer Mail List [email protected] https://mail.osgi.org/mailman/listinfo/osgi-dev
