- 浏览: 2542533 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
AspectJ(2)Language Introduction
Chapter 2. The AspectJ Language
2.1 The Anatomy of an Aspect
An Example Aspect
...snip...
Join Points and Pointcuts
After reading and study withincode demo, I begin to understand this key words. withincode, that means that be in this method of that class in this example.
PointTests.java:
package com.sillycat.easyaspectj;
import junit.framework.TestCase;
public class PointTests extends TestCase {
public static void main(String args[]) {
junit.swingui.TestRunner.run(PointTests.class);
}
public void testPointChange() {
Point sample = new Point(1, 1);
assertFalse(sample.isDirty());
sample.setX(5);
assertTrue(sample.isDirty());
sample.save();
assertFalse(sample.isDirty());
sample.setY(2);
assertFalse(sample.isDirty());
sample.save();
assertFalse(sample.isDirty());
}
}
My aspectj class AspectPoint.aj:
package com.sillycat.easyaspectj;
public aspect AspectPoint {
private boolean Point.isDirty = false;
public void Point.makeDirty() {
isDirty = true;
}
public boolean Point.isDirty() {
return isDirty;
}
public void Point.save() {
isDirty = false;
// add code to save point
}
pointcut fieldChanged(Point changed) :
set( private double Point.*) &&
target(changed) &&
!withincode( Point.new(..)) &&
withincode( void Point.setX(..));
after(Point changed ) : fieldChanged(changed) {
System.out.println("Make Dirty");
changed.makeDirty();
}
}
Point.java class is as follow:
public class Point {
private double x;
private double y;
private boolean isDirty = false;
Point(double x, double y) {
this.x = x;
this.y = y;
}
public void setX(double x) {
this.x = x;
isDirty = true;
}
public void setY(double y) {
this.y = y;
isDirty = true;
}
public void setPolarCoordinates(double theta, double r) {
x = r * Math.cos(theta);
y = r * Math.sin(theta);
isDirty = true;
}
...snip..
Some Example Pointcuts
When a particular method body executes: execution(void Point.setX(int))
When a method is called: call(void Point.setX(int))
When an exception handler executes: handler(ArrayOutOfBoundsException)
When the object currently executing is of type SomeType: this(SomeType)
When the target object is of type SomeType: target(SomeType)
When the executing code belongs to class MyClass: within(MyClass)
call VS. execution
Pointcut composition
Pointcut Parameters
Example: HandleLiveness
2.2. Advice
The around advice runs instead of the join point. The original action associated with the join point can be invoked through the special proceed call:
public void sayHello(String message){
System.out.println(message);
}
public static void main(String[] args) {
HelloWorld h = new HelloWorld();
h.sayHello(" study the aspectJ!");
h.sayHello(" study the spring roo!");
h.sayHello(" study the mw3!");
}
pointcut hello(HelloWorld h1, String hello):
target(h1) && args(hello) && (call (void say*(String)));
void around(HelloWorld h1,String hello): hello(h1, hello){
if(hello.indexOf("study") > 0){
System.out.print("Carl");
}
proceed(h1,hello);
}
2.3 Inter-type declarations
2.4 thisJoinPoint
System.out.print(thisJoinPoint.getSourceLocation() + ": ");
HelloWorld.java:11: Carl study the aspectJ!
references:
http://www.eclipse.org/aspectj/doc/released/progguide/language.html
http://sishuok.com/forum/posts/list/281.html
Chapter 2. The AspectJ Language
2.1 The Anatomy of an Aspect
An Example Aspect
...snip...
Join Points and Pointcuts
After reading and study withincode demo, I begin to understand this key words. withincode, that means that be in this method of that class in this example.
PointTests.java:
package com.sillycat.easyaspectj;
import junit.framework.TestCase;
public class PointTests extends TestCase {
public static void main(String args[]) {
junit.swingui.TestRunner.run(PointTests.class);
}
public void testPointChange() {
Point sample = new Point(1, 1);
assertFalse(sample.isDirty());
sample.setX(5);
assertTrue(sample.isDirty());
sample.save();
assertFalse(sample.isDirty());
sample.setY(2);
assertFalse(sample.isDirty());
sample.save();
assertFalse(sample.isDirty());
}
}
My aspectj class AspectPoint.aj:
package com.sillycat.easyaspectj;
public aspect AspectPoint {
private boolean Point.isDirty = false;
public void Point.makeDirty() {
isDirty = true;
}
public boolean Point.isDirty() {
return isDirty;
}
public void Point.save() {
isDirty = false;
// add code to save point
}
pointcut fieldChanged(Point changed) :
set( private double Point.*) &&
target(changed) &&
!withincode( Point.new(..)) &&
withincode( void Point.setX(..));
after(Point changed ) : fieldChanged(changed) {
System.out.println("Make Dirty");
changed.makeDirty();
}
}
Point.java class is as follow:
public class Point {
private double x;
private double y;
private boolean isDirty = false;
Point(double x, double y) {
this.x = x;
this.y = y;
}
public void setX(double x) {
this.x = x;
isDirty = true;
}
public void setY(double y) {
this.y = y;
isDirty = true;
}
public void setPolarCoordinates(double theta, double r) {
x = r * Math.cos(theta);
y = r * Math.sin(theta);
isDirty = true;
}
...snip..
Some Example Pointcuts
When a particular method body executes: execution(void Point.setX(int))
When a method is called: call(void Point.setX(int))
When an exception handler executes: handler(ArrayOutOfBoundsException)
When the object currently executing is of type SomeType: this(SomeType)
When the target object is of type SomeType: target(SomeType)
When the executing code belongs to class MyClass: within(MyClass)
call VS. execution
Pointcut composition
Pointcut Parameters
Example: HandleLiveness
2.2. Advice
The around advice runs instead of the join point. The original action associated with the join point can be invoked through the special proceed call:
public void sayHello(String message){
System.out.println(message);
}
public static void main(String[] args) {
HelloWorld h = new HelloWorld();
h.sayHello(" study the aspectJ!");
h.sayHello(" study the spring roo!");
h.sayHello(" study the mw3!");
}
pointcut hello(HelloWorld h1, String hello):
target(h1) && args(hello) && (call (void say*(String)));
void around(HelloWorld h1,String hello): hello(h1, hello){
if(hello.indexOf("study") > 0){
System.out.print("Carl");
}
proceed(h1,hello);
}
2.3 Inter-type declarations
2.4 thisJoinPoint
System.out.print(thisJoinPoint.getSourceLocation() + ": ");
HelloWorld.java:11: Carl study the aspectJ!
references:
http://www.eclipse.org/aspectj/doc/released/progguide/language.html
http://sishuok.com/forum/posts/list/281.html
发表评论
-
NodeJS12 and Zlib
2020-04-01 07:44 468NodeJS12 and Zlib It works as ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 330Traefik 2020(1)Introduction and ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 428Private Registry 2020(1)No auth ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 377Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 468NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 414Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 332Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 243GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 445GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 321GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 307Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 310Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 286Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 303Serverless with NodeJS and Tenc ... -
NodeJS MySQL Library and npmjs
2020-02-07 06:21 282NodeJS MySQL Library and npmjs ... -
Python Library 2019(1)requests and aiohttp
2019-12-18 01:12 257Python Library 2019(1)requests ... -
NodeJS Installation 2019
2019-10-20 02:57 565NodeJS Installation 2019 Insta ... -
Monitor Tool 2019(2)Monit on Multiple Instances and Email Alerts
2019-10-18 10:57 257Monitor Tool 2019(2)Monit on Mu ... -
Sqlite Database 2019(1)Sqlite3 Installation and Docker phpsqliteadmin
2019-09-05 11:24 362Sqlite Database 2019(1)Sqlite3 ... -
Supervisor 2019(2)Ubuntu and Multiple Services
2019-08-19 10:53 366Supervisor 2019(2)Ubuntu and Mu ...
相关推荐
This book is an introduction to AOP with AspectJ and Eclipse and shows how to create a productive AO development environment by using the AspectJ Development Tools for Eclipse (AJDT). Tools have an ...
2. **AspectJ语法**: AspectJ提供了强大的语法结构,包括`pointcut`(切点)、`advice`(通知)和`join point`(连接点)。切点定义了代码执行的特定位置,通知是在这些位置执行的代码,而连接点则是实际触发通知的...
2. **通知(Advice)**:这是切面实际执行的代码,会在特定的时间点(切点)被触发。AspectJ提供了五种不同类型的通知:前置通知(before)、后置通知(after)、返回后通知(after returning)、异常后通知(after ...
5. **强大的切点表达式**:AspectJ的切点表达式语言(Pointcut Expression Language, PEL)允许精确地指定切点,可以根据包名、类名、方法名、参数类型等条件进行匹配。 6. **编织增强(Advising Enhancements)**...
### AspectJ in Action 第二版:企业级AOP与Spring应用深入解析 #### 知识点一:AspectJ概述及特点 - **AspectJ简介**:AspectJ是一种面向切面编程(AOP)语言,它扩展了Java语言,提供了一种更强大的方式来处理...
2. 配置织入:有两类织入方式:编译时织入和运行时织入。编译时织入需要使用AspectJ的编译器ajc,而运行时织入则在应用启动时由Spring自动处理。两种方式都需要在Spring配置中指定启用AspectJ自动代理。 3. 定义切...
2. **通知(Advice)**:通知是切点发生时执行的代码,它可以是在方法调用之前、之后或环绕方法执行。AspectJ提供了不同类型的通知,包括前置通知(Before)、后置通知(After)、返回通知(After Returning)、异常...
2. 通知类型:包括前置通知(before)、后置通知(after)、返回通知(after returning)、异常通知(after throwing)和环绕通知(around advice)。 3. 切点表达式:用于指定通知何时执行的语法规则,可以基于方法...
aspectj-1.7.0.jar aspectj的包
2. **语法支持**:AspectJ 提供了自己的扩展语言,称为AspectJ语言(AJ),它扩展了Java语法,允许开发者声明切面、切入点和通知。 3. **API**:`aspectj-1.6.9.jar` 包含了AspectJ的API,开发者可以通过这些API在...
2. `aspectjrt-1.5.0.jar`:AspectJ运行时库,包含了执行AspectJ代码所必需的类和接口。它提供了运行时支持,如AOP代理、切面实例化以及通知的执行等。这个库是运行AspectJ应用程序的基础,确保了切面可以在运行时...
2. **配置文件**:如Spring的XML配置文件,用于启用AspectJ自动代理。 3. **测试类**:演示如何在实际应用中触发切面逻辑。 通过运行这个示例,你可以观察到切面如何在方法调用前后插入额外的逻辑,如打印日志,而...
Eclipse AspectJ: Aspect Oriented Programming with AspectJ and the Eclipse ADT
【标题】"org.aspectj,aspectj项目库(org.aspectj).zip" 提供的是开源项目AspectJ的源码库。AspectJ是一种强大的面向切面编程(AOP)框架,它扩展了Java语言,允许程序员以声明式方式处理系统的横切关注点,如日志...
3. **切点表达式**:AspectJ的切点表达式语言(Pointcut Expression Language, PEL)允许精确地定义切点,例如通过方法签名、类名或注解来匹配代码位置。 4. **通知类型**:包括前通知(Before)、后通知(After)、...
2. **连接点(Join Point)**:程序执行中的特定点,如方法调用、异常抛出等。 3. **通知(Advice)**:在特定连接点执行的代码,也就是切面的行为部分。 4. **切入点(Pointcut)**:定义一组连接点的规则,用于确定哪些...
2. 使用开源的 AspectJ plugin 依赖库进行集成开发,例如使用 HujiangTechnology/gradle_plugin_android_aspectj 依赖库。 3. 自己配置 Gradle 文件,例如使用 GitHub 上面的参考功能。 三、AspectJ 的应用场景 ...
2. `lib`目录:可能包含AspectJ的库文件,如`aspectjrt.jar`和`aspectjweaver.jar`。 3. `build.xml`或`pom.xml`:构建脚本,用于编译和运行程序,可能使用Ant或Maven。 4. `README.md`或`Readme.txt`:项目说明,...
2. **切面和通知**:详细解释如何定义切面,以及如何在切面中编写通知。通知是在特定连接点执行的代码,可以是前置通知(before advice)、后置通知(after advice)、环绕通知(around advice)等。 3. **切点...