AOP 개념 및 Spring 의 AOP 기능. Spring Framework – AOP 절차적 프로그래밍 OOP AOP.

Slides:



Advertisements
Similar presentations
Spring Transaction & Spring AOP
Advertisements

AspectWerkz 2 - and the road to AspectJ 5 Jonas Bonér Senior Software Engineer BEA Systems.
Aspect Oriented Programming. AOP Contents 1 Overview 2 Terminology 3 The Problem 4 The Solution 4 Join point models 5 Implementation 6 Terminology Review.
1 JAC : Aspect Oriented Programming in Java An article review by Yuval Nir and Limor Lahiani.
Aspect Oriented Programming - AspectJ Radhika Rajput.
Secure Systems Research Group - FAU Aspect Oriented Programming Carlos Oviedo Secure Systems Research Group.
Taking into account meta-programming concerns in static program verification Julien Charles.
Spring AOP Aspect Oriented Programming
Aspect-Oriented Programming In Eclipse ® Aspect-Oriented Programming in Eclipse with AspectJ Dr Helen Hawkins and Sian January.
Aspect-Oriented Programming: An Overview Brandon Wirick Feb
More on AspectJ. aspect MoveTracking { private static boolean _flag = false; public static boolean testAndClear() { boolean result = _flag; _flag = false;
Introduction to Aspect- Oriented Programming CS 3360 Gregor Kiczales, et. al. Getting started with AspectJ, CACM, 44(10):59-65, October Fall 2012.
Outline Introduction Problem Statement Object-Oriented Design Aspect-Oriented Design Conclusion Demo.
MVC 패턴과 Spring.
SOAP 실전예제 Internet Computing KUT Youn-Hee Han.
Introduction to Aspect Oriented Programming Presented By: Kotaiah Choudary. Ravipati M.Tech IInd Year. School of Info. Tech.
Spring core v3.x Prepared by: Nhan Le. History v3.0 Spring Expression Language Java based bean metadata v3.1 Cache Abstraction Bean Definition Profile.
Modularizing Web Services Management with AOP María Agustina Cibrán, Bart Verheecke { Maria.Cibran, System and Software Engineering.
Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007.
A Distributed Aspect-Oriented System for J2EE Applications Muga Nishizawa and Shigeru Chiba (Tokyo Institute of Technology, Japan) Background - As benefits.
AOSD1 Aspect-Oriented Software Design Karl Lieberherr Theo Skotiniotis.
A Presentation By V AIBHAV S AHARAN Web-enHanced Information Management COMS E6125.
AOP-1 Aspect Oriented Programming. AOP-2 Aspects of AOP and Related Tools Limitation of OO Separation of Concerns Aspect Oriented programming AspectJ.
AspectWrapper CHALFOUN Pierre et BUIST Éric. Overview Introduction – what and why In a nutshell – main components Our approach – how we did it Demo –
1/43 고급자바프로그래밍 (ADVANCED JAVA PROGRAMMING) 강원대학교 컴퓨터학부 2012 년 가을학기 담당교수 정충교 1.
©2005 International.NET Association Asia Pacific WPF 둘러보기 이 수 겸 – kenial Microsoft ASP.Net MVP.
AspectJ – AOP for Java Tom Janofsky. Instructor at Penn State Abington Consultant with Chariot Solutions JUG Member.
Course Progress Lecture 1 –Java data binding: Basket example: UML class diagram -> class dictionary without tokens-> language design -> class dictionary.
Aspect Oriented Development Alex Beatty.  Purpose  Cross-cutting Concerns  Join Points, Pointcuts, and Advices  Weaving  Invasive vs. Non-Invasive.
Text 16 de mayo de 2009 Spring Framework Part III. Portable Service Abstractions Buenos Aires, June 2009.
Extending the Field Access Pointcuts of AspectJ to Arrays ICS 2006 – Taipei, December 2006 Kung Chen and Chin-Hung Chien* National Chengchi University.
Spring 프레임워크의 이해 4. Spring AOP 이해 및 활용 Grow up to be NHN 人 Spring – AOP 요구사항 !! 비즈니스 계층과 퍼시스턴스 계층의 모든 메써드 시작과 종료시 “ 메써드 시작 ”, “ 메써드 종료 ” 라는 Logging.
SnSDK Framework Software & System Development Kit 개발 노트 Ver. 2.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring AOP – Part 2 Advanced Aspect-Oriented.
Aspect Oriented Programming Adlux Consultancy Services Pvt Ltd
Kansas City Java User’s Group Jason W. Bedell July 12, 2006
问题 Code scattering Blocks of duplicated code Blocks of complementary code, and different modules implementing complementary parts of the concern Code.
Comparison of Different AOP Approaches Presented by: Xiaojing Wang.
AOSD'04, Lancaster, UK 1 Remote Pointcut - A Language Construct for Distributed AOP Muga Nishizawa (Tokyo Tech) Shigeru Chiba (Tokyo Tech) Michiaki Tatsubori.
A: A: double “4” A: “34” 4.
Introduction to Aspect- Oriented Programming CS 3360 Gregor Kiczales, et. al. Getting started with AspectJ, CACM, 44(10):59-65, October Spring 2012.
Text 16 de mayo de 2009 Spring Framework Part III. Portable Service Abstractions Buenos Aires, June 2009.
Spring Framework BT Team 25/02/ Spring A lightweight framework that addresses each tier in a Web application. Presentation layer – An MVC framework.
SCoPE: an AspectJ Compiler for Supporting User-Defined Analysis-Based Pointcuts Tomoyuki Aotani Hidehiko Masuhara
SnSDK Framework Software & System Development Kit 개발 노트 Ver. 1.2.
CHAP 14. 프로세스와 스레드. © 2012 생능출판사 All rights reserved 다중 스레딩 하나의 애플리케이션이 동시에 여러 가지 작업을 하 는 것 이들 작업은 스레드 (thread) 라고 불린다.
1 An AOP Implementation Framework for Extending Join Point Models Naoyasu Ubayashi(Kyushu Institute of Technology, Japan) Hidehiko Masuhara(University.
MVC 패턴과 Spring.
L’origine dei mali: le dipendenze tra componenti Stefano Leli 14° Workshop DotNetMarche Venerdì 16 aprile
Exception and Exception Handling. Exception An abnormal event that is likely to happen during program is execution Computer could run out of memory Calling.
PPL 2004, Gamagori, AICHI1 Remote Pointcut - A Language Construct for Distributed AOP Muga Nishizawa (Tokyo Tech, Japan) Shigeru Chiba (Tokyo Tech, Japan)
 Is a programming paradigm  Extends OOP  Enables modularization of cross cutting concerns.
Caching: An Optimization Aspect. Class Diagram for Base Item +name : String +check() : int Simple +weight : int +check() : int Container +capacity : int.
Leveraging ColdSpring to build a robust Flex applications Chris Scott, Cynergy Systems.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Chengyu Sun California State University, Los Angeles
Aspect-Oriented Programming with the Eclipse AspectJ plug-in
By Ru Shen Department of Computer Science UAlbany, 2008
Aspect-Oriented Programming
null, true, and false are also reserved.
ЕВОЛУЦИЈА СОФТВЕРА ПОДРЖАНА АСПЕКТНО-ОРИЈЕНТИСАНИМ ПРОГРАМИРАЊЕМ
Chengyu Sun California State University, Los Angeles
AOP in .NET Business Rules + Plumbing = Enterprise Software
Distributed Dynamic Weaving is a Crosscutting Concern
Java Decompiler.
CS520 Web Programming Spring – Aspect Oriented Programming
AspectAda Aspect-Oriented Programming for Ada95
Aspect Oriented Programming
Adaptive Programming in JAsCo
Presentation transcript:

AOP 개념 및 Spring 의 AOP 기능

Spring Framework – AOP 절차적 프로그래밍 OOP AOP

Spring Framework – AOP ??????? 다음 문제의 정답은 ?

Spring Framework – AOP 사고의 전환

Spring Framework - AOP 요구사항 !! MessageRenderer, MessageProvider 의 모든 메써드 시작과 종료시 “ MethodName 시작 ”, “ MethodName 종료 ” 라는 Logging 메시지를 출력한다.

Spring Framework - AOP

요구사항 변경 !! MessageRenderer, MessageProvider 의 모든 메써드 시작과 종료시 “ MethodName Start ”, “ MethodName End ” 라는 Logging 메시지를 출력한다.

Spring Framework - AOP 요구사항 변경 !! MessageRenderer, MessageProvider 의 모든 메써드 시작과 종료시 “ MethodName Start ”, “ MethodName End ” 라는 Logging 메시지를 출력한다. 메써드로 전달되는 인자를 Logging 메시지로 출력한다.

Spring Framework - AOP 삽질의 연속

Spring Framework - AOP

요구사항 !! 비즈니스 계층과 퍼시스턴스 계층의 모든 메써드 시작과 종료시 “ 메써드 시작 ”, “ 메써드 종료 ” 라는 Logging 메시지를 출력한다. 또한 메써드에 인자를 출력한다. Runtime Exception 이 발생할 경우 시스템 관리자에게 에러 메시지에 대한 메일을 발송한다.

Spring Framework – AOP

지금까지의 구현 방법 - UserServiceImpl public User findUser(String userId) throws UserNotFoundException { if (logger.isDebugEnabled()) { logger.debug("findUser() 시작 "); logger.debug("User ID : " + userId); } User user = userDAO.findUser(userId); if (user == null) { throw new UserNotFoundException(context.getMessage( "user.notfound.exception", new Object[] { userId }, null)); } if (logger.isDebugEnabled()) { logger.debug(userId + " 사용자 정보 : " + user); } if (logger.isDebugEnabled()) { logger.debug("findUser() 종료 "); } return user; }

Spring Framework – AOP AOP 를 이용한 해결 방법

AOP 적용 - UserServiceImpl public User findUser(String userId) throws UserNotFoundException { User user = userDAO.findUser(userId); if (user == null) { throw new UserNotFoundException(context.getMessage( "user.notfound.exception", new Object[] { userId }, null)); } if (logger.isDebugEnabled()) { logger.debug(userId + " 사용자 정보 : " + user); } return user; }

AOP 적용 – LoggingAdvice public class UserLoggingAdvice implements MethodInterceptor { protected final Log logger = LogFactory.getLog(getClass()); public Object invoke(MethodInvocation invocation) throws Throwable { String className = invocation.getThis().getClass().getName(); if (logger.isDebugEnabled()) { logger.debug(className + "." + invocation.getMethod().getName() + "()" + " 시작 !!"); Object[] args = invocation.getArguments(); if ((args != null) && (args.length > 0)) { for (int i = 0; i < args.length; i++) { logger.debug("Argument[" + i + "] : " + args[i]); } //Target 클래스의 메써드를 실행한다. Object retVal = invocation.proceed(); if (logger.isDebugEnabled()) { logger.debug(className + "." + invocation.getMethod().getName() + "()" + " 종료 !!"); } return retVal; }

Spring Framework – AOP

Logging Poincut public class LoggingPointcut extends StaticMethodMatcherPointcut { public boolean matches(Method method, Class cls) { if( "findUser".equals(method.getName()) ) { return true; } return false; } public ClassFilter getClassFilter() { return new ClassFilter() { public boolean matches(Class cls) { return (cls == UserServiceImpl.class) || (cls == MySQLUserDAO.class); } }; }

Spring Framework – AOP

Spring Framework - AOP

샘플 애플리케이션 개발 및 분석 (Spring 프레임워크 워크북 3 장 ) Spring Framework – AOP

프로그램이 실행되는 중 식별할 수 있는 Point. 예를 들어 메써드의 실행, Exception Handling 등이 포함된다. Join point

Spring Framework – AOP Join Point 에서 Aspect 에 의하여 실행되는 Action 을 의미 예를 들어 Logging Aspect 일 경우 Join Point 에서 Logging 하는 것을 의미한다. Advice

Spring Framework – AOP Before advice : Join Point 전에 실행되는 Advice. Around advice : Join Point 전, 후에 실행되는 Advice. After returning advice : Joint Point 완료된 후에 실행되는 Advice After throwing advice : Exception Throwing 이 될 때 실행되는 Advice After (finally) advice : After returning advice, After throwing advice 모든 경우에 실행 Advice 의 종류

Spring Framework – public void doAccessCheck() { //... } Before Advice

Spring Framework – pointcut="com.xyz.myapp.SystemArchitecture.dataAccessOperation()", returning="retVal") public void doAccessCheck(Object retVal) { //... } After Returning Advice

Spring Framework – pointcut="com.xyz.myapp.SystemArchitecture.dataAccessOperation()", throwing="ex") public void doRecoveryActions(DataAccessException ex) { //... } After Throwing Advice

Spring Framework – public void doReleaseLock() { //... } After (finally) Advice

Spring Framework – public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable { // start stopwatch Object retVal = pjp.proceed(); // stop stopwatch return retVal; } Around Advice

Spring Framework – AOP Join Point 들을 선택하는 규칙을 정의하는 것. Weaving Rule 을 정의하는 것 Pointcut

Spring Framework – AOP StaticMethodMatcherPointcut DynamicMethodMatcherPointcut Perl5RegexpMethodPointcut JdkRegexpMethodPointcut NameMatchMethodPointcut ComposablePointcut ControlFlowPointcut Pointcut 의 종류 – Spring 1.x

Spring Framework – AOP execution within this target args Pointcut 의 종류 – Spring 2.0

Spring Framework &&, ||, ! Pointcut 의 종류 – Spring 2.0

Spring Framework – AOP execution(* com.xyz.service.AccountService.*(..)) @args(com.xyz.security.Classified) Pointcut 의 예제 – Spring 2.0

Spring Framework – AOP 하나의 Crosscutting Concern 을 Aspect 로 정의 가능 Advice 와 Pointcut 이 결합되어 Aspect 가 된다. 예를 들어 Transaction, Security 등이 하나의 Aspect 가 된다. Aspect

Spring Framework – AOP 애플리케이션의 핵심 비즈니스 로직을 구현하고 있는 Object Aspect 에 의하여 Advice 가 적용되는 Object Target Object

Spring Framework – AOP Advcie, Pointcut, Target Object 로 분리된 것을 하나로 결합하는 것을 의미 Weaving 작업을 지원하는 Tool(AspectJ, Spring AOP) 을 Weaver 라 지칭 Weaving

Spring Framework - AOP AOP 를 적용하기 전의 소스 구조

Spring Framework - AOP AOP 를 적용 후

Spring Framework - AOP

요구사항 !! Runtime Exception 이 발생할 경우 시스템 관리자에게 에러 메시지에 대한 메일을 발송한다.

Spring Framework - AOP 요구사항 !! UserServiceImpl 의 updateUser() 는 “ admin ”, removeUser 는 “ admin ” 권한을 가진 사용자만 접근이 가능하도록 해라.

Spring Framework - AOP

AOP 적용 단계

AOP 를 DDD 에 적용

과제 요구사항 !! DAO 클래스의 메써드 실행속도가 500ms 이 넘을 경우 Warning 메시지를 출력한다.