Thanks Stack! This makes sense I just did not happen to observe that we are getting className from configuration which makes it a pluggable implementation.
Thanks again! On Wed, Jun 14, 2017 at 1:30 AM, Stack <[email protected]> wrote: > On Mon, Jun 12, 2017 at 8:18 PM, Sachin Jain <[email protected]> > wrote: > > > 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. > > > > > This pattern is usual in place to allow plugging in alternative > implementations. > S > > > > Thanks > > -Sachin > > >
