java - Is there a way to find out which bundles are using my Bundle? -


i'm building osgi framework , wondering if there way bundles bound mine?

it's because offer service bundles, , make new resources optimize preformence while offering service. offer way destroy resources when no longer needed, want failsafe when bundle unbinds without first deleting used resources.

can use bundlecontext this?

you seem asking 2 different questions. in first paragraph you're asking bundles bound you, interpret mean bundles import exported packaged. in second you're asking consumers of services; these orthogonal issues.

for first question, can use bundlewiring api:

bundlewiring mywiring = mybundle.adapt(bundlewiring.class); list<bundlewire> exports = mywiring.getprovidedwires(packagenamespace.package_namespace); (bundlewire export : exports) {     bundle importer = export.getrequirerwiring().getbundle() } 

for services, can use servicefactory pattern. registering service instance of servicefactory rather directly instance of service interface can keep track of bundles consume service. here skeleton of service implementation using pattern:

public class myservicefactory implements servicefactory<myserviceimpl> {      public myserviceimpl getservice(bundle bundle, serviceregistration reg) {          // create instance of service, customised consumer bundle          return new myserviceimpl(bundle);     }      public void ungetservice(bundle bundle, serviceregistration reg, myserviceimpl svc) {          // release resources used service impl          svc.releaseresources();     } } 

update: since implementing service ds, things bit easier. ds manages creation of instance you... tricky thing working out bundle consumer:

@component(servicefactory = true) public class mycomponent {      @activate     public void activate(componentcontext context) {         bundle consumer = context.getusingbundle();         // ...     } } 

in many cases don't need componentcontext , consuming bundle. if assigning resources each consumer bundle, can save instance fields of component, , remember clean them in deactivate method. ds create instance of component class each consumer bundle.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -