Más contenido relacionado Similar a Practical Example of AOP with AspectJ (20) Más de Yegor Bugayenko (20) Practical Example of AOP with AspectJ3. /20@yegor256 3
class Page {
public String html() {
// load HTML and return
}
}
class Directory {
public void delete() {
// remove all files
}
}
class File {
public long length() {
// return file size
}
}
8. /20@yegor256 8
@Aspect
class Robustness {
@Around("execution(* *(..)) && @annotation(Retry)")
public Object around(ProceedingJoinPoint point) {
while (true) {
try {
return point.proceed();
} catch (Exception ex) {
// just ignore it
}
}
}
}
9. /20@yegor256 9
class Page {
@Retry
public String html() {
// load HTML and return
}
}
@Aspect
class Robustness {
@Around(“…”)
public Object around(point) {
while (true) {
try {
return point.proceed();
} catch (Exception ex) {
// just ignore it
}
}
}
}
Page.class
Robustness.class
11. /20@yegor256 11
class Page {
private Robustness r;
public String html() {
return this.r.around(point);
}
public String html_aroundBody() {
// load HTML and return
}
}
@Aspect
class Robustness {
@Around(“…”)
public Object around(point) {
while (true) {
try {
return point.proceed();
} catch (Exception ex) {
// just ignore it
}
}
}
}
Page.class
Robustness.class
16. /20@yegor256 16
@Aspect
class Robustness {
@Around("execution(* *(..)) && @annotation(Retry)")
public Object around(ProceedingJoinPoint point) {
while (true) {
try {
return point.proceed();
} catch (Exception ex) {
// just ignore it
}
}
}
}
17. /20@yegor256 17
class RobustPage {
private final Page page;
public String html() {
while (true) {
try {
return this.page.html();
} catch (Exception ex) {
// ignore
}
}
}
}
21. /20@yegor256 21
class Page {
public String html() around retry() {
// load HTML and return
}
advice Object retry() {
while (true) {
try {
return proceed;
} catch (Exception ex) {
// ignore
}
}
}
}
23. /20@yegor256 23
page = new Robust<Page>(new Page()) {
@Override
public String html() around retry() {
return origin.html();
}
}