Be aware that AOP adds overhead onto these operations. I had to revert usage of AOP in a project once where we some of the methods were called very frequent. In most cases it is no problem but if you application will make heavy use of these getters and setters it could become noticeable.

To your concrete problem:

Guice can only intercept method on objects it has created. This means if you want to be able to intercept methods on objects which are of type Company (or a subclass of it) then you must use Guice to create this object. Either by having Guice inject it into your code or by calling injector.getInstance().



On 15.05.2017 17:27, shishir gowda wrote:
No, I am not injecting instances of Company into classes.
I am actually trying intercept methods of Company which is extending Ebean Model.
I have tried AspectJ too, but with little luck.
Ack wrt foo.

I am basically trying to write a cache layer, which uses redis as cache, and ebean as backend, so the plan is to intercept getters/setters of ebean model, and perform cache ops.


On Monday, 15 May 2017 17:09:53 UTC+5:30, Thomas Broyer wrote:

    Are you really using Guice to inject instances of Company into
    your classes? Guice will only intercept methods on objects that it
    instantiates itself (see
    https://github.com/google/guice/wiki/AOP#limitations
    <https://github.com/google/guice/wiki/AOP#limitations>) If you
    want broader use of AOP, you'll have to use another tool, such as
    AspectJ.
    Oh, and I see your foo method is 'static', that's not going to
    work either, as it cannot be overridden.

    On Monday, May 15, 2017 at 1:30:07 PM UTC+2, shishir gowda wrote:

        I have ebean entity:

            @Entity
            public class Company extends Model {
        @Id
                 public Long id;
                 static void foo {
                       Logger.info("in company");
                 }
            ...
            }

        A guice Module defining the interceptor:

            public class Module extends AbstractModule {
                protected void configure() {

                    CacheImpl cache = new CacheImpl();
                    requestInjection(cache);
                    bindInterceptor(subclassesOf(Company.class),
        any(), cache);

                }
            }

        This does not intercept any calls made to Company (foo(),
        save(),get(), find()..)

        When I change bindInterceptor to a class extending Play
        Controller, it works by intercepting the calls.

        Can some one tell me if I am missing anything?

        my methodInterceptor:

            @Component
            public class CacheImpl implements MethodInterceptor {

                public Object invoke(MethodInvocation method) throws
        Throwable{
                    Logger.info("class {}",method.getClass().getName());
                    if (method.getMethod().getName() == "list") {
                        Logger.info("interceptor in list");
                    } else {
                        Logger.info("in interceptor for  {}",
        method.getMethod().getName());

                    }
                    return method.proceed();

                }
            }

--
You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+unsubscr...@googlegroups.com <mailto:google-guice+unsubscr...@googlegroups.com>. To post to this group, send email to google-guice@googlegroups.com <mailto:google-guice@googlegroups.com>.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/e7028ea4-0a6f-48ea-9a94-e6fcd75273c6%40googlegroups.com <https://groups.google.com/d/msgid/google-guice/e7028ea4-0a6f-48ea-9a94-e6fcd75273c6%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/97a37734-23aa-b070-18f8-00f192ca9383%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.

Reply via email to