Tapestry decorator with marker

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Tapestry decorator with marker

labheshr
Hi,

I've written a simple decorator as follows (in my app module):
  @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);
  }

With the marker definition as:

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@UseWith(AnnotationUseContext.SERVICE)
public @interface TimeIt {
}


And here's how I use it:

@Marker(Timer.class)
public class ASpecificManagerImpl implements ASpecificManager {

public void methodA() {...}

public void methodB() {...}
}

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?

My timing advisor looks like this

  public <T> void addTimingAdvice(MethodAdviceReceiver methodAdviceReceiver, Class<T> serviceInterface, Logger logger) {
    MethodAdvice advice = invocation -> {
      long start = System.currentTimeMillis();
      invocation.proceed();
      long end = System.currentTimeMillis();
      logger.info(serviceInterface.getName() + " took: " + (end - start) + " [ms]");
    };
    methodAdviceReceiver.adviseAllMethods(advice);
  }

Thanks


________________________________

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 | Threaded
Open this post in threaded view
|

RE: Tapestry decorator with marker

labheshr
Minor correction:

I meant to type:

@Marker(TimeIt.class)
public class ASpecificManagerImpl implements ASpecificManager {...}

in my email.. (and not Timer.class...)

(My question is still the same...thanks)


From: Labhesh Ramchandani
Sent: Sunday, September 02, 2018 8:56 PM
To: '[hidden email]'
Subject: Tapestry decorator with marker

Hi,

I've written a simple decorator as follows (in my app module):
  @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);
  }

With the marker definition as:

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@UseWith(AnnotationUseContext.SERVICE)
public @interface TimeIt {
}


And here's how I use it:

@Marker(Timer.class)
public class ASpecificManagerImpl implements ASpecificManager {

public void methodA() {...}

public void methodB() {...}
}

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?

My timing advisor looks like this

  public <T> void addTimingAdvice(MethodAdviceReceiver methodAdviceReceiver, Class<T> serviceInterface, Logger logger) {
    MethodAdvice advice = invocation -> {
      long start = System.currentTimeMillis();
      invocation.proceed();
      long end = System.currentTimeMillis();
      logger.info(serviceInterface.getName() + " took: " + (end - start) + " [ms]");
    };
    methodAdviceReceiver.adviseAllMethods(advice);
  }

Thanks


________________________________

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 | Threaded
Open this post in threaded view
|

Re: Tapestry decorator with marker

Thiago H de Paula Figueiredo
In reply to this post by labheshr
On Sun, Sep 2, 2018 at 9:56 PM Labhesh Ramchandani <
[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

RE: Tapestry decorator with marker

labheshr
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:[hidden email]]
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 <
[hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

RE: Tapestry decorator with marker

labheshr
In reply to this post by Thiago H de Paula Figueiredo
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:[hidden email]]
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 <
[hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Tapestry decorator with marker

Thiago H de Paula Figueiredo
In reply to this post by labheshr
On Mon, Sep 3, 2018 at 10:12 PM Labhesh Ramchandani <
[hidden email]> 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:[hidden email]]
> 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 <
> [hidden email]> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>


--
Thiago
Reply | Threaded
Open this post in threaded view
|

RE: Tapestry decorator with marker

labheshr

I use 5.4.1

However; using the advisor's built in method solves my problem of putting @TimeIt on the function implementation...as this:

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

Thanks for answering all my questions!

-----Original Message-----
From: Thiago H. de Paula Figueiredo [mailto:[hidden email]]
Sent: Tuesday, September 04, 2018 10:24 AM
To: Tapestry users
Subject: Re: Tapestry decorator with marker

On Mon, Sep 3, 2018 at 10:12 PM Labhesh Ramchandani <
[hidden email]> 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:[hidden email]]
> 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 <
> [hidden email]> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>


--
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: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Tapestry decorator with marker

Thiago H de Paula Figueiredo
On Tue, Sep 4, 2018 at 11:29 AM Labhesh Ramchandani <
[hidden email]> wrote:

>
> I use 5.4.1
>

Just change to 5.4.3. There's absolutely no reason to do that.


> However; using the advisor's built in method solves my problem of putting
> @TimeIt on the function implementation...as this:
>
>     for(Method m: receiver.getInterface().getMethods()) {
>       if (receiver.getMethodAnnotation(m, TimeIt.class) != null) {
>         receiver.adviseMethod(m, advice);
>       }
>     }
>

I'm not sure how it works for the annotation being just in the method
implementation, since you're explicitly checking the interface methods.


>
> Thanks for answering all my questions!
>

You're welcome


>
> -----Original Message-----
> From: Thiago H. de Paula Figueiredo [mailto:[hidden email]]
> Sent: Tuesday, September 04, 2018 10:24 AM
> To: Tapestry users
> Subject: Re: Tapestry decorator with marker
>
> On Mon, Sep 3, 2018 at 10:12 PM Labhesh Ramchandani <
> [hidden email]> 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:[hidden email]]
> > 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 <
> > [hidden email]> 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: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
>
>
> --
> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>


--
Thiago