-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Business Method Interceptor Methods
Signed-off-by: thadumi <th.theodor.th@gmail.com>
- Loading branch information
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
...pters/interceptor_programming_contract/business_method_interceptor_methods.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
//// | ||
******************************************************************* | ||
* Copyright (c) 2019 Eclipse Foundation | ||
* | ||
* This specification document is made available under the terms | ||
* of the Eclipse Foundation Specification License v1.0, which is | ||
* available at https://www.eclipse.org/legal/efsl.php. | ||
******************************************************************* | ||
//// | ||
|
||
[[business_method_interceptor_methods]] | ||
== Business Method Interceptor Methods | ||
|
||
image:intercept-4.png[image] | ||
|
||
Interceptor methods that interpose on | ||
business method invocations are denoted by the _AroundInvoke_ | ||
annotation. | ||
|
||
Around-invoke methods may be declared in | ||
interceptor classes, in the superclasses of interceptor classes, in the | ||
target class, and/or in superclasses of the target class. However, only | ||
one around-invoke method may be declared in a given class. | ||
|
||
Around-invoke methods can have _public_ , | ||
_private_ , _protected_ , or _package_ level access. An around-invoke | ||
method must not be declared as _abstract, final or static_ . | ||
|
||
Around-invoke methods have the following | ||
signature: | ||
|
||
_Object_ __ _<METHOD>(InvocationContext)_ | ||
|
||
Note: An around-invoke interceptor method may | ||
be declared to throw any checked exceptions that the associated target | ||
method allows within its throws clause. It may be declared to throw the | ||
java.lang.Exception, _for example, if it_ interposes on several methods | ||
that can throw unrelated checked exceptions. | ||
|
||
An around-invoke method can invoke any | ||
component or resource that the method it is intercepting can invoke. | ||
|
||
In general, an around-invoke method | ||
invocation occurs within the same transaction and security context as | ||
the method on which it is interposing. However, note that the | ||
transaction context may be changed by transactional interceptor methods | ||
in the invocation chain, such as those defined by the _Java Transaction | ||
API_ specification link:intercept.html#a547[See Jakarta Transaction (JTA) | ||
version 2.0. | ||
https://jakarta.ee/specifications/transactions/2.0/.] . | ||
|
||
The following example defines | ||
MonitoringInterceptor, which is used to interpose on ShoppingCart | ||
business methods: | ||
|
||
@Inherited | ||
|
||
@InterceptorBinding | ||
|
||
@Target(\{TYPE, METHOD}) @Retention(RUNTIME) | ||
|
||
public @interface Monitored \{} | ||
|
||
|
||
|
||
@Monitored @Interceptor | ||
|
||
public class MonitoringInterceptor \{ | ||
|
||
|
||
|
||
@AroundInvoke | ||
|
||
public Object | ||
monitorInvocation(InvocationContext ctx) \{ | ||
|
||
|
||
|
||
//... log invocation data ... | ||
|
||
|
||
|
||
return ctx.proceed(); | ||
|
||
} | ||
|
||
|
||
|
||
} | ||
|
||
|
||
|
||
@Monitored | ||
|
||
public class ShoppingCart \{ | ||
|
||
|
||
|
||
public void placeOrder(Order o) \{ | ||
|
||
... | ||
|
||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters