SlideShare une entreprise Scribd logo
1  sur  17
Télécharger pour lire hors ligne
AspectJ Introduction
For non-programmers:
What is it good for
And how to use it
https://tamasrev.wordpress.com/
https://twitter.com/tamasrev
2017
What is AspectJ
• “AspectJ is an aspect-oriented programming (AOP) extension […] for
the Java programming language” [1]
What is AspectJ
• AspectJ intercepts code. It can run any code before / after / around /
instead of the original code.
• Other Aspect-Oriented Programming (AOP) libraries do the same
• AspectJ adds code between the caller and the called method
• Does this sound familiar?
• Database Triggers can intercept SQL commands and run something before /
after / around / instead of the original command.
• Wrappers (Proxies, Skeletons) are similar: they come between the caller and
the called method
What is AOP good for – typical use cases
• Audit logging
• Transaction-handling
• Start transaction before the method call
• Commit transaction after the method call
• Roll back transaction at exception
• Enforcing security constraints
• Profiling: measure time before and after a method call
• Pluggable architecture – we can add after-event callbacks, just like the
Tapestry web framework does [2]
AOP – more use-cases
• Enforcing methods to run asynchronously
• Debug logging
• Extending business logic – just like the normal Object-Oriented
programs would do
• This makes maintenance difficult
• Sometimes this is the only option for somebody else’s code
• This establishes the same dependencies just like the normal Object-Oriented
inheritance would
• AspectJ in Action describes several more use-cases [7]
Other AOP solutions for Java
• Other than AspectJ, there are several tools for Aspect-Oriented
programming in Java. One of those tools is AOP Alliance and they list
their competitors [6]. So here is a list:
• AOP Alliance
• ASM
• Javassist
• Jboss-AOP
• Nanning
Who uses AspectJ
• “AspectJ has become a widely used de facto standard for AOP by
emphasizing simplicity and usability for end users.” [1]
• Spring, the leading java IoC framework
• Hadoop, the framework for data-intensive distributed system
• AWS SDK for Java – the Software Development Kit for Amazons could
• CAS, the Configuration Server
• MySQL Connector for java
• Xwiki, the collaborative editing tool
• Atlassian Bamboo, the CI server
Who uses other AOP tools
• Tapestry web framework uses javassist
• JBoss Application Server dependencies include javassist, ASM
• Provides JBoss-AOP to its users
• The gwt web framework uses AOP Alliance – through Guice IoC
framework
• The Jetty web container uses ASM
• The Wicket web framework uses ASM
Can you use AspectJ?
• AspectJ is distributed with Eclipse Public License 1.0 [3] [4]
• Summary:
“Most users only want to use AspectJ to build programs they distribute. There are no restrictions
here. When you distribute your program, be sure to include all the runtime classes from the
aspectjrt.jar for that version of AspectJ. When distributing only the runtime classes, you need not
provide any notice that the program was compiled with AspectJ or includes binaries from the
AspectJ project, except as necessary to preserve the warranty disclaimers in our license.” [5]
• Legally: yes, you can use AspectJ
How does AspectJ work?
• AspectJ intercepts code – this is called instrumentalization.
• Code that can be instrumentalized:
• Methods
• Constructors
• Static initializers
• Intercepting means we can run something around the original code:
• We can run stuff before and / or after the original code – so we slightly modify the original
behavior
• We can run stuff instead of the original code – we can specify totally different behavior
• What we write:
• Instruct AspectJ what to intercept – i.e. method, constructor, initializer
• Instruct AspectJ what behavior it should add around the original code
• What AspectJ does: AspectJ is weaving our code with the original code. It makes
our code run around the original code.
How does AspectJ work?
• AspectJ weaving modifies the JVM byte code.
• JVM byte code: the language that runs on the Java Virtual Machine (JVM)
• The JVM byte code is a standard language
• Hardly anybody writes byte code. We compile it from a high-level language, like Java, Groovy,
Scala, Kotlin, …
• AspectJ can modify the byte code at compile time.
• It’s called compile-time weaving.
• It’s a convenience for the developers.
• AspectJ can modify the byte code at load time. I.e. when the JVM loads the classes.
• It’s called load-time weaving.
• It’s a way to modify 3rd party code.
• When AspectJ modifies the byte code, it basically applies the Proxy Object Design
Pattern.
• The Proxy Object Design Pattern is a generalization of the Wrapper Design Pattern.
What is AspectJ good for
• AspectJ is good to implement Wrappers when the original Service has
lots of SQL config.
• Logging in test servers to figure out what’s going on.
• Implementing cross-cutting concerns quickly
• A controversial use-case:
• “Patching” 3rd party code for experiments
• This is controversial because modifying 3rd party code can cause political
trouble between the vendor and the customer. I.e. whose code is broken
now?
What kind of problems can AspectJ cause?
• It might make code harder to maintain
• It has memory requirements
How to debug code that uses AspectJ?
• In the exception traces we’ll see things like around<MethodName>
• We can turn it off with the –XnoInline switch. It too has a memory
implication.
• We can always check how the process was started:
• If we see –Djavaagent=…/aspectjweaver.jar, then it uses AspectJ
• The Aspects are registered under META-INF/aop.xml unless specified
otherwise
• When it’s specified otherwise, it’s on the process start parameters, like this:
• -Dorg.aspectj.weaver.loadtime.configuration=META-
INFdebug_logging_aop.xml
• Those parameters are usually specified at the registry or in command files
Questions
• If you have any questions, please contact me on twitter:
• https://twitter.com/tamasrev
• You can see a programming guide on eclipse.org :
https://www.eclipse.org/aspectj/doc/released/progguide/starting.ht
ml
References
• [1] AspectJ on Wikipedia https://en.wikipedia.org/wiki/AspectJ
• [2] AfterRender annotation in Tapestry
http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/annotations/A
fterRender.html
• [3] Eclipse Public License https://www.eclipse.org/legal/epl-v10.html
• [4] About the AspectJ project https://projects.eclipse.org/projects/tools.aspectj
• [5] AspectJ FAQ: How is AspectJ licensed?
https://www.eclipse.org/aspectj/doc/released/faq.php#q:license
• [6] AOP tools listed at AOP Alliance
http://aopalliance.sourceforge.net/motivations.html
• [7] AspectJ in Action https://www.manning.com/books/aspectj-in-action-second-
edition
Images
• [1] Yawning cat: https://www.pexels.com/photo/animal-kitten-cat-
funny-56857/
• [2] Yawning boy https://pixabay.com/hu/%C3%A1s%C3%ADt-
%C3%A1lmos-baba-2073293/

Contenu connexe

Tendances

Debugging ansible modules
Debugging ansible modulesDebugging ansible modules
Debugging ansible modulesaleonhardt
 
RESTFul Tools For Lazy Experts - CFSummit 2016
RESTFul Tools For Lazy Experts - CFSummit 2016RESTFul Tools For Lazy Experts - CFSummit 2016
RESTFul Tools For Lazy Experts - CFSummit 2016Ortus Solutions, Corp
 
CBDW2014 - Down the RabbitMQ hole with ColdFusion
CBDW2014 - Down the RabbitMQ hole with ColdFusionCBDW2014 - Down the RabbitMQ hole with ColdFusion
CBDW2014 - Down the RabbitMQ hole with ColdFusionOrtus Solutions, Corp
 
Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6Ganesh Kondal
 
Open stack and_vagrant-os-meetup-2015
Open stack and_vagrant-os-meetup-2015Open stack and_vagrant-os-meetup-2015
Open stack and_vagrant-os-meetup-2015yfauser
 
Functional Programming in PHP
Functional Programming in PHPFunctional Programming in PHP
Functional Programming in PHPAurimas Niekis
 
Next generation frontend tooling
Next generation frontend toolingNext generation frontend tooling
Next generation frontend toolingpksjce
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0Ganesh Kondal
 
Web development basics (Part-5)
Web development basics (Part-5)Web development basics (Part-5)
Web development basics (Part-5)Rajat Pratap Singh
 
QA Challenge Accepted 4.0 - Cypress vs. Selenium
QA Challenge Accepted 4.0 - Cypress vs. SeleniumQA Challenge Accepted 4.0 - Cypress vs. Selenium
QA Challenge Accepted 4.0 - Cypress vs. SeleniumLyudmil Latinov
 
Lock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin CoroutinesLock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin CoroutinesRoman Elizarov
 
Proxying DBI with DBD::Gofer and App::Staticperl
Proxying DBI with DBD::Gofer and App::StaticperlProxying DBI with DBD::Gofer and App::Staticperl
Proxying DBI with DBD::Gofer and App::Staticperlnohuhu
 
Real World Elixir Deployment
Real World Elixir DeploymentReal World Elixir Deployment
Real World Elixir DeploymentPete Gamache
 
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakMarcus Denker
 
GenRetry: Simple Exponential Backoff in Elixir
GenRetry: Simple Exponential Backoff in ElixirGenRetry: Simple Exponential Backoff in Elixir
GenRetry: Simple Exponential Backoff in ElixirPete Gamache
 
Asynchronous programming in ASP.NET
Asynchronous programming in ASP.NETAsynchronous programming in ASP.NET
Asynchronous programming in ASP.NETAlex Thissen
 
Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013slandelle
 

Tendances (20)

Debugging ansible modules
Debugging ansible modulesDebugging ansible modules
Debugging ansible modules
 
RESTFul Tools For Lazy Experts - CFSummit 2016
RESTFul Tools For Lazy Experts - CFSummit 2016RESTFul Tools For Lazy Experts - CFSummit 2016
RESTFul Tools For Lazy Experts - CFSummit 2016
 
Testing Automaton - CFSummit 2016
Testing Automaton - CFSummit 2016Testing Automaton - CFSummit 2016
Testing Automaton - CFSummit 2016
 
CBDW2014 - Down the RabbitMQ hole with ColdFusion
CBDW2014 - Down the RabbitMQ hole with ColdFusionCBDW2014 - Down the RabbitMQ hole with ColdFusion
CBDW2014 - Down the RabbitMQ hole with ColdFusion
 
Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6Tech io nodejs_20130531_v0.6
Tech io nodejs_20130531_v0.6
 
Open stack and_vagrant-os-meetup-2015
Open stack and_vagrant-os-meetup-2015Open stack and_vagrant-os-meetup-2015
Open stack and_vagrant-os-meetup-2015
 
Functional Programming in PHP
Functional Programming in PHPFunctional Programming in PHP
Functional Programming in PHP
 
Next generation frontend tooling
Next generation frontend toolingNext generation frontend tooling
Next generation frontend tooling
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
 
Web development basics (Part-5)
Web development basics (Part-5)Web development basics (Part-5)
Web development basics (Part-5)
 
QA Challenge Accepted 4.0 - Cypress vs. Selenium
QA Challenge Accepted 4.0 - Cypress vs. SeleniumQA Challenge Accepted 4.0 - Cypress vs. Selenium
QA Challenge Accepted 4.0 - Cypress vs. Selenium
 
Lock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin CoroutinesLock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin Coroutines
 
Proxying DBI with DBD::Gofer and App::Staticperl
Proxying DBI with DBD::Gofer and App::StaticperlProxying DBI with DBD::Gofer and App::Staticperl
Proxying DBI with DBD::Gofer and App::Staticperl
 
Load test REST APIs using gatling
Load test REST APIs using gatlingLoad test REST APIs using gatling
Load test REST APIs using gatling
 
Real World Elixir Deployment
Real World Elixir DeploymentReal World Elixir Deployment
Real World Elixir Deployment
 
Cypress workshop for JSFoo 2019
Cypress  workshop for JSFoo 2019Cypress  workshop for JSFoo 2019
Cypress workshop for JSFoo 2019
 
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond Smalltak
 
GenRetry: Simple Exponential Backoff in Elixir
GenRetry: Simple Exponential Backoff in ElixirGenRetry: Simple Exponential Backoff in Elixir
GenRetry: Simple Exponential Backoff in Elixir
 
Asynchronous programming in ASP.NET
Asynchronous programming in ASP.NETAsynchronous programming in ASP.NET
Asynchronous programming in ASP.NET
 
Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013
 

Similaire à Aspect j introduction for non-programmers

we45 DEFCON Workshop - Building AppSec Automation with Python
we45 DEFCON Workshop - Building AppSec Automation with Pythonwe45 DEFCON Workshop - Building AppSec Automation with Python
we45 DEFCON Workshop - Building AppSec Automation with PythonAbhay Bhargav
 
Using Apache Camel as AKKA
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKAJohan Edstrom
 
Oracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuningOracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuningMichel Schildmeijer
 
presentation on online movie ticket booking
presentation on online movie ticket bookingpresentation on online movie ticket booking
presentation on online movie ticket bookingdharmawath
 
IaC? VSTS to the rescue! Abbreviations explained
IaC? VSTS to the rescue! Abbreviations explainedIaC? VSTS to the rescue! Abbreviations explained
IaC? VSTS to the rescue! Abbreviations explainedJeroen Niesen
 
Performance of Microservice Frameworks on different JVMs
Performance of Microservice Frameworks on different JVMsPerformance of Microservice Frameworks on different JVMs
Performance of Microservice Frameworks on different JVMsMaarten Smeets
 
MWLUG - Universal Java
MWLUG  -  Universal JavaMWLUG  -  Universal Java
MWLUG - Universal JavaPhilippe Riand
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)Sujit Majety
 
Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to SpringSujit Kumar
 
Building Asynchronous Applications
Building Asynchronous ApplicationsBuilding Asynchronous Applications
Building Asynchronous ApplicationsJohan Edstrom
 
Getting to Walk with DevOps
Getting to Walk with DevOpsGetting to Walk with DevOps
Getting to Walk with DevOpsEklove Mohan
 

Similaire à Aspect j introduction for non-programmers (20)

we45 DEFCON Workshop - Building AppSec Automation with Python
we45 DEFCON Workshop - Building AppSec Automation with Pythonwe45 DEFCON Workshop - Building AppSec Automation with Python
we45 DEFCON Workshop - Building AppSec Automation with Python
 
Using Apache Camel as AKKA
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKA
 
Oracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuningOracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuning
 
Fastest Servlets in the West
Fastest Servlets in the WestFastest Servlets in the West
Fastest Servlets in the West
 
JVM
JVMJVM
JVM
 
Infrastructure as Code
Infrastructure as CodeInfrastructure as Code
Infrastructure as Code
 
presentation on online movie ticket booking
presentation on online movie ticket bookingpresentation on online movie ticket booking
presentation on online movie ticket booking
 
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptxJAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
 
IaC? VSTS to the rescue! Abbreviations explained
IaC? VSTS to the rescue! Abbreviations explainedIaC? VSTS to the rescue! Abbreviations explained
IaC? VSTS to the rescue! Abbreviations explained
 
Performance of Microservice Frameworks on different JVMs
Performance of Microservice Frameworks on different JVMsPerformance of Microservice Frameworks on different JVMs
Performance of Microservice Frameworks on different JVMs
 
MWLUG - Universal Java
MWLUG  -  Universal JavaMWLUG  -  Universal Java
MWLUG - Universal Java
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
 
Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)
 
Introduction to Spring
Introduction to SpringIntroduction to Spring
Introduction to Spring
 
Building Asynchronous Applications
Building Asynchronous ApplicationsBuilding Asynchronous Applications
Building Asynchronous Applications
 
Getting to Walk with DevOps
Getting to Walk with DevOpsGetting to Walk with DevOps
Getting to Walk with DevOps
 
Java virtual machine
Java virtual machineJava virtual machine
Java virtual machine
 
Hello world - intro to node js
Hello world - intro to node jsHello world - intro to node js
Hello world - intro to node js
 
Java introduction
Java introductionJava introduction
Java introduction
 
Flexible compute
Flexible computeFlexible compute
Flexible compute
 

Dernier

ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfTobias Schneck
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIIvo Andreev
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampVICTOR MAESTRE RAMIREZ
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxJoão Esperancinha
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdfMeon Technology
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyRaymond Okyere-Forson
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmonyelliciumsolutionspun
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsJaydeep Chhasatia
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?AmeliaSmith90
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorShane Coughlan
 
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageSales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageDista
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfBrain Inventory
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesSoftwareMill
 
Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024Mind IT Systems
 
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.Sharon Liu
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesShyamsundar Das
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLAlluxio, Inc.
 
Webinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.pptWebinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.pptkinjal48
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadIvo Andreev
 

Dernier (20)

ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AI
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - Datacamp
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptx
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdf
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human Beauty
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS Calculator
 
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageSales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdf
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retries
 
Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024
 
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in Trivandrum
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security Challenges
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
 
Webinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.pptWebinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.ppt
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and Bad
 

Aspect j introduction for non-programmers

  • 1. AspectJ Introduction For non-programmers: What is it good for And how to use it https://tamasrev.wordpress.com/ https://twitter.com/tamasrev 2017
  • 2. What is AspectJ • “AspectJ is an aspect-oriented programming (AOP) extension […] for the Java programming language” [1]
  • 3. What is AspectJ • AspectJ intercepts code. It can run any code before / after / around / instead of the original code. • Other Aspect-Oriented Programming (AOP) libraries do the same • AspectJ adds code between the caller and the called method • Does this sound familiar? • Database Triggers can intercept SQL commands and run something before / after / around / instead of the original command. • Wrappers (Proxies, Skeletons) are similar: they come between the caller and the called method
  • 4. What is AOP good for – typical use cases • Audit logging • Transaction-handling • Start transaction before the method call • Commit transaction after the method call • Roll back transaction at exception • Enforcing security constraints • Profiling: measure time before and after a method call • Pluggable architecture – we can add after-event callbacks, just like the Tapestry web framework does [2]
  • 5. AOP – more use-cases • Enforcing methods to run asynchronously • Debug logging • Extending business logic – just like the normal Object-Oriented programs would do • This makes maintenance difficult • Sometimes this is the only option for somebody else’s code • This establishes the same dependencies just like the normal Object-Oriented inheritance would • AspectJ in Action describes several more use-cases [7]
  • 6. Other AOP solutions for Java • Other than AspectJ, there are several tools for Aspect-Oriented programming in Java. One of those tools is AOP Alliance and they list their competitors [6]. So here is a list: • AOP Alliance • ASM • Javassist • Jboss-AOP • Nanning
  • 7. Who uses AspectJ • “AspectJ has become a widely used de facto standard for AOP by emphasizing simplicity and usability for end users.” [1] • Spring, the leading java IoC framework • Hadoop, the framework for data-intensive distributed system • AWS SDK for Java – the Software Development Kit for Amazons could • CAS, the Configuration Server • MySQL Connector for java • Xwiki, the collaborative editing tool • Atlassian Bamboo, the CI server
  • 8. Who uses other AOP tools • Tapestry web framework uses javassist • JBoss Application Server dependencies include javassist, ASM • Provides JBoss-AOP to its users • The gwt web framework uses AOP Alliance – through Guice IoC framework • The Jetty web container uses ASM • The Wicket web framework uses ASM
  • 9. Can you use AspectJ? • AspectJ is distributed with Eclipse Public License 1.0 [3] [4] • Summary: “Most users only want to use AspectJ to build programs they distribute. There are no restrictions here. When you distribute your program, be sure to include all the runtime classes from the aspectjrt.jar for that version of AspectJ. When distributing only the runtime classes, you need not provide any notice that the program was compiled with AspectJ or includes binaries from the AspectJ project, except as necessary to preserve the warranty disclaimers in our license.” [5] • Legally: yes, you can use AspectJ
  • 10. How does AspectJ work? • AspectJ intercepts code – this is called instrumentalization. • Code that can be instrumentalized: • Methods • Constructors • Static initializers • Intercepting means we can run something around the original code: • We can run stuff before and / or after the original code – so we slightly modify the original behavior • We can run stuff instead of the original code – we can specify totally different behavior • What we write: • Instruct AspectJ what to intercept – i.e. method, constructor, initializer • Instruct AspectJ what behavior it should add around the original code • What AspectJ does: AspectJ is weaving our code with the original code. It makes our code run around the original code.
  • 11. How does AspectJ work? • AspectJ weaving modifies the JVM byte code. • JVM byte code: the language that runs on the Java Virtual Machine (JVM) • The JVM byte code is a standard language • Hardly anybody writes byte code. We compile it from a high-level language, like Java, Groovy, Scala, Kotlin, … • AspectJ can modify the byte code at compile time. • It’s called compile-time weaving. • It’s a convenience for the developers. • AspectJ can modify the byte code at load time. I.e. when the JVM loads the classes. • It’s called load-time weaving. • It’s a way to modify 3rd party code. • When AspectJ modifies the byte code, it basically applies the Proxy Object Design Pattern. • The Proxy Object Design Pattern is a generalization of the Wrapper Design Pattern.
  • 12. What is AspectJ good for • AspectJ is good to implement Wrappers when the original Service has lots of SQL config. • Logging in test servers to figure out what’s going on. • Implementing cross-cutting concerns quickly • A controversial use-case: • “Patching” 3rd party code for experiments • This is controversial because modifying 3rd party code can cause political trouble between the vendor and the customer. I.e. whose code is broken now?
  • 13. What kind of problems can AspectJ cause? • It might make code harder to maintain • It has memory requirements
  • 14. How to debug code that uses AspectJ? • In the exception traces we’ll see things like around<MethodName> • We can turn it off with the –XnoInline switch. It too has a memory implication. • We can always check how the process was started: • If we see –Djavaagent=…/aspectjweaver.jar, then it uses AspectJ • The Aspects are registered under META-INF/aop.xml unless specified otherwise • When it’s specified otherwise, it’s on the process start parameters, like this: • -Dorg.aspectj.weaver.loadtime.configuration=META- INFdebug_logging_aop.xml • Those parameters are usually specified at the registry or in command files
  • 15. Questions • If you have any questions, please contact me on twitter: • https://twitter.com/tamasrev • You can see a programming guide on eclipse.org : https://www.eclipse.org/aspectj/doc/released/progguide/starting.ht ml
  • 16. References • [1] AspectJ on Wikipedia https://en.wikipedia.org/wiki/AspectJ • [2] AfterRender annotation in Tapestry http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/annotations/A fterRender.html • [3] Eclipse Public License https://www.eclipse.org/legal/epl-v10.html • [4] About the AspectJ project https://projects.eclipse.org/projects/tools.aspectj • [5] AspectJ FAQ: How is AspectJ licensed? https://www.eclipse.org/aspectj/doc/released/faq.php#q:license • [6] AOP tools listed at AOP Alliance http://aopalliance.sourceforge.net/motivations.html • [7] AspectJ in Action https://www.manning.com/books/aspectj-in-action-second- edition
  • 17. Images • [1] Yawning cat: https://www.pexels.com/photo/animal-kitten-cat- funny-56857/ • [2] Yawning boy https://pixabay.com/hu/%C3%A1s%C3%ADt- %C3%A1lmos-baba-2073293/