For implementing your own matcher AbstractMatcher would be a good start.

i.e.
public class MyMatcher extends AbstractMatcher<Method> {
    public boolean matches(Method method) {
        // your code here
    }
}

Note: the above can only match methods. if it should also be able to match classes make your matcher extend one of the following:
 - AbstractMatcher<AnnotatedElement>
 - AbstractMatcher<GenericDeclaration>
 - AbstractMatcher<Object>



On 10/11/2012 04:42 PM, Rob Withers wrote:

I did find the Annotations solution.

 

What would my own Matcher look like, perhaps using reflection and AspectJ expressions to specify methods?  Is there such a duck out there?

 

Thanks,

Rob

 

From: google-guice@googlegroups.com [mailto:google-guice@googlegroups.com] On Behalf Of Stephan Classen
Sent: Thursday, October 11, 2012 2:46 AM
To: google-guice@googlegroups.com
Subject: Re: Aspect logging in Guice?

 

You can write your own matche and use it instead of passing Matchers.any().
Or if it is ok for you to annotate the methods which you want to intercept you can use the existing Matchers.annotatedWith(...)


On 10/10/2012 05:37 AM, Rob Withers wrote:

The first one you point to is a “Built-in Binding”.  However, I do not see this in the guice-3.0.jar.  Also, how do I use it?

 

The second link on Custom Injections scans for a Logger in each class, so this does not seem to be using AOP.

 

Here is the class I came up with, below.  My problem is that I don’t see how to install the pointcut to intercept a specific method in a class.  I can bind it to all methods, but not one method.  How can I do that?

 

public class WhisperModule extends AbstractMurmurModule {

 

       @Override

       protected void configure() {

              …

 

bindInterceptor(Matchers.subclassesOf(WhisperTerminal.class), Matchers.any(), new LoggingInterceptor());

       }

}

 

public class LoggingInterceptor implements MethodInterceptor {

    private Logger logger;

 

    public LoggingInterceptor() {

       PropertyConfigurator.configure("log4j.properties");

       logger = Logger.getLogger(LoggingInterceptor.class);

    }

 

    public Object invoke(MethodInvocation methodInvocation) throws Throwable {

       String header = methodInvocation.getThis().getClass()

                     + ":" + methodInvocation.getMethod().getName();

        logger.info(header + " invocation");

        Object result = null;

        try {

            result = methodInvocation.proceed();

            logger.info(header + " return: " + result);

            return result;

        } catch (Exception ex) {

            logger.error(header, ex);

              throw ex;

        }

    }

}

 

 

Thanks,

Rob

 

From: google-guice@googlegroups.com [mailto:google-guice@googlegroups.com] On Behalf Of Cédric Beust ?
Sent: Tuesday, October 09, 2012 10:56 PM
To: google-guice@googlegroups.com
Subject: Re: Aspect logging in Guice?

 

Something like that?

 

Or you could inject your own loggers with type listeners.


-- 

Cédric




On Tue, Oct 9, 2012 at 5:31 PM, Rob Withers <reefed...@gmail.com> wrote:

Before I run off and implement a LoggingInterceptor, is there an AOP logging facility in core guice or an extension I could use?

 

Thanks,
Rob

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-guice/-/rphjmZue5wQJ.
To post to this group, send email to google-guice@googlegroups.com.
To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.

 

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to google-guice@googlegroups.com.
To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to google-guice@googlegroups.com.
To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.

 

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to google-guice@googlegroups.com.
To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to google-guice@googlegroups.com.
To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to google-guice@googlegroups.com.
To unsubscribe from this group, send email to google-guice+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.

Reply via email to