in geode-benchmarks/src/main/java/org/apache/geode/benchmark/tasks/StartClientWithSniProxy.java [57:87]
protected ClientCacheFactory reflectivelySetSniSocketFactory(
final ClientCacheFactory clientCacheFactory,
final InetAddress proxyInetAddress)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException,
ClassNotFoundException {
/*
* We'd like to simply do the following, but that would introduce a compile-time dependency on
* Geode [1.13,). But we want this benchmark code to work with older Geode version. So we'll
* use reflection to do it.
*
* return clientCacheFactory
* .setPoolSocketFactory(ProxySocketFactories.sni(
* proxyHostAddress,
* SNI_PROXY_PORT));
*/
final Class<?> proxySocketFactoriesClass =
Class.forName("org.apache.geode.cache.client.proxy.ProxySocketFactories");
final Method sniStaticMethod =
proxySocketFactoriesClass.getMethod("sni", String.class, int.class);
final Object sniSocketFactory =
sniStaticMethod.invoke(null, proxyInetAddress.getHostName(), proxyPort);
final Class<?> socketFactoryClass =
Class.forName("org.apache.geode.cache.client.SocketFactory");
final Method setPoolSocketFactoryMethod =
clientCacheFactory.getClass().getMethod("setPoolSocketFactory", socketFactoryClass);
return (ClientCacheFactory) setPoolSocketFactoryMethod.invoke(clientCacheFactory,
sniSocketFactory);
}