Hi,

I was going through the code of ConnectionFactory.createConnection in
branch-1.3. Here is the method which is called upon eventually

static Connection createConnection(final Configuration conf, final
boolean managed,
    final ExecutorService pool, final User user)
throws IOException {
  String className = conf.get(HConnection.HBASE_CLIENT_CONNECTION_IMPL,
    ConnectionManager.HConnectionImplementation.class.getName());
  Class<?> clazz = null;
  try {
    clazz = Class.forName(className);
  } catch (ClassNotFoundException e) {
    throw new IOException(e);
  }
  try {
    // Default HCM#HCI is not accessible; make it so before invoking.
    Constructor<?> constructor =
      clazz.getDeclaredConstructor(Configuration.class,
        boolean.class, ExecutorService.class, User.class);
    constructor.setAccessible(true);
    return (Connection) constructor.newInstance(conf, managed, pool, user);
  } catch (Exception e) {
    throw new IOException(e);
  }
}


It looks like we are instantiating HConnectionImplementaion via Reflection.
I am a bit curious to understand why we used Reflection here and not
instantiated it via just new operator.

Thanks
-Sachin

Reply via email to