You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Sanket Sharma <sa...@gmail.com> on 2014/04/05 15:45:27 UTC
Service Advisor and Annotations
Hi,
In my app module, I have a service advisor method defined like the
following:
@Advise
@NeedsAdvice
public void adviseMe(MyAdvisor myAdvisor, MethodAdviceReceiver
methodAdviceReceiver, Logger logger)
{
logger.debug("Advising");
myAdvisor.addAdvice(methodAdviceReceiver);
}
@NeedsAdvise is defined as below:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface NeedsAdvice{}
The service that is to be advised is defined as below:
@NeedsAdvice
public class MyServiceImpl implements MyService {
...
..
}
However, when the application runs, the adviceMe method is never invoked
and the methods calls are never intercepted.
When I change the method signature to include the service ID being advised,
everything works as expected:
public void adviseMyService(MyAdvisor myAdvisor, MethodAdviceReceiver
methodAdviceReceiver, Logger logger)
{
logger.debug("Advising");
myAdvisor.addAdvice(methodAdviceReceiver);
}
Not sure what am missing with marker annotations? Would appreciate any help.
Sanket
Re: Service Advisor and Annotations
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Sat, 05 Apr 2014 15:30:43 -0300, Sanket Sharma <sa...@gmail.com>
wrote:
> Hi,
Hi!
> Thank you for the response. I am using 5.4 Beta 3.
Nice! Correcting myself to be more exact, since 5.4-beta-3 the service
proxies get the service implementation annotations, both at class level
and method level. This was my pet peeve my Tapestry-IoC for years until a
good soul fixed that. :p
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Service Advisor and Annotations
Posted by Sanket Sharma <sa...@gmail.com>.
Hi,
Thank you for the response. I am using 5.4 Beta 3.
Best Regards,
Sanket
On Sat, Apr 5, 2014 at 7:30 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:
> Hi!
>
> On Sat, 05 Apr 2014 12:59:30 -0300, Sanket Sharma <sa...@gmail.com>
> wrote:
>
> Was wondering if there is a more direct way to get a list of all methods
>> in the service marked with a given annotation?
>>
>
> Not from Tapestry-IoC. By the way, are you using Tapestry 5.4-beta or
> later? They're the only versions in which getting annotations from
> services' methods and classes will work.
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
Re: Service Advisor and Annotations
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
Hi!
On Sat, 05 Apr 2014 12:59:30 -0300, Sanket Sharma <sa...@gmail.com>
wrote:
> Was wondering if there is a more direct way to get a list of all methods
> in the service marked with a given annotation?
Not from Tapestry-IoC. By the way, are you using Tapestry 5.4-beta or
later? They're the only versions in which getting annotations from
services' methods and classes will work.
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Service Advisor and Annotations
Posted by Sanket Sharma <sa...@gmail.com>.
So I made some progress with my advisor method and seem to have hit another
road block:
The examples for serviceAdvisor in documentation receive an argument of
MethodAdviceReceiver:
public static void adviseNonNull(MethodAdviceReceiver receiver) {
...
}
In my code I would like access all methods in the class marked with a
certain annotation. Currently, my code looks like below:
for (Method method : receiver.getInterface().getMethods()) {
logger.debug("Checking method: "+ method.getName());
NeedsAdvice advice = receiver.getMethodAnnotation(method, NeedsAdvice.
class);
logger.debug("Annotation @NeedsAdvice found on Method: " + method.getName()
+ " " + (advice==null));
if (advice != null) {
adviceMethod(advice.propagation(), method, receiver);
}
}
Was wondering if there is a more direct way to get a list of all methods in
the service marked with a given annotation?
Sanket
On Sat, Apr 5, 2014 at 5:06 PM, Sanket Sharma <sa...@gmail.com>wrote:
> Okay, I think I figured it out.
> The marker annotation needs to applied to the implementation class as
> follows:
>
> @Marker(NeedsAdvice.class)
>
> Is that correct?
>
>
>
> On Sat, Apr 5, 2014 at 3:45 PM, Sanket Sharma <sa...@gmail.com>wrote:
>
>> Hi,
>>
>> In my app module, I have a service advisor method defined like the
>> following:
>>
>> @Advise
>>
>> @NeedsAdvice
>>
>> public void adviseMe(MyAdvisor myAdvisor, MethodAdviceReceiver
>> methodAdviceReceiver, Logger logger)
>>
>> {
>>
>> logger.debug("Advising");
>>
>> myAdvisor.addAdvice(methodAdviceReceiver);
>>
>> }
>>
>> @NeedsAdvise is defined as below:
>>
>>
>> @Retention(RetentionPolicy.RUNTIME)
>>
>> @Target({ElementType.TYPE, ElementType.METHOD})
>>
>> public @interface NeedsAdvice{}
>>
>>
>> The service that is to be advised is defined as below:
>>
>>
>> @NeedsAdvice
>>
>> public class MyServiceImpl implements MyService {
>>
>> ...
>>
>> ..
>>
>> }
>>
>>
>>
>>
>>
>> However, when the application runs, the adviceMe method is never invoked
>> and the methods calls are never intercepted.
>>
>> When I change the method signature to include the service ID being
>> advised, everything works as expected:
>>
>> public void adviseMyService(MyAdvisor myAdvisor, MethodAdviceReceiver
>> methodAdviceReceiver, Logger logger)
>>
>> {
>>
>> logger.debug("Advising");
>>
>> myAdvisor.addAdvice(methodAdviceReceiver);
>>
>> }
>>
>>
>> Not sure what am missing with marker annotations? Would appreciate any
>> help.
>>
>>
>> Sanket
>>
>>
>>
>
Re: Service Advisor and Annotations
Posted by Sanket Sharma <sa...@gmail.com>.
Okay, I think I figured it out.
The marker annotation needs to applied to the implementation class as
follows:
@Marker(NeedsAdvice.class)
Is that correct?
On Sat, Apr 5, 2014 at 3:45 PM, Sanket Sharma <sa...@gmail.com>wrote:
> Hi,
>
> In my app module, I have a service advisor method defined like the
> following:
>
> @Advise
>
> @NeedsAdvice
>
> public void adviseMe(MyAdvisor myAdvisor, MethodAdviceReceiver
> methodAdviceReceiver, Logger logger)
>
> {
>
> logger.debug("Advising");
>
> myAdvisor.addAdvice(methodAdviceReceiver);
>
> }
>
> @NeedsAdvise is defined as below:
>
>
> @Retention(RetentionPolicy.RUNTIME)
>
> @Target({ElementType.TYPE, ElementType.METHOD})
>
> public @interface NeedsAdvice{}
>
>
> The service that is to be advised is defined as below:
>
>
> @NeedsAdvice
>
> public class MyServiceImpl implements MyService {
>
> ...
>
> ..
>
> }
>
>
>
>
>
> However, when the application runs, the adviceMe method is never invoked
> and the methods calls are never intercepted.
>
> When I change the method signature to include the service ID being
> advised, everything works as expected:
>
> public void adviseMyService(MyAdvisor myAdvisor, MethodAdviceReceiver
> methodAdviceReceiver, Logger logger)
>
> {
>
> logger.debug("Advising");
>
> myAdvisor.addAdvice(methodAdviceReceiver);
>
> }
>
>
> Not sure what am missing with marker annotations? Would appreciate any
> help.
>
>
> Sanket
>
>
>