eolivelli opened a new pull request #11636: URL: https://github.com/apache/pulsar/pull/11636
- load the DefaultImplementation only once with reflection - use standard Java calls to access the Pulsar Implementation classes - reduce the overall overhead of using Reflection - clarify the relationsship between the classes - add explicit linking between the impl and api classes, this way it is easier to read the code and perform refactorings - allow to handle correctly the Exception thrown by implementation classes ### Motivation Currently the link between the Pulsar Client API and the Implementation is done at runtime, using Java reflection, in the DefaultImplementation class. This comes with a few problems: - it is not clear the Classloader who is loading the classes of the Implementation, DefaultImplementation relied on "RelectionUtils", with surprising effects we saw during the past months, expecially in Pulsar Functions/Pulsar II - the old DefaultImplementation class used to catch all the checked exception and hide them - the old reflection approach used "strings" to refer to implementation classes, making it harder to perform refactorings, understand the code flow (by reading), using the help of the IDE - using reflection is generally "slower", with this fix we are going to save CPU cycles, and also the JVM will be able to understand better what's happening and (probably) perform more runtime optimizations (at least we are going to save a few method calls and stack...) ### Modifications - Introduce a new Java interface `PulsarClientImplementationBinding` that defines the connections from the "public API" and the "implementation", this interface contains all the methods of the old "DefaultImplementation" - Move the Implementation to the pulsar-client module, in the concrete class `PulsarClientImplementationBindingImpl` - `PulsarClientImplementationBindingImpl` can access directly, without reflection all the implementation classes, this is faster and also it allows us to have direct linking (for human reading, for IDE help....) - Load the `PulsarClientImplementationBindingImpl` class only once - Rewrite all the references to the old `DefaultImplementation.staticMethod(xxx)` to `DefaultImplementation.getDefaultImplementation().method(xxx)` - Fix some places in which hidden IOException may have bubbled up breaking things without notice ### Verifying this change This change is a trivial rework / code cleanup without any test coverage. ### Documentation No need for docs -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
