Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fix broken links

...

This is a method that is placed in a module class. Note the terminology: advise is the verb ("to advise a method") and advice is the noun ("with this advice"). The MethodAdviceReceiver is a wrapper around the service being advised: you can add advice to some or all methods of the service, and also obtain the interface of the service. It is automatically passed into service advisor methods.

...

Service advisor methods are always void methods (this is different than service decorator methods).

The @Match annotation indicates that this advice applies to all services (both your own, and those defined by Tapestry). You will want to narrow down which services are actually targetted in most cases.

Note that some services, especially those built-in to Tapestry IoC, are marked as not subject to decoration, this applies to service advice as well as service decoration.

The MethodAdvice interface is very simple; it receives an Invocation representing a method call. Invocation has methods for inspecting the type and value of the parameters, and for overriding the values of the parameters.

...

No Format
  @Match("*")
  public static void adviseLogging(LoggingAdvisor loggingAdvisor, Logger logger, MethodAdviceReciever reciever)
  {
    loggingAdvisor.addLoggingAdvice(logger, reciever);
  }

LoggingAdvisor is a built-in Tapestry IoC service. This demonstrates how services can be injected into service advisor methods. The Logger parameter is the logger for the service being advised.

Lazy Advice

LazyAdvisor makes method invocations lazy: methods that return an interface (rather than a value) will not execute immediately; instead, the method invocation is postponed until a method of the return value is invoked.

...

In many cases, the order in which the advice is given is very important; for example, you may want logging first, then transaction management, then security checks. The @Order annotation allows you to explictly set the order.

...