Chapter 6. Capturing Join Points on Advice

Introduction

In AspectJ, aspects are first-class language constructs just like classes. Classes and their business logic can be advised by aspects and so can aspects themselves. Although aspects can contain methods and other candidate join points, there is one construct that is specific to aspects that is in need of its own mechanism for capturing its join points. That construct is advice.

This chapter deals with using pointcut definitions that are purely concerned with capturing join points that occur within advice. AspectJ provides the solitary adviceexecution() pointcut for this purpose.

Introducing the adviceexecution( ) pointcut’s syntax and a simple example of its use, this chapter then shows how the adviceexecution( ) pointcut can provide an especially effective means of working with situations where advice and the behavior it invokes need to be excluded from being advised by the other aspects in your application.

This chapter ends by showing how to use some interesting characteristics of how AspectJ implements advice to access the original join point that triggered the advice that is in turn being advised using the adviceexecution( ) pointcut.

The adviceexecution( ) pointcut is a reasonably new addition to the AspectJ developers toolbox, and this chapter shows how useful this pointcut can be when working with aspects that apply to aspects.

6.1. Capturing When Advice Is Executing

Problem

You want to capture when any piece of advice is ...

Get AspectJ Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.