Rename SystemArchitecture aspect to CommonPointcuts in AOP ref doc

See gh-25357
This commit is contained in:
Sam Brannen 2020-07-06 16:20:05 +02:00
parent 52c2ca610b
commit 8be2a43d52
1 changed files with 41 additions and 41 deletions

View File

@ -524,10 +524,10 @@ matching.
[[aop-common-pointcuts]] [[aop-common-pointcuts]]
==== Sharing Common Pointcut Definitions ==== Sharing Common Pointcut Definitions
When working with enterprise applications, developers often want to refer to modules of the When working with enterprise applications, developers often want to refer to modules of
application and particular sets of operations from within several aspects. We recommend the application and particular sets of operations from within several aspects. We
defining a `SystemArchitecture` aspect that captures common pointcut expressions for recommend defining a `CommonPointcuts` aspect that captures common pointcut expressions
this purpose. Such an aspect typically resembles the following example: for this purpose. Such an aspect typically resembles the following example:
[source,java,indent=0,subs="verbatim",role="primary"] [source,java,indent=0,subs="verbatim",role="primary"]
.Java .Java
@ -538,7 +538,7 @@ this purpose. Such an aspect typically resembles the following example:
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
@Aspect @Aspect
public class SystemArchitecture { public class CommonPointcuts {
/** /**
* A join point is in the web layer if the method is defined * A join point is in the web layer if the method is defined
@ -602,7 +602,7 @@ this purpose. Such an aspect typically resembles the following example:
import org.springframework.aop.Pointcut import org.springframework.aop.Pointcut
@Aspect @Aspect
class SystemArchitecture { class CommonPointcuts {
/** /**
* A join point is in the web layer if the method is defined * A join point is in the web layer if the method is defined
@ -669,7 +669,7 @@ write the following:
---- ----
<aop:config> <aop:config>
<aop:advisor <aop:advisor
pointcut="com.xyz.myapp.SystemArchitecture.businessService()" pointcut="com.xyz.myapp.CommonPointcuts.businessService()"
advice-ref="tx-advice"/> advice-ref="tx-advice"/>
</aop:config> </aop:config>
@ -923,7 +923,7 @@ You can declare before advice in an aspect by using the `@Before` annotation:
@Aspect @Aspect
public class BeforeExample { public class BeforeExample {
@Before("com.xyz.myapp.SystemArchitecture.dataAccessOperation()") @Before("com.xyz.myapp.CommonPointcuts.dataAccessOperation()")
public void doAccessCheck() { public void doAccessCheck() {
// ... // ...
} }
@ -939,7 +939,7 @@ You can declare before advice in an aspect by using the `@Before` annotation:
@Aspect @Aspect
class BeforeExample { class BeforeExample {
@Before("com.xyz.myapp.SystemArchitecture.dataAccessOperation()") @Before("com.xyz.myapp.CommonPointcuts.dataAccessOperation()")
fun doAccessCheck() { fun doAccessCheck() {
// ... // ...
} }
@ -999,7 +999,7 @@ declare it by using the `@AfterReturning` annotation:
@Aspect @Aspect
public class AfterReturningExample { public class AfterReturningExample {
@AfterReturning("com.xyz.myapp.SystemArchitecture.dataAccessOperation()") @AfterReturning("com.xyz.myapp.CommonPointcuts.dataAccessOperation()")
public void doAccessCheck() { public void doAccessCheck() {
// ... // ...
} }
@ -1015,7 +1015,7 @@ declare it by using the `@AfterReturning` annotation:
@Aspect @Aspect
class AfterReturningExample { class AfterReturningExample {
@AfterReturning("com.xyz.myapp.SystemArchitecture.dataAccessOperation()") @AfterReturning("com.xyz.myapp.CommonPointcuts.dataAccessOperation()")
fun doAccessCheck() { fun doAccessCheck() {
// ... // ...
} }
@ -1040,7 +1040,7 @@ the following example shows:
public class AfterReturningExample { public class AfterReturningExample {
@AfterReturning( @AfterReturning(
pointcut="com.xyz.myapp.SystemArchitecture.dataAccessOperation()", pointcut="com.xyz.myapp.CommonPointcuts.dataAccessOperation()",
returning="retVal") returning="retVal")
public void doAccessCheck(Object retVal) { public void doAccessCheck(Object retVal) {
// ... // ...
@ -1058,7 +1058,7 @@ the following example shows:
class AfterReturningExample { class AfterReturningExample {
@AfterReturning( @AfterReturning(
pointcut = "com.xyz.myapp.SystemArchitecture.dataAccessOperation()", pointcut = "com.xyz.myapp.CommonPointcuts.dataAccessOperation()",
returning = "retVal") returning = "retVal")
fun doAccessCheck(retVal: Any) { fun doAccessCheck(retVal: Any) {
// ... // ...
@ -1093,7 +1093,7 @@ example shows:
@Aspect @Aspect
public class AfterThrowingExample { public class AfterThrowingExample {
@AfterThrowing("com.xyz.myapp.SystemArchitecture.dataAccessOperation()") @AfterThrowing("com.xyz.myapp.CommonPointcuts.dataAccessOperation()")
public void doRecoveryActions() { public void doRecoveryActions() {
// ... // ...
} }
@ -1109,7 +1109,7 @@ example shows:
@Aspect @Aspect
class AfterThrowingExample { class AfterThrowingExample {
@AfterThrowing("com.xyz.myapp.SystemArchitecture.dataAccessOperation()") @AfterThrowing("com.xyz.myapp.CommonPointcuts.dataAccessOperation()")
fun doRecoveryActions() { fun doRecoveryActions() {
// ... // ...
} }
@ -1133,7 +1133,7 @@ following example shows how to do so:
public class AfterThrowingExample { public class AfterThrowingExample {
@AfterThrowing( @AfterThrowing(
pointcut="com.xyz.myapp.SystemArchitecture.dataAccessOperation()", pointcut="com.xyz.myapp.CommonPointcuts.dataAccessOperation()",
throwing="ex") throwing="ex")
public void doRecoveryActions(DataAccessException ex) { public void doRecoveryActions(DataAccessException ex) {
// ... // ...
@ -1151,7 +1151,7 @@ following example shows how to do so:
class AfterThrowingExample { class AfterThrowingExample {
@AfterThrowing( @AfterThrowing(
pointcut = "com.xyz.myapp.SystemArchitecture.dataAccessOperation()", pointcut = "com.xyz.myapp.CommonPointcuts.dataAccessOperation()",
throwing = "ex") throwing = "ex")
fun doRecoveryActions(ex: DataAccessException) { fun doRecoveryActions(ex: DataAccessException) {
// ... // ...
@ -1184,7 +1184,7 @@ The following example shows how to use after finally advice:
@Aspect @Aspect
public class AfterFinallyExample { public class AfterFinallyExample {
@After("com.xyz.myapp.SystemArchitecture.dataAccessOperation()") @After("com.xyz.myapp.CommonPointcuts.dataAccessOperation()")
public void doReleaseLock() { public void doReleaseLock() {
// ... // ...
} }
@ -1200,7 +1200,7 @@ The following example shows how to use after finally advice:
@Aspect @Aspect
class AfterFinallyExample { class AfterFinallyExample {
@After("com.xyz.myapp.SystemArchitecture.dataAccessOperation()") @After("com.xyz.myapp.CommonPointcuts.dataAccessOperation()")
fun doReleaseLock() { fun doReleaseLock() {
// ... // ...
} }
@ -1252,7 +1252,7 @@ The following example shows how to use around advice:
@Aspect @Aspect
public class AroundExample { public class AroundExample {
@Around("com.xyz.myapp.SystemArchitecture.businessService()") @Around("com.xyz.myapp.CommonPointcuts.businessService()")
public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable { public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
// start stopwatch // start stopwatch
Object retVal = pjp.proceed(); Object retVal = pjp.proceed();
@ -1272,7 +1272,7 @@ The following example shows how to use around advice:
@Aspect @Aspect
class AroundExample { class AroundExample {
@Around("com.xyz.myapp.SystemArchitecture.businessService()") @Around("com.xyz.myapp.CommonPointcuts.businessService()")
fun doBasicProfiling(pjp: ProceedingJoinPoint): Any { fun doBasicProfiling(pjp: ProceedingJoinPoint): Any {
// start stopwatch // start stopwatch
val retVal = pjp.proceed() val retVal = pjp.proceed()
@ -1331,7 +1331,7 @@ You could write the following:
[source,java,indent=0,subs="verbatim,quotes",role="primary"] [source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java .Java
---- ----
@Before("com.xyz.myapp.SystemArchitecture.dataAccessOperation() && args(account,..)") @Before("com.xyz.myapp.CommonPointcuts.dataAccessOperation() && args(account,..)")
public void validateAccount(Account account) { public void validateAccount(Account account) {
// ... // ...
} }
@ -1339,7 +1339,7 @@ You could write the following:
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin .Kotlin
---- ----
@Before("com.xyz.myapp.SystemArchitecture.dataAccessOperation() && args(account,..)") @Before("com.xyz.myapp.CommonPointcuts.dataAccessOperation() && args(account,..)")
fun validateAccount(account: Account) { fun validateAccount(account: Account) {
// ... // ...
} }
@ -1358,7 +1358,7 @@ from the advice. This would look as follows:
[source,java,indent=0,subs="verbatim,quotes",role="primary"] [source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java .Java
---- ----
@Pointcut("com.xyz.myapp.SystemArchitecture.dataAccessOperation() && args(account,..)") @Pointcut("com.xyz.myapp.CommonPointcuts.dataAccessOperation() && args(account,..)")
private void accountDataAccessOperation(Account account) {} private void accountDataAccessOperation(Account account) {}
@Before("accountDataAccessOperation(account)") @Before("accountDataAccessOperation(account)")
@ -1369,7 +1369,7 @@ from the advice. This would look as follows:
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin .Kotlin
---- ----
@Pointcut("com.xyz.myapp.SystemArchitecture.dataAccessOperation() && args(account,..)") @Pointcut("com.xyz.myapp.CommonPointcuts.dataAccessOperation() && args(account,..)")
private fun accountDataAccessOperation(account: Account) { private fun accountDataAccessOperation(account: Account) {
} }
@ -1612,7 +1612,7 @@ The following example shows how to do so:
.Java .Java
---- ----
@Around("execution(List<Account> find*(..)) && " + @Around("execution(List<Account> find*(..)) && " +
"com.xyz.myapp.SystemArchitecture.inDataAccessLayer() && " + "com.xyz.myapp.CommonPointcuts.inDataAccessLayer() && " +
"args(accountHolderNamePattern)") "args(accountHolderNamePattern)")
public Object preProcessQueryPattern(ProceedingJoinPoint pjp, public Object preProcessQueryPattern(ProceedingJoinPoint pjp,
String accountHolderNamePattern) throws Throwable { String accountHolderNamePattern) throws Throwable {
@ -1624,7 +1624,7 @@ The following example shows how to do so:
.Kotlin .Kotlin
---- ----
@Around("execution(List<Account> find*(..)) && " + @Around("execution(List<Account> find*(..)) && " +
"com.xyz.myapp.SystemArchitecture.inDataAccessLayer() && " + "com.xyz.myapp.CommonPointcuts.inDataAccessLayer() && " +
"args(accountHolderNamePattern)") "args(accountHolderNamePattern)")
fun preProcessQueryPattern(pjp: ProceedingJoinPoint, fun preProcessQueryPattern(pjp: ProceedingJoinPoint,
accountHolderNamePattern: String): Any { accountHolderNamePattern: String): Any {
@ -1695,7 +1695,7 @@ the `UsageTracked` interface (to expose statistics via JMX for example):
@DeclareParents(value="com.xzy.myapp.service.*+", defaultImpl=DefaultUsageTracked.class) @DeclareParents(value="com.xzy.myapp.service.*+", defaultImpl=DefaultUsageTracked.class)
public static UsageTracked mixin; public static UsageTracked mixin;
@Before("com.xyz.myapp.SystemArchitecture.businessService() && this(usageTracked)") @Before("com.xyz.myapp.CommonPointcuts.businessService() && this(usageTracked)")
public void recordUsage(UsageTracked usageTracked) { public void recordUsage(UsageTracked usageTracked) {
usageTracked.incrementUseCount(); usageTracked.incrementUseCount();
} }
@ -1713,7 +1713,7 @@ the `UsageTracked` interface (to expose statistics via JMX for example):
lateinit var mixin: UsageTracked lateinit var mixin: UsageTracked
} }
@Before("com.xyz.myapp.SystemArchitecture.businessService() && this(usageTracked)") @Before("com.xyz.myapp.CommonPointcuts.businessService() && this(usageTracked)")
fun recordUsage(usageTracked: UsageTracked) { fun recordUsage(usageTracked: UsageTracked) {
usageTracked.incrementUseCount() usageTracked.incrementUseCount()
} }
@ -1757,12 +1757,12 @@ annotation. Consider the following example:
[source,java,indent=0,subs="verbatim,quotes",role="primary"] [source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java .Java
---- ----
@Aspect("perthis(com.xyz.myapp.SystemArchitecture.businessService())") @Aspect("perthis(com.xyz.myapp.CommonPointcuts.businessService())")
public class MyAspect { public class MyAspect {
private int someState; private int someState;
@Before("com.xyz.myapp.SystemArchitecture.businessService()") @Before("com.xyz.myapp.CommonPointcuts.businessService()")
public void recordServiceUsage() { public void recordServiceUsage() {
// ... // ...
} }
@ -1772,12 +1772,12 @@ annotation. Consider the following example:
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin .Kotlin
---- ----
@Aspect("perthis(com.xyz.myapp.SystemArchitecture.businessService())") @Aspect("perthis(com.xyz.myapp.CommonPointcuts.businessService())")
class MyAspect { class MyAspect {
private val someState: Int = 0 private val someState: Int = 0
@Before("com.xyz.myapp.SystemArchitecture.businessService()") @Before("com.xyz.myapp.CommonPointcuts.businessService()")
fun recordServiceUsage() { fun recordServiceUsage() {
// ... // ...
} }
@ -1841,7 +1841,7 @@ call `proceed` multiple times. The following listing shows the basic aspect impl
this.order = order; this.order = order;
} }
@Around("com.xyz.myapp.SystemArchitecture.businessService()") @Around("com.xyz.myapp.CommonPointcuts.businessService()")
public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable { public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
int numAttempts = 0; int numAttempts = 0;
PessimisticLockingFailureException lockFailureException; PessimisticLockingFailureException lockFailureException;
@ -1881,7 +1881,7 @@ call `proceed` multiple times. The following listing shows the basic aspect impl
this.order = order this.order = order
} }
@Around("com.xyz.myapp.SystemArchitecture.businessService()") @Around("com.xyz.myapp.CommonPointcuts.businessService()")
fun doConcurrentOperation(pjp: ProceedingJoinPoint): Any { fun doConcurrentOperation(pjp: ProceedingJoinPoint): Any {
var numAttempts = 0 var numAttempts = 0
var lockFailureException: PessimisticLockingFailureException var lockFailureException: PessimisticLockingFailureException
@ -1944,7 +1944,7 @@ expression so that only `@Idempotent` operations match, as follows:
[source,java,indent=0,subs="verbatim,quotes",role="primary"] [source,java,indent=0,subs="verbatim,quotes",role="primary"]
.Java .Java
---- ----
@Around("com.xyz.myapp.SystemArchitecture.businessService() && " + @Around("com.xyz.myapp.CommonPointcuts.businessService() && " +
"@annotation(com.xyz.myapp.service.Idempotent)") "@annotation(com.xyz.myapp.service.Idempotent)")
public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable { public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
// ... // ...
@ -1953,7 +1953,7 @@ expression so that only `@Idempotent` operations match, as follows:
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
.Kotlin .Kotlin
---- ----
@Around("com.xyz.myapp.SystemArchitecture.businessService() && " + @Around("com.xyz.myapp.CommonPointcuts.businessService() && " +
"@annotation(com.xyz.myapp.service.Idempotent)") "@annotation(com.xyz.myapp.service.Idempotent)")
fun doConcurrentOperation(pjp: ProceedingJoinPoint): Any { fun doConcurrentOperation(pjp: ProceedingJoinPoint): Any {
// ... // ...
@ -2048,12 +2048,12 @@ pointcut expression. Another way of defining the above pointcut would be as foll
<aop:config> <aop:config>
<aop:pointcut id="businessService" <aop:pointcut id="businessService"
expression="com.xyz.myapp.SystemArchitecture.businessService()"/> expression="com.xyz.myapp.CommonPointcuts.businessService()"/>
</aop:config> </aop:config>
---- ----
Assume that you have a `SystemArchitecture` aspect as described in <<aop-common-pointcuts>>. Assume that you have a `CommonPointcuts` aspect as described in <<aop-common-pointcuts>>.
Then declaring a pointcut inside an aspect is very similar to declaring a top-level pointcut, Then declaring a pointcut inside an aspect is very similar to declaring a top-level pointcut,
as the following example shows: as the following example shows:
@ -2617,7 +2617,7 @@ through JMX for example.)
default-impl="com.xyz.myapp.service.tracking.DefaultUsageTracked"/> default-impl="com.xyz.myapp.service.tracking.DefaultUsageTracked"/>
<aop:before <aop:before
pointcut="com.xyz.myapp.SystemArchitecture.businessService() pointcut="com.xyz.myapp.CommonPointcuts.businessService()
and this(usageTracked)" and this(usageTracked)"
method="recordUsage"/> method="recordUsage"/>
@ -3606,7 +3606,7 @@ fully qualified class names:
// the creation of a new bean (any object in the domain model) // the creation of a new bean (any object in the domain model)
protected pointcut beanCreation(Object beanInstance) : protected pointcut beanCreation(Object beanInstance) :
initialization(new(..)) && initialization(new(..)) &&
SystemArchitecture.inDomainModel() && CommonPointcuts.inDomainModel() &&
this(beanInstance); this(beanInstance);
} }
---- ----