I'm making an application server and in it I need to use some bytecode manipulation (e.g. inserting custom equals
and hashCode
methods to classes annotated with @Entity
). Now I give the JVM a Java Agent (the -javaagent option) which does bytecode transformations using ASM.
I've been considering using OSGi, but I don't know whether it allows me to do the necessary bytecode manipulation.
@Entity
annotation, must be manipulated.OSGI 4.3 added the WeavingHook which allows you to do byte code manipulation with a byte code manipulator of your choice. I use it with JavaAssist on one of my projects and it works great.
1) Yes, it is possible to do bytecode manipulation in OSGi. The how is a bit different than with standard java, you need to use the extender pattern describe here http://www.osgi.org/blog/2007/02/osgi-extender-model.html. I believe Eclipse is using that in their equinox aspect project: http://www.eclipse.org/equinox/incubator/aspects/. Spring DM is definitely using this pattern to autoconfigure osgi dm module.
2) that would be up to the extender pattern you use. tha's how the spring extender is working, looking for configuration files in the META-INF/spring folder of bundle before they are started by the platform.
3) Again, this would be up to the extender you define.
4) I believe this would be possible since before a bundle can be started, it has to resolved and dependencies started, your extender could then analyze bundle dependencies and start the byte code manipulation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With