Ariel Shaqed (Scolnicov)

11/28/2022, 8:01 AM
Java experts: What's a modern JVM-ish way to do advice aka AOP (Aspect-Oriented programming)? I'm looking to wrap all API calls performed by our hadoopfs library. It will measure number of calls and duration by context inside the client. So I'd like to wrap e.g. io.lakefs.clients.api.ObjectsApi inside a wrapper object. The wrapper will present the same interface as ObjectsApi (say, inherit from it), and will perform one action before calling the underlying method and another after it. I control the calling code, but I have no control over the API code (it's the autogenerated client). Acceptable compromises: • Change the actual type, say be a Wrapped<ObjectsApi> that is not an ObjectsApi. (I control the caller) • Use reflection. (Every call is an HTTP request+response, so the cost of reflection is acceptable) Thanks!
I know about Proxy, but ObjectsApi is not an interface. So I'd need to copy a fair bit of interface, which is too much manual labout.
Right now I'm going for ByteBuddy so I can party like it's 2014.
2014 party