Route scan in OSGi

My project has a set of user annotations that can be present in any bundle deployed in OSGi 4.3. I want to find any class with these annotations in the classpath. I tried using BundleWiring.listResources (...) and Bundle.loadClass (...) for every class found. I did some tests with a small set of packages, and it needs almost 200 MB of constant-generation JVM memory space because all classes are loading.

Is there a way to free the loaded PermGen memory space classes when the program realizes that they do not have these annotations?

Is there a better way to search for annotated classes in OSGi?

+4
source share
2 answers

I think you should not annotate the scan, as it slows down the launch and requires a lot of memory. JEE application servers run annotation scans at startup to make lazy programmers happy, and the result is very annoying (like scanning JPA or EJB annotations).

I assume that you are introducing a technology in which you can define the rules. I suggest you define rules that are similar to them:

  • Annotate your class
  • Enter the MANIFEST header in which the annotated class should be specified.

An even better solution would be to use a custom capability namespace with the specified attributes. For instance:.

Provide-Capability: myNamespace;classes=com.foo.myClass1,com.foo.myClass2

In your technology, you should write a BundleTracker that calls:

BundleWiring.getCapabilities("myNamespace");

, , .

, Bnd MANIFEST. , bnd , maven.

Btw: ASM - Java AST. , , MANIFEST, . MANIFEST, -, -.

+7

OSGi, classpath . , . , OSGi .

, OSGi. , - / . , , @Path @Provider, API- REST.

+2

Source: https://habr.com/ru/post/1536475/


All Articles