[
https://issues.apache.org/jira/browse/HBASE-18898?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16210114#comment-16210114
]
Appy commented on HBASE-18898:
------------------------------
Spent few hours reading Guice user guide. So can do DI on constructors, methods
and fields. We can even do [on-demand
injection|https://github.com/google/guice/wiki/Injections#on-demand-injection].
Guice should also injects everything marked @Inject on object creation, but we
don't want that, so we can skip that by creating instances ourselves.
ref: http://docs.oracle.com/javaee/6/api/javax/inject/Inject.html
bq. Constructors are injected first, followed by fields, and then methods.
Fields and methods in superclasses are injected before those in subclasses.
Ordering of injection among fields and among methods in the same class is not
specified.
However, i don't see any way to specify the functions that should be injected.
Guice will always inject *all* methods marked @Inject. So we can't have
something like {{@Hook.PreGet boolean myfunction(....) }} and be able to
select functions marked with specific annotation.
Given there are no selectors/matchers functionality for injection (like the
ones for AOP), i don't see any way around other than doing reflection ourselves.
Any suggestions?
While talking about AOP, i can't come up with any way to use AOP for dependency
injection while invoking observer hooks.
After all that learning, i do have a way to get rid of million wrappers in
*CpHost classes using AOP. Unlike full scale jax-rs style DI, this likely
wouldn't have any external impact (we are running out of time anyways) and
would be much less work.
> Provide way for the core flow to know whether CP implemented each of the hooks
> ------------------------------------------------------------------------------
>
> Key: HBASE-18898
> URL: https://issues.apache.org/jira/browse/HBASE-18898
> Project: HBase
> Issue Type: Improvement
> Components: Coprocessors, Performance
> Reporter: Anoop Sam John
> Assignee: Anoop Sam John
> Priority: Critical
>
> This came as a discussion topic at the tale of HBASE-17732
> Can we have a way in the code (before trying to call the hook) to know
> whether the user has implemented one particular hook or not? eg: On write
> related hooks only prePut() might be what the user CP implemented. All others
> are just dummy impl from the interface. Can we have a way for the core code
> to know this and avoid the call to other dummy hooks fully? Some times we do
> some processing for just calling CP hooks (Say we have to make a POJO out of
> PB object for calling) and if the user CP not impl this hook, we can avoid
> this extra work fully. The pain of this will be more when we have to later
> deprecate one hook and add new. So the dummy impl in new hook has to call the
> old one and that might be doing some extra work normally.
> If the CP f/w itself is having a way to tell this, the core code can make
> use. What am expecting is some thing like in PB way where we can call
> CPObject.hasPreXXXX(), then CPObject. preXXXX ().. Should not like asking
> users to impl this extra ugly thing. When the CP instance is loaded in the
> RS/HM, that object will be having this info also.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)