On Mon, Sep 3, 2018 at 10:12 PM Labhesh Ramchandani <
labhesh.ramchand...@aqr.com> wrote:

> Thanks, Thiago.. I switched to use the "Advisor" solution instead of
> creating my own decorator...
>

You're welcome!


> 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);
>       }
>     }
>   }
>

It looks good!

a. Does the @Marker(TimeIt.class) have to go on the service implementation?
> Can it not be applied to the service's method directly?
>

You need it in the service implementation because otherwise your advise
method wouldn't be applied to the service at all.


> 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
>

What Tapestry version are you using? For service implementation methods
which implement a service interface method, you can put the annotation in
the service implementation method since Tapestry 5.4.2.


>
> 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.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>


-- 
Thiago

Reply via email to