SlideShare una empresa de Scribd logo
1 de 32
Introducción a AspectJ Mauricio Quezada 07/01/11
Lo que queremos publicImportantcomplexMethod() {// applicationlogiconly returnanImportantResult;   }
Como es en realidad… publicImportantcomplexMethod() {	LOG.log(“Enteringthemethod..”); // complexlogic... mutex.lock(); // more complexlogic... cipher.encrypt(message); // ... Connection con = getConnection(); // ... returnanImportantResult;   }
Aspectos Modularizancross-cuttingconcerns
Aspectos Modularizancross-cuttingconcerns Logging, seguridad, sincronización, control de acceso …
Aspectos Modularizancross-cuttingconcerns Logging, seguridad, sincronización, control de acceso … before(): call(complexMethod(..))     { 	  LOG.log(“Callingtehmethod”);   }
AspectJ Lenguaje orientado a aspectos para Java Define su propio Join Point Model: Joinpoints + pointcuts + advices = aspect
¿Qué es el Join Point Model? Es el modelo que define cuáles son los: JoinPoints: Puntos de ejecución Ej. Llamada de un método, lanzamiento de una excepción Pointcut: Predicados que “atrapan” a los joinpoints Ej. Llamar al método foo(), lanzar una excepción de tipo Exception Advice: Acción a realizar dado un pointcut
En AspectJ pointcutmove(): call(publicvoidFigureElement.setXY(int,int)); before(): move() { System.out.println(“abouttomove”); } after(): move() {  System.out.println(“moved”); }
Wildcards *Account= UserAccount, AdminAccount, ... java.*.Date = java.util.Date, java.sql.Date, ... javax..*Model+ = TableModel + subclasses+ TreeModel + subclasses + ...
Pointcuts call(publicvoidAccount.*(int)); call(* *.*(int)) ||call(* *.*(double)); execution(public !final * *.*(..))  &&within(Dao+);
Pointcuts pointcutcreditOp(Accountacc, floatamt) :call (voidAccount.credit(float)) && target (acc) && args (amt); pointcut creditOp2(Accountacc, floatamt) : execution (voidAccount.credit(float)) && this(acc) 	&& args (amt);
Advices before(): call(* Account.*(..)) { ... } after(): call(...) { ... } Objectaround(): move() { // ... Objectret = proceed(); // ... returnret; }
Sí capitán, estamos listos! Ejemplos
Log abstractaspect Log { abstractpointcutmyClass(); pointcutmyConstr(): myClass() && execution(new(..)); pointcutmyMethod(): myClass() && execution(* *(..));
Log (2) after() throwing (Error e): myMethod() { LOG.getInstance().write(e); } before(): myConstr() { LOG.getInstance().write		(“Creatingobject”); } }
Log (3) publicaspectLogMyClassesextends Log { pointcutmyClass(): within( Account ) || within( Dao+ ) || within( Controller ); }
TimerLog publicabstractaspectTimerLog { abstractpointcutmyMethod(); before(): myMethod () { Timer.start(); System.out.println( 		“Timerstarted at “ + t.startTime); 	} }
Transparent RMI public interface Receiver extendsRemote { publicvoidreceive(Stringname, Object[] params) 	throwsRemoteException; } abstractaspectTransparentRMI { abstractpointcutmyInterceptedClass(); pointcutclientCall(Object[] arg): myInterceptedClass()  		&& execution(void *.*(..))  		&& args(arg);
Transparent RMI (2) voidaround(Object[] arg): clientCall(arg) { 	Receiver r = null; 	r = (Receiver) Naming.lookup(“rmi://...”); r.receive( thisJoinPoint.getSignature().getName(), arg);  } }
Access Control aspectIdentificationperthis(this(Client)) { publicSubjectsubject = null; } aspectAuthenticationpercflow(serviceRequest()) { privateSubjectsubject; pointcutserviceRequest(): call(* ServerInterface+.service(..));
Access Control (2) pointcutauthenticationCall(Objectcaller): this(caller) && serviceRequest() && if(Identification.hasAspect(caller)); publicSubjectgetSubject() { returnsubject; 	}
Access Control (3) before(Objectcaller): authenticationCall(caller) { Identification id = 				  		Identification.aspectOf(caller); if(id.subject == null) { // askforlogin subject = id.subject; } else { throwanException; 	} 	} }
Access Control (4) aspectAuthorization { pointcutcheckedMethods(): within(Server) &&execution(* service(..)); Objectaround(): checkedMethods() { Authenticationauth = Authen.aspectOf(); Subjectsubject = auth.getSubject(); if(checkForPermission) returnproceed();} }
Inter-Typedeclarations declare parents: banking.entities* implementsIdentifiable; declare warning: : get(public !final *.*) || set(public *.*) : “Should use a getteror setter method”;
Cache publicabstractaspect Cache {Map _cache = new HashMap();abstractpointcutcacheMe(Object o);Objectaround(Object o): cacheMe(o) {ObjectinCache = _cache.get(o);if(inCache == null) {inCache = proceed(o);		_cache.put(o, inCache); 	}returninCache;} }
Pero yo no programo en Java…
Pero yo no programo en Java… <script type=“text/javascript”> varpointcut = AspectScript.Pointcuts.call(foo); varadvice = function() {  alert("Callingfoo");  	}; AspectScript.before(pointcut, advice); </script>
Pero yo no programo en Java… require ‘aquarium’ classAccount includeAquarium::DSL before :calls_to=> [:credit, :debit] br />		do |join_point, object, *args| object.balance= read_from_database… end
Otras implementaciones de aspectos AspectC / AspectC++ AspectScript* (Javascript) Aquarium (Ruby) MetaclassTalk (Smalltalk) Spring AOP JBoss AOP etc * hecho en Chile
Conclusiones Los aspectos permiten modularizarcross-cuttingconcerns AspectJ es un lenguaje bastante expresivo, pero limitado Muy útiles en ambientes de desarrollo
Referencias AspectJ Project http://www.eclipse.org/aspectj/ AJDT (Eclipse plugin) http://www.eclipse.org/ajdt/ Slides de CC71P – Objetos y Aspectos http://pleiad.dcc.uchile.cl/teaching/cc71p Howaspectorientedprogramming can helptobuildsecure software http://people.cs.kuleuven.be/~bart.dedecker/pubs/aspects.pdf AspectScripthttp://www.pleiad.cl/aspectscript/ Mis tareas de CC71P :-P

Más contenido relacionado

La actualidad más candente

Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Vincenzo Iozzo
 
Java synchronizers
Java synchronizersJava synchronizers
Java synchronizersts_v_murthy
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Ismar Silveira
 
A Layered Architecture for the Model-driven Development of Distributed Simula...
A Layered Architecture for the Model-driven Development of Distributed Simula...A Layered Architecture for the Model-driven Development of Distributed Simula...
A Layered Architecture for the Model-driven Development of Distributed Simula...Daniele Gianni
 
Qt Memory Management & Signal and Slots
Qt Memory Management & Signal and SlotsQt Memory Management & Signal and Slots
Qt Memory Management & Signal and SlotsJussi Pohjolainen
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency GotchasAlex Miller
 
Grand Central Dispatch in Objective-C
Grand Central Dispatch in Objective-CGrand Central Dispatch in Objective-C
Grand Central Dispatch in Objective-CPavel Albitsky
 
Lexical environment in ecma 262 5
Lexical environment in ecma 262 5Lexical environment in ecma 262 5
Lexical environment in ecma 262 5Kim Hunmin
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleThierry Wasylczenko
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewPaulo Morgado
 
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...Iosif Itkin
 
Writing more complex models (continued)
Writing more complex models (continued)Writing more complex models (continued)
Writing more complex models (continued)Mohamed Samy
 
Multi client
Multi clientMulti client
Multi clientganteng8
 
Heap overflows for humans – 101
Heap overflows for humans – 101Heap overflows for humans – 101
Heap overflows for humans – 101Craft Symbol
 
Коварный code type ITGM #9
Коварный code type ITGM #9Коварный code type ITGM #9
Коварный code type ITGM #9Andrey Zakharevich
 

La actualidad más candente (20)

Computer networkppt4577
Computer networkppt4577Computer networkppt4577
Computer networkppt4577
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
 
Java synchronizers
Java synchronizersJava synchronizers
Java synchronizers
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
A Layered Architecture for the Model-driven Development of Distributed Simula...
A Layered Architecture for the Model-driven Development of Distributed Simula...A Layered Architecture for the Model-driven Development of Distributed Simula...
A Layered Architecture for the Model-driven Development of Distributed Simula...
 
02 - Basics of Qt
02 - Basics of Qt02 - Basics of Qt
02 - Basics of Qt
 
#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG
 
Qt Memory Management & Signal and Slots
Qt Memory Management & Signal and SlotsQt Memory Management & Signal and Slots
Qt Memory Management & Signal and Slots
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
 
Grand Central Dispatch in Objective-C
Grand Central Dispatch in Objective-CGrand Central Dispatch in Objective-C
Grand Central Dispatch in Objective-C
 
Lexical environment in ecma 262 5
Lexical environment in ecma 262 5Lexical environment in ecma 262 5
Lexical environment in ecma 262 5
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 preview
 
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
 
Writing more complex models (continued)
Writing more complex models (continued)Writing more complex models (continued)
Writing more complex models (continued)
 
Play image
Play imagePlay image
Play image
 
14 thread
14 thread14 thread
14 thread
 
Multi client
Multi clientMulti client
Multi client
 
Heap overflows for humans – 101
Heap overflows for humans – 101Heap overflows for humans – 101
Heap overflows for humans – 101
 
Коварный code type ITGM #9
Коварный code type ITGM #9Коварный code type ITGM #9
Коварный code type ITGM #9
 

Similar a Introduccion a AspectJ

Introdução à programação orientada para aspectos
Introdução à programação orientada para aspectosIntrodução à programação orientada para aspectos
Introdução à programação orientada para aspectosManuel Menezes de Sequeira
 
Step-by-step Development of an Application for the Java Card Connected Platform
Step-by-step Development of an Application for the Java Card Connected PlatformStep-by-step Development of an Application for the Java Card Connected Platform
Step-by-step Development of an Application for the Java Card Connected PlatformEric Vétillard
 
Resiliency & Security_Ballerina Day CMB 2018
Resiliency & Security_Ballerina Day CMB 2018  Resiliency & Security_Ballerina Day CMB 2018
Resiliency & Security_Ballerina Day CMB 2018 Ballerina
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Juan Pablo
 
Paradigmas de linguagens de programacao - aula#9
Paradigmas de linguagens de programacao - aula#9Paradigmas de linguagens de programacao - aula#9
Paradigmas de linguagens de programacao - aula#9Ismar Silveira
 
Java remote method invocation
Java remote method invocationJava remote method invocation
Java remote method invocationVan Dawn
 
JDD 2016 - Michał Balinski, Oleksandr Goldobin - Practical Non Blocking Micro...
JDD 2016 - Michał Balinski, Oleksandr Goldobin - Practical Non Blocking Micro...JDD 2016 - Michał Balinski, Oleksandr Goldobin - Practical Non Blocking Micro...
JDD 2016 - Michał Balinski, Oleksandr Goldobin - Practical Non Blocking Micro...PROIDEA
 
.NET Fest 2017. Михаил Щербаков. Механизмы предотвращения атак в ASP.NET Core
.NET Fest 2017. Михаил Щербаков. Механизмы предотвращения атак в ASP.NET Core.NET Fest 2017. Михаил Щербаков. Механизмы предотвращения атак в ASP.NET Core
.NET Fest 2017. Михаил Щербаков. Механизмы предотвращения атак в ASP.NET CoreNETFest
 
Modern C++ Concurrency API
Modern C++ Concurrency APIModern C++ Concurrency API
Modern C++ Concurrency APISeok-joon Yun
 
Architecture Patterns in Practice with Kotlin. UA Mobile 2017.
Architecture Patterns in Practice with Kotlin. UA Mobile 2017.Architecture Patterns in Practice with Kotlin. UA Mobile 2017.
Architecture Patterns in Practice with Kotlin. UA Mobile 2017.UA Mobile
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy codeShriKant Vashishtha
 
Job Managment Portlet
Job Managment PortletJob Managment Portlet
Job Managment Portletriround
 
Transaction Management Tool
Transaction Management ToolTransaction Management Tool
Transaction Management ToolPeeyush Ranjan
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesAnkit Rastogi
 
Add an interactive command line to your C++ application
Add an interactive command line to your C++ applicationAdd an interactive command line to your C++ application
Add an interactive command line to your C++ applicationDaniele Pallastrelli
 
Informatica_MDM_User_Exits.ppt
Informatica_MDM_User_Exits.pptInformatica_MDM_User_Exits.ppt
Informatica_MDM_User_Exits.pptDurganandYedlapati
 

Similar a Introduccion a AspectJ (20)

Jersey Guice AOP
Jersey Guice AOPJersey Guice AOP
Jersey Guice AOP
 
Introdução à programação orientada para aspectos
Introdução à programação orientada para aspectosIntrodução à programação orientada para aspectos
Introdução à programação orientada para aspectos
 
Step-by-step Development of an Application for the Java Card Connected Platform
Step-by-step Development of an Application for the Java Card Connected PlatformStep-by-step Development of an Application for the Java Card Connected Platform
Step-by-step Development of an Application for the Java Card Connected Platform
 
Resiliency & Security_Ballerina Day CMB 2018
Resiliency & Security_Ballerina Day CMB 2018  Resiliency & Security_Ballerina Day CMB 2018
Resiliency & Security_Ballerina Day CMB 2018
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
 
Anti patterns
Anti patternsAnti patterns
Anti patterns
 
Paradigmas de linguagens de programacao - aula#9
Paradigmas de linguagens de programacao - aula#9Paradigmas de linguagens de programacao - aula#9
Paradigmas de linguagens de programacao - aula#9
 
Java remote method invocation
Java remote method invocationJava remote method invocation
Java remote method invocation
 
JDD 2016 - Michał Balinski, Oleksandr Goldobin - Practical Non Blocking Micro...
JDD 2016 - Michał Balinski, Oleksandr Goldobin - Practical Non Blocking Micro...JDD 2016 - Michał Balinski, Oleksandr Goldobin - Practical Non Blocking Micro...
JDD 2016 - Michał Balinski, Oleksandr Goldobin - Practical Non Blocking Micro...
 
.NET Fest 2017. Михаил Щербаков. Механизмы предотвращения атак в ASP.NET Core
.NET Fest 2017. Михаил Щербаков. Механизмы предотвращения атак в ASP.NET Core.NET Fest 2017. Михаил Щербаков. Механизмы предотвращения атак в ASP.NET Core
.NET Fest 2017. Михаил Щербаков. Механизмы предотвращения атак в ASP.NET Core
 
Modern C++ Concurrency API
Modern C++ Concurrency APIModern C++ Concurrency API
Modern C++ Concurrency API
 
Architecture Patterns in Practice with Kotlin. UA Mobile 2017.
Architecture Patterns in Practice with Kotlin. UA Mobile 2017.Architecture Patterns in Practice with Kotlin. UA Mobile 2017.
Architecture Patterns in Practice with Kotlin. UA Mobile 2017.
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy code
 
Java rmi
Java rmiJava rmi
Java rmi
 
Job Managment Portlet
Job Managment PortletJob Managment Portlet
Job Managment Portlet
 
Transaction Management Tool
Transaction Management ToolTransaction Management Tool
Transaction Management Tool
 
Java RMI
Java RMIJava RMI
Java RMI
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
Add an interactive command line to your C++ application
Add an interactive command line to your C++ applicationAdd an interactive command line to your C++ application
Add an interactive command line to your C++ application
 
Informatica_MDM_User_Exits.ppt
Informatica_MDM_User_Exits.pptInformatica_MDM_User_Exits.ppt
Informatica_MDM_User_Exits.ppt
 

Más de Mauricio Quezada

Línea de tiempo Movimiento Estudiantil 2011
Línea de tiempo Movimiento Estudiantil 2011Línea de tiempo Movimiento Estudiantil 2011
Línea de tiempo Movimiento Estudiantil 2011Mauricio Quezada
 
Proofs of Partial Knowledge and Simplified Design of Witness Hiding Protocols
Proofs of Partial Knowledge and Simplified Design of Witness Hiding ProtocolsProofs of Partial Knowledge and Simplified Design of Witness Hiding Protocols
Proofs of Partial Knowledge and Simplified Design of Witness Hiding ProtocolsMauricio Quezada
 
Monitorizando aplicaciones con AspectJ
Monitorizando aplicaciones con AspectJMonitorizando aplicaciones con AspectJ
Monitorizando aplicaciones con AspectJMauricio Quezada
 
Criptografía y Teoría de Juegos
Criptografía y Teoría de JuegosCriptografía y Teoría de Juegos
Criptografía y Teoría de JuegosMauricio Quezada
 
Cómo compartir un Secreto
Cómo compartir un SecretoCómo compartir un Secreto
Cómo compartir un SecretoMauricio Quezada
 

Más de Mauricio Quezada (6)

Línea de tiempo Movimiento Estudiantil 2011
Línea de tiempo Movimiento Estudiantil 2011Línea de tiempo Movimiento Estudiantil 2011
Línea de tiempo Movimiento Estudiantil 2011
 
Aspectos y seguridad
Aspectos y seguridadAspectos y seguridad
Aspectos y seguridad
 
Proofs of Partial Knowledge and Simplified Design of Witness Hiding Protocols
Proofs of Partial Knowledge and Simplified Design of Witness Hiding ProtocolsProofs of Partial Knowledge and Simplified Design of Witness Hiding Protocols
Proofs of Partial Knowledge and Simplified Design of Witness Hiding Protocols
 
Monitorizando aplicaciones con AspectJ
Monitorizando aplicaciones con AspectJMonitorizando aplicaciones con AspectJ
Monitorizando aplicaciones con AspectJ
 
Criptografía y Teoría de Juegos
Criptografía y Teoría de JuegosCriptografía y Teoría de Juegos
Criptografía y Teoría de Juegos
 
Cómo compartir un Secreto
Cómo compartir un SecretoCómo compartir un Secreto
Cómo compartir un Secreto
 

Último

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 

Último (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 

Introduccion a AspectJ

  • 1. Introducción a AspectJ Mauricio Quezada 07/01/11
  • 2. Lo que queremos publicImportantcomplexMethod() {// applicationlogiconly returnanImportantResult; }
  • 3. Como es en realidad… publicImportantcomplexMethod() { LOG.log(“Enteringthemethod..”); // complexlogic... mutex.lock(); // more complexlogic... cipher.encrypt(message); // ... Connection con = getConnection(); // ... returnanImportantResult; }
  • 5. Aspectos Modularizancross-cuttingconcerns Logging, seguridad, sincronización, control de acceso …
  • 6. Aspectos Modularizancross-cuttingconcerns Logging, seguridad, sincronización, control de acceso … before(): call(complexMethod(..)) { LOG.log(“Callingtehmethod”); }
  • 7. AspectJ Lenguaje orientado a aspectos para Java Define su propio Join Point Model: Joinpoints + pointcuts + advices = aspect
  • 8. ¿Qué es el Join Point Model? Es el modelo que define cuáles son los: JoinPoints: Puntos de ejecución Ej. Llamada de un método, lanzamiento de una excepción Pointcut: Predicados que “atrapan” a los joinpoints Ej. Llamar al método foo(), lanzar una excepción de tipo Exception Advice: Acción a realizar dado un pointcut
  • 9. En AspectJ pointcutmove(): call(publicvoidFigureElement.setXY(int,int)); before(): move() { System.out.println(“abouttomove”); } after(): move() { System.out.println(“moved”); }
  • 10. Wildcards *Account= UserAccount, AdminAccount, ... java.*.Date = java.util.Date, java.sql.Date, ... javax..*Model+ = TableModel + subclasses+ TreeModel + subclasses + ...
  • 11. Pointcuts call(publicvoidAccount.*(int)); call(* *.*(int)) ||call(* *.*(double)); execution(public !final * *.*(..)) &&within(Dao+);
  • 12. Pointcuts pointcutcreditOp(Accountacc, floatamt) :call (voidAccount.credit(float)) && target (acc) && args (amt); pointcut creditOp2(Accountacc, floatamt) : execution (voidAccount.credit(float)) && this(acc) && args (amt);
  • 13. Advices before(): call(* Account.*(..)) { ... } after(): call(...) { ... } Objectaround(): move() { // ... Objectret = proceed(); // ... returnret; }
  • 14. Sí capitán, estamos listos! Ejemplos
  • 15. Log abstractaspect Log { abstractpointcutmyClass(); pointcutmyConstr(): myClass() && execution(new(..)); pointcutmyMethod(): myClass() && execution(* *(..));
  • 16. Log (2) after() throwing (Error e): myMethod() { LOG.getInstance().write(e); } before(): myConstr() { LOG.getInstance().write (“Creatingobject”); } }
  • 17. Log (3) publicaspectLogMyClassesextends Log { pointcutmyClass(): within( Account ) || within( Dao+ ) || within( Controller ); }
  • 18. TimerLog publicabstractaspectTimerLog { abstractpointcutmyMethod(); before(): myMethod () { Timer.start(); System.out.println( “Timerstarted at “ + t.startTime); } }
  • 19. Transparent RMI public interface Receiver extendsRemote { publicvoidreceive(Stringname, Object[] params) throwsRemoteException; } abstractaspectTransparentRMI { abstractpointcutmyInterceptedClass(); pointcutclientCall(Object[] arg): myInterceptedClass() && execution(void *.*(..)) && args(arg);
  • 20. Transparent RMI (2) voidaround(Object[] arg): clientCall(arg) { Receiver r = null; r = (Receiver) Naming.lookup(“rmi://...”); r.receive( thisJoinPoint.getSignature().getName(), arg); } }
  • 21. Access Control aspectIdentificationperthis(this(Client)) { publicSubjectsubject = null; } aspectAuthenticationpercflow(serviceRequest()) { privateSubjectsubject; pointcutserviceRequest(): call(* ServerInterface+.service(..));
  • 22. Access Control (2) pointcutauthenticationCall(Objectcaller): this(caller) && serviceRequest() && if(Identification.hasAspect(caller)); publicSubjectgetSubject() { returnsubject; }
  • 23. Access Control (3) before(Objectcaller): authenticationCall(caller) { Identification id = Identification.aspectOf(caller); if(id.subject == null) { // askforlogin subject = id.subject; } else { throwanException; } } }
  • 24. Access Control (4) aspectAuthorization { pointcutcheckedMethods(): within(Server) &&execution(* service(..)); Objectaround(): checkedMethods() { Authenticationauth = Authen.aspectOf(); Subjectsubject = auth.getSubject(); if(checkForPermission) returnproceed();} }
  • 25. Inter-Typedeclarations declare parents: banking.entities* implementsIdentifiable; declare warning: : get(public !final *.*) || set(public *.*) : “Should use a getteror setter method”;
  • 26. Cache publicabstractaspect Cache {Map _cache = new HashMap();abstractpointcutcacheMe(Object o);Objectaround(Object o): cacheMe(o) {ObjectinCache = _cache.get(o);if(inCache == null) {inCache = proceed(o); _cache.put(o, inCache); }returninCache;} }
  • 27. Pero yo no programo en Java…
  • 28. Pero yo no programo en Java… <script type=“text/javascript”> varpointcut = AspectScript.Pointcuts.call(foo); varadvice = function() { alert("Callingfoo"); }; AspectScript.before(pointcut, advice); </script>
  • 29. Pero yo no programo en Java… require ‘aquarium’ classAccount includeAquarium::DSL before :calls_to=> [:credit, :debit] br /> do |join_point, object, *args| object.balance= read_from_database… end
  • 30. Otras implementaciones de aspectos AspectC / AspectC++ AspectScript* (Javascript) Aquarium (Ruby) MetaclassTalk (Smalltalk) Spring AOP JBoss AOP etc * hecho en Chile
  • 31. Conclusiones Los aspectos permiten modularizarcross-cuttingconcerns AspectJ es un lenguaje bastante expresivo, pero limitado Muy útiles en ambientes de desarrollo
  • 32. Referencias AspectJ Project http://www.eclipse.org/aspectj/ AJDT (Eclipse plugin) http://www.eclipse.org/ajdt/ Slides de CC71P – Objetos y Aspectos http://pleiad.dcc.uchile.cl/teaching/cc71p Howaspectorientedprogramming can helptobuildsecure software http://people.cs.kuleuven.be/~bart.dedecker/pubs/aspects.pdf AspectScripthttp://www.pleiad.cl/aspectscript/ Mis tareas de CC71P :-P