I was able to solve the #b by using receiver's getMethodAnnotation...

However; re. my #a : do I still need to put the @Marker(TimeIt.class) on the 
serviceImpl I am interested in? Would be good to just put it on the method of 
interest directly?

    for(Method m: receiver.getInterface().getMethods()) {
      if (receiver.getMethodAnnotation(m, TimeIt.class) != null) {
        receiver.adviseMethod(m, advice);
      }
    }

Thanks


-----Original Message-----
From: Labhesh Ramchandani
Sent: Monday, September 03, 2018 9:13 PM
To: 'Tapestry users'
Subject: RE: Tapestry decorator with marker

Thanks, Thiago.. I switched to use the "Advisor" solution instead of creating 
my own decorator...
Here's what I have so far:

  @Advise
  @TimeIt
  public static void adviseTimer(MethodAdviceReceiver receiver, Logger log) {
    MethodAdvice advice = invocation -> {
      long start = System.currentTimeMillis();
      invocation.proceed();
      long end = System.currentTimeMillis();
      log.info(receiver.getInterface().getName() + "::" + 
invocation.getMethod().getName() + " took: " +
                             (end - start) + " " + "[ms]");
    };
    for(Method m: receiver.getInterface().getMethods()) {
      if(m.isAnnotationPresent(TimeIt.class)){
        receiver.adviseMethod(m, advice);
      }
    }
  }

1. I put the @Marker(TimeIt.class) on the service implementation and
2. I put @TimeIt on the method I am interested in logging on the service 
interface


Is this the best possible solution?

In particular, I have two concerns:

a. Does the @Marker(TimeIt.class) have to go on the service implementation? Can 
it not be applied to the service's method directly?
b. @TimeIt does not get picked up on the method *definition* in the service's 
implementation. It must be on the service *interface* to work. This makes the 
current solution cumbersome because I need to add annotation to both interface 
and implementation and I cannot control which implementation of the interface 
the TimeIt is applied to

Can you please suggest a better solution?

Thanks again



-----Original Message-----
From: Thiago H. de Paula Figueiredo [mailto:thiag...@gmail.com]
Sent: Monday, September 03, 2018 3:37 PM
To: Tapestry users
Subject: Re: Tapestry decorator with marker

On Sun, Sep 2, 2018 at 9:56 PM Labhesh Ramchandani <
labhesh.ramchand...@aqr.com> wrote:

> Hi,
>

Hello!


>   @Decorate
>   @TimeIt
>   public static <T> T decorateTimer(Class<T> serviceInterface, T delegate,
>       String serviceId, Logger logger,
>       TimerDecorator decorator) {
>     return decorator.build(serviceInterface, delegate, serviceId, logger);
>   }
>
> Is there a way to annotate just the specific method? I don't want to time
> all methods...just the ones that have the marker on them?
> In the example above; I'd like to decorate (and time) just method A and
> not B; how can I do that? Also how do I get the methodReciever to log the
> name of the specific methodA being timed?
>

Yes. Instead of using methodAdviceReceiver.adviseAllMethods(advice), you
can specify which methods you want to advise by using adviseMethod(Method
method, MethodAdvice advice) instead. Of course, the logic to define which
methods to advise is up to you.

--
Thiago

________________________________

Disclaimer: This e-mail may contain confidential and/or privileged information. 
If you are not the intended recipient or have received this e-mail in error, 
please notify the sender immediately and destroy/delete this e-mail. You are 
hereby notified that any unauthorized copying, disclosure or distribution of 
the material in this e-mail is strictly prohibited.

AQR Capital Management, LLC, along with its affiliates (collectively "AQR") may 
collect certain personal information from you. AQR operates pursuant to a 
Global Privacy Policy which describes the types of personal information we 
obtain, how we use the information, with whom we share it and the choices 
available to you regarding our use of the information. We also describe the 
measures we take to protect the security of the information and how you can 
contact us about our privacy practices. By providing your personal information 
you agree to do so pursuant to the Global Privacy Policy. For a copy of the 
Global Privacy Policy please click here<https://www.aqr.com/Privacy-Policy>.

This communication is for informational purposes only. It is not intended as an 
offer or solicitation for the purchase or sale of any financial instrument or 
as an official confirmation of any transaction. All information contained in 
this communication is not warranted as to completeness or accuracy and is 
subject to change without notice. Any comments or statements made in this 
communication do not necessarily reflect those of AQR Capital Management, LLC 
and its affiliates.

Reply via email to