hbase-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stack <st...@duboce.net>
Subject Re: Question on Implementation of createConnection
Date Wed, 14 Jun 2017 04:18:59 GMT
On Tue, Jun 13, 2017 at 8:31 PM, Sachin Jain <sachinjain024@gmail.com>
wrote:

> 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.
>
>
No worries.
At your service,
St.Ack


> Thanks again!
>
> On Wed, Jun 14, 2017 at 1:30 AM, Stack <stack@duboce.net> wrote:
>
> > On Mon, Jun 12, 2017 at 8:18 PM, Sachin Jain <sachinjain024@gmail.com>
> > 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_CLI
> ENT_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
> > >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message