eran
eran

Reputation: 1

Can an OSGI bundle tell what bundle consumes it?

if, for example, I have a 'sayHello()' method and I want this method to return a slightly different string depending on the bundle who called it.

i cannot trust the caller bundle to provide it's name but rather would like to somehow ask the container for the caller's id.

Upvotes: 0

Views: 95

Answers (1)

Christian Schneider
Christian Schneider

Reputation: 19626

If you are talking about a simple method call then this is not possible. If you provide a service to consume then you can do this.

Instead of registering the Class containing sayHello as a service you can register a class implementing http://www.osgi.org/javadoc/r4v43/core/org/osgi/framework/ServiceFactory.html . This class can then create the actual service class and at that moment has access to the bundle that requests the service.

Upvotes: 1

Related Questions