[feat] Authentication implementations such as AuthenticationOAuth2 should support sharing thread pools or DNS cache
- Dominant language
- Java
- Stars
- 15.3k
- Forks
- 3.8k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 160
Description
### Search before reporting
- [x] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.
### Motivation
PIP-234 implementation #24790 adds support for sharing thread pools and DNS resolver/cache across multiple client instances. However, authentication implementations such as AuthenticationOAuth2 create new thread pools and DNS resolvers/caches. This isn't desired, since it would be useful to be able to share the Netty Event Loop and configure the DNS settings in the client and use them for all Pulsar client DNS lookups, at least for most common use cases.
### Solution
The org.apache.pulsar.client.api.Authentication interface could be changed so that the "container" could pass a context instance with contains methods to lookup shared instances.
```java
/**
* Initialize the authentication provider.
*/
default void start(AuthenticationInitContext context) throws PulsarClientException {
start();
}
/**
* Initialize the authentication provider.
*/
void start() throws PulsarClientException;
```
The AuthenticationInitContext could contain generic "getService" and "getServiceByName" methods:
```java
public interface AuthenticationInitContext {
Optional getService(Class serviceClass);
Optional getServiceByName(Class serviceClass, String name);
}
```
This solution could be used to pass the Netty event loop, DNS resolver and Timer to be shared in the AuthenticationOAuth2 implementation.
### Alternatives
_No response_
### Anything else?
_No response_
### Are you willing to submit a PR?
- [x] I'm willing to submit a PR!
Contributor guide
Assessment
This issue has not been assessed yet.