SlideShare ist ein Scribd-Unternehmen logo
1 von 54
Feelin’ Groovy: An Afternoon of Reflexive Metaprogramming Matt Stine UM-CIS Seminar September 3, 2008
Who Am I? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object]
Groovy: A Brief Tour ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Groovy: A Brief Tour ,[object Object],[object Object]
Groovy: A Brief Tour ,[object Object]
Groovy: A Brief Tour ,[object Object],[object Object]
Groovy: A Brief Tour ,[object Object],[object Object],[object Object],[object Object],[object Object]
Groovy: A Brief Tour ,[object Object]
Groovy: A Brief Tour ,[object Object]
Groovy: A Brief Tour ,[object Object],[object Object]
Reflexive Metaprogramming? ,[object Object],[object Object],Source: H. C. Cunningham. Reflexive metaprogramming in Ruby, Journal of Computing Sciences in Colleges, Vol, 22, No. 5, pp. 145-146, CCSC, May 2007.
How Groovy supports RM ,[object Object],[object Object],[object Object],[object Object]
How Groovy supports RM ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Groovy Object
Groovy interceptors
POJOs, POGOs, and their MetaClass
How Groovy Handles POGO Method Calls
How Groovy supports RM ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How Groovy supports RM ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Three areas of focus: ,[object Object],[object Object],[object Object]
Groovy AOP ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Two approaches: ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using GroovyInterceptable
Using MetaClass
Using MetaClass (on a POJO)
Method Injection ,[object Object],[object Object],[object Object],[object Object]
Categories ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Category Method Injection
Category Method Injection (2)
ExpandoMetaClass ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ExpandoMetaClass  Injection ,[object Object]
ExpandoMetaClass  Injection ,[object Object]
ExpandoMetaClass  Injection ,[object Object]
ExpandoMetaClass  Injection ,[object Object]
Method Synthesis ,[object Object],[object Object],[object Object],[object Object]
Method Synthesis
Method Synthesis ,[object Object],[object Object],[object Object],[object Object],[object Object]
Intercept, Cache, Invoke
Method Synthesis ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
A Look at Internal DSL’s ,[object Object],[object Object],[object Object]
Why DSL’s? ,[object Object],[object Object],[object Object],[object Object],[object Object]
Groovy + DSL’s ,[object Object],[object Object]
An Example DSL ,[object Object],[object Object]
What is JScience? ,[object Object],[object Object],[object Object]
How to represent a mass with JScience?
Wouldn’t it be nicer… ,[object Object],[object Object],[object Object],[object Object]
DSL Implementation
DSL Implementation
DSL Implementation
DSL Implementation
QUESTIONS?!?!?!
Resources ,[object Object],[object Object],[object Object]
References ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (8)

Groovy
GroovyGroovy
Groovy
 
Groovy And Grails
Groovy And GrailsGroovy And Grails
Groovy And Grails
 
Groovy intro
Groovy introGroovy intro
Groovy intro
 
C# interview questions
C# interview questionsC# interview questions
C# interview questions
 
C# interview quesions
C# interview quesionsC# interview quesions
C# interview quesions
 
Meta Programming in Groovy
Meta Programming in GroovyMeta Programming in Groovy
Meta Programming in Groovy
 
Greach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovyGreach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovy
 
python training | python course | python online training
python training |  python course |  python online trainingpython training |  python course |  python online training
python training | python course | python online training
 

Andere mochten auch

Getting Things Done
Getting Things DoneGetting Things Done
Getting Things DoneMatt Stine
 
Java(tm) Technology On Google App Engine
Java(tm) Technology On Google App EngineJava(tm) Technology On Google App Engine
Java(tm) Technology On Google App EngineMatt Stine
 
The Cloud Native Journey
The Cloud Native JourneyThe Cloud Native Journey
The Cloud Native JourneyMatt Stine
 
Functional solid
Functional solidFunctional solid
Functional solidMatt Stine
 
Lattice: A Cloud-Native Platform for Your Spring Applications
Lattice: A Cloud-Native Platform for Your Spring ApplicationsLattice: A Cloud-Native Platform for Your Spring Applications
Lattice: A Cloud-Native Platform for Your Spring ApplicationsMatt Stine
 
Competing with Software: It Takes a Platform -- Devops @ EMC World
Competing with Software: It Takes a Platform -- Devops @ EMC WorldCompeting with Software: It Takes a Platform -- Devops @ EMC World
Competing with Software: It Takes a Platform -- Devops @ EMC Worldcornelia davis
 
Linux Collaboration Summit Keynote: Transformation: It Takes a Platform
Linux Collaboration Summit Keynote: Transformation: It Takes a PlatformLinux Collaboration Summit Keynote: Transformation: It Takes a Platform
Linux Collaboration Summit Keynote: Transformation: It Takes a Platformcornelia davis
 
It's the End of the Cloud as We Know It
It's the End of the Cloud as We Know ItIt's the End of the Cloud as We Know It
It's the End of the Cloud as We Know ItMatt Stine
 
Deploying Microservices to Cloud Foundry
Deploying Microservices to Cloud FoundryDeploying Microservices to Cloud Foundry
Deploying Microservices to Cloud FoundryMatt Stine
 
Evolving Devops: The Benefits of PaaS and Application Dial Tone
Evolving Devops: The Benefits of PaaS and Application Dial ToneEvolving Devops: The Benefits of PaaS and Application Dial Tone
Evolving Devops: The Benefits of PaaS and Application Dial Tonecornelia davis
 
Velocity NY 2016 - Devops: Who Does What?
Velocity NY 2016 - Devops: Who Does What?Velocity NY 2016 - Devops: Who Does What?
Velocity NY 2016 - Devops: Who Does What?cornelia davis
 
Pivotal Cloud Platform Roadshow Keynote
Pivotal Cloud Platform Roadshow KeynotePivotal Cloud Platform Roadshow Keynote
Pivotal Cloud Platform Roadshow Keynotecornelia davis
 
Reactive Fault Tolerant Programming with Hystrix and RxJava
Reactive Fault Tolerant Programming with Hystrix and RxJavaReactive Fault Tolerant Programming with Hystrix and RxJava
Reactive Fault Tolerant Programming with Hystrix and RxJavaMatt Stine
 
Devops Enterprise Summit: My Great Awakening: 
Top “Ah-ha” Moments As Former ...
Devops Enterprise Summit: My Great Awakening: 
Top “Ah-ha” Moments As Former ...Devops Enterprise Summit: My Great Awakening: 
Top “Ah-ha” Moments As Former ...
Devops Enterprise Summit: My Great Awakening: 
Top “Ah-ha” Moments As Former ...cornelia davis
 
12 Factor, or Cloud Native Apps – What EXACTLY Does that Mean for Spring Deve...
12 Factor, or Cloud Native Apps – What EXACTLY Does that Mean for Spring Deve...12 Factor, or Cloud Native Apps – What EXACTLY Does that Mean for Spring Deve...
12 Factor, or Cloud Native Apps – What EXACTLY Does that Mean for Spring Deve...cornelia davis
 
Cloud Foundry Introduction (w Demo) at Silicon Valley Code Camp
Cloud Foundry Introduction (w Demo) at Silicon Valley Code CampCloud Foundry Introduction (w Demo) at Silicon Valley Code Camp
Cloud Foundry Introduction (w Demo) at Silicon Valley Code Campcornelia davis
 
Removing Barriers Between Dev and Ops
Removing Barriers Between Dev and OpsRemoving Barriers Between Dev and Ops
Removing Barriers Between Dev and Opscornelia davis
 
Software Quality in the Devops World: The Impact of Continuous Delivery on Te...
Software Quality in the Devops World: The Impact of Continuous Delivery on Te...Software Quality in the Devops World: The Impact of Continuous Delivery on Te...
Software Quality in the Devops World: The Impact of Continuous Delivery on Te...cornelia davis
 
Cloud Foundry Platform Operations - CF Summit 2015
Cloud Foundry Platform Operations - CF Summit 2015Cloud Foundry Platform Operations - CF Summit 2015
Cloud Foundry Platform Operations - CF Summit 2015cornelia davis
 

Andere mochten auch (20)

Getting Things Done
Getting Things DoneGetting Things Done
Getting Things Done
 
Java(tm) Technology On Google App Engine
Java(tm) Technology On Google App EngineJava(tm) Technology On Google App Engine
Java(tm) Technology On Google App Engine
 
The Cloud Native Journey
The Cloud Native JourneyThe Cloud Native Journey
The Cloud Native Journey
 
Functional solid
Functional solidFunctional solid
Functional solid
 
Lattice: A Cloud-Native Platform for Your Spring Applications
Lattice: A Cloud-Native Platform for Your Spring ApplicationsLattice: A Cloud-Native Platform for Your Spring Applications
Lattice: A Cloud-Native Platform for Your Spring Applications
 
Competing with Software: It Takes a Platform -- Devops @ EMC World
Competing with Software: It Takes a Platform -- Devops @ EMC WorldCompeting with Software: It Takes a Platform -- Devops @ EMC World
Competing with Software: It Takes a Platform -- Devops @ EMC World
 
Linux Collaboration Summit Keynote: Transformation: It Takes a Platform
Linux Collaboration Summit Keynote: Transformation: It Takes a PlatformLinux Collaboration Summit Keynote: Transformation: It Takes a Platform
Linux Collaboration Summit Keynote: Transformation: It Takes a Platform
 
It's the End of the Cloud as We Know It
It's the End of the Cloud as We Know ItIt's the End of the Cloud as We Know It
It's the End of the Cloud as We Know It
 
Deploying Microservices to Cloud Foundry
Deploying Microservices to Cloud FoundryDeploying Microservices to Cloud Foundry
Deploying Microservices to Cloud Foundry
 
Evolving Devops: The Benefits of PaaS and Application Dial Tone
Evolving Devops: The Benefits of PaaS and Application Dial ToneEvolving Devops: The Benefits of PaaS and Application Dial Tone
Evolving Devops: The Benefits of PaaS and Application Dial Tone
 
Velocity NY 2016 - Devops: Who Does What?
Velocity NY 2016 - Devops: Who Does What?Velocity NY 2016 - Devops: Who Does What?
Velocity NY 2016 - Devops: Who Does What?
 
Pivotal Cloud Platform Roadshow Keynote
Pivotal Cloud Platform Roadshow KeynotePivotal Cloud Platform Roadshow Keynote
Pivotal Cloud Platform Roadshow Keynote
 
Reactive Fault Tolerant Programming with Hystrix and RxJava
Reactive Fault Tolerant Programming with Hystrix and RxJavaReactive Fault Tolerant Programming with Hystrix and RxJava
Reactive Fault Tolerant Programming with Hystrix and RxJava
 
Devops Enterprise Summit: My Great Awakening: 
Top “Ah-ha” Moments As Former ...
Devops Enterprise Summit: My Great Awakening: 
Top “Ah-ha” Moments As Former ...Devops Enterprise Summit: My Great Awakening: 
Top “Ah-ha” Moments As Former ...
Devops Enterprise Summit: My Great Awakening: 
Top “Ah-ha” Moments As Former ...
 
12 Factor, or Cloud Native Apps – What EXACTLY Does that Mean for Spring Deve...
12 Factor, or Cloud Native Apps – What EXACTLY Does that Mean for Spring Deve...12 Factor, or Cloud Native Apps – What EXACTLY Does that Mean for Spring Deve...
12 Factor, or Cloud Native Apps – What EXACTLY Does that Mean for Spring Deve...
 
Cloud Foundry Introduction (w Demo) at Silicon Valley Code Camp
Cloud Foundry Introduction (w Demo) at Silicon Valley Code CampCloud Foundry Introduction (w Demo) at Silicon Valley Code Camp
Cloud Foundry Introduction (w Demo) at Silicon Valley Code Camp
 
Removing Barriers Between Dev and Ops
Removing Barriers Between Dev and OpsRemoving Barriers Between Dev and Ops
Removing Barriers Between Dev and Ops
 
Software Quality in the Devops World: The Impact of Continuous Delivery on Te...
Software Quality in the Devops World: The Impact of Continuous Delivery on Te...Software Quality in the Devops World: The Impact of Continuous Delivery on Te...
Software Quality in the Devops World: The Impact of Continuous Delivery on Te...
 
Vert.x
Vert.xVert.x
Vert.x
 
Cloud Foundry Platform Operations - CF Summit 2015
Cloud Foundry Platform Operations - CF Summit 2015Cloud Foundry Platform Operations - CF Summit 2015
Cloud Foundry Platform Operations - CF Summit 2015
 

Ähnlich wie Feelin' Groovy: An Afternoon of Reflexive Metaprogramming

Dynamic Languages on the JVM
Dynamic Languages on the JVMDynamic Languages on the JVM
Dynamic Languages on the JVMelliando dias
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller ColumnsJonathan Fine
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming LanguageYLTO
 
Groovy Metaprogramming for Dummies
Groovy Metaprogramming for DummiesGroovy Metaprogramming for Dummies
Groovy Metaprogramming for DummiesDarren Cruse
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfnofakeNews
 
Why don't you Groovy?
Why don't you Groovy?Why don't you Groovy?
Why don't you Groovy?Orest Ivasiv
 
Groovy Finesse
Groovy FinesseGroovy Finesse
Groovy Finessemzgubin
 
Groovy Finesse
Groovy FinesseGroovy Finesse
Groovy Finessemzgubin
 
Java Interview Questions
Java Interview QuestionsJava Interview Questions
Java Interview QuestionsKuntal Bhowmick
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using ReflectionGanesh Samarthyam
 
Classes and Objects
Classes and ObjectsClasses and Objects
Classes and Objectsvmadan89
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010Rich Helton
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questionsGradeup
 
Core Java Interview Questions with Answers.pdf
Core Java Interview Questions with Answers.pdfCore Java Interview Questions with Answers.pdf
Core Java Interview Questions with Answers.pdfSudhanshiBakre1
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...Guillaume Laforge
 
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Steven Smith
 

Ähnlich wie Feelin' Groovy: An Afternoon of Reflexive Metaprogramming (20)

Dynamic Languages on the JVM
Dynamic Languages on the JVMDynamic Languages on the JVM
Dynamic Languages on the JVM
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller Columns
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming Language
 
Groovy Metaprogramming for Dummies
Groovy Metaprogramming for DummiesGroovy Metaprogramming for Dummies
Groovy Metaprogramming for Dummies
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
 
Why don't you Groovy?
Why don't you Groovy?Why don't you Groovy?
Why don't you Groovy?
 
Groovy Finesse
Groovy FinesseGroovy Finesse
Groovy Finesse
 
Groovy Finesse
Groovy FinesseGroovy Finesse
Groovy Finesse
 
Suga java training_with_footer
Suga java training_with_footerSuga java training_with_footer
Suga java training_with_footer
 
Java Interview Questions
Java Interview QuestionsJava Interview Questions
Java Interview Questions
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
 
Classes and Objects
Classes and ObjectsClasses and Objects
Classes and Objects
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
 
Csci360 20 (1)
Csci360 20 (1)Csci360 20 (1)
Csci360 20 (1)
 
Csci360 20
Csci360 20Csci360 20
Csci360 20
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questions
 
Java_notes.ppt
Java_notes.pptJava_notes.ppt
Java_notes.ppt
 
Core Java Interview Questions with Answers.pdf
Core Java Interview Questions with Answers.pdfCore Java Interview Questions with Answers.pdf
Core Java Interview Questions with Answers.pdf
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
 
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
 

Mehr von Matt Stine

Architectures That Bend but Don't Break
Architectures That Bend but Don't BreakArchitectures That Bend but Don't Break
Architectures That Bend but Don't BreakMatt Stine
 
Cloud Native Architecture Patterns Tutorial
Cloud Native Architecture Patterns TutorialCloud Native Architecture Patterns Tutorial
Cloud Native Architecture Patterns TutorialMatt Stine
 
Resilient Architecture
Resilient ArchitectureResilient Architecture
Resilient ArchitectureMatt Stine
 
Cloud Foundry: The Best Place to Run Microservices
Cloud Foundry: The Best Place to Run MicroservicesCloud Foundry: The Best Place to Run Microservices
Cloud Foundry: The Best Place to Run MicroservicesMatt Stine
 
To Microservices and Beyond
To Microservices and BeyondTo Microservices and Beyond
To Microservices and BeyondMatt Stine
 
Cloud Foundry Diego: Modular and Extensible Substructure for Microservices
Cloud Foundry Diego: Modular and Extensible Substructure for MicroservicesCloud Foundry Diego: Modular and Extensible Substructure for Microservices
Cloud Foundry Diego: Modular and Extensible Substructure for MicroservicesMatt Stine
 
Building Distributed Systems with Netflix OSS and Spring Cloud
Building Distributed Systems with Netflix OSS and Spring CloudBuilding Distributed Systems with Netflix OSS and Spring Cloud
Building Distributed Systems with Netflix OSS and Spring CloudMatt Stine
 
Pivotal Cloud Platform Roadshow: Sign Up for Pivotal Web Services
Pivotal Cloud Platform Roadshow: Sign Up for Pivotal Web ServicesPivotal Cloud Platform Roadshow: Sign Up for Pivotal Web Services
Pivotal Cloud Platform Roadshow: Sign Up for Pivotal Web ServicesMatt Stine
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoMatt Stine
 
Agile Development with OSGi
Agile Development with OSGiAgile Development with OSGi
Agile Development with OSGiMatt Stine
 
Cloud Foundry and Microservices: A Mutualistic Symbiotic Relationship
Cloud Foundry and Microservices: A Mutualistic Symbiotic RelationshipCloud Foundry and Microservices: A Mutualistic Symbiotic Relationship
Cloud Foundry and Microservices: A Mutualistic Symbiotic RelationshipMatt Stine
 
The Seven Wastes of Software Development
The Seven Wastes of Software DevelopmentThe Seven Wastes of Software Development
The Seven Wastes of Software DevelopmentMatt Stine
 
Information Sciences Solutions to Core Facility Problems at St. Jude Children...
Information Sciences Solutions to Core Facility Problems at St. Jude Children...Information Sciences Solutions to Core Facility Problems at St. Jude Children...
Information Sciences Solutions to Core Facility Problems at St. Jude Children...Matt Stine
 
Achieve Your Goals
Achieve Your GoalsAchieve Your Goals
Achieve Your GoalsMatt Stine
 
Deploying Grails to Morph App Space
Deploying Grails to Morph App SpaceDeploying Grails to Morph App Space
Deploying Grails to Morph App SpaceMatt Stine
 
JUG Leadership Lessons Learned
JUG Leadership Lessons LearnedJUG Leadership Lessons Learned
JUG Leadership Lessons LearnedMatt Stine
 
Introduction to JMS and Message-Driven POJOs
Introduction to JMS and Message-Driven POJOsIntroduction to JMS and Message-Driven POJOs
Introduction to JMS and Message-Driven POJOsMatt Stine
 
Case Study: SRM 2.0 - A next generation shared resource management system bui...
Case Study: SRM 2.0 - A next generation shared resource management system bui...Case Study: SRM 2.0 - A next generation shared resource management system bui...
Case Study: SRM 2.0 - A next generation shared resource management system bui...Matt Stine
 

Mehr von Matt Stine (19)

Architectures That Bend but Don't Break
Architectures That Bend but Don't BreakArchitectures That Bend but Don't Break
Architectures That Bend but Don't Break
 
Cloud Native Architecture Patterns Tutorial
Cloud Native Architecture Patterns TutorialCloud Native Architecture Patterns Tutorial
Cloud Native Architecture Patterns Tutorial
 
Resilient Architecture
Resilient ArchitectureResilient Architecture
Resilient Architecture
 
Cloud Foundry: The Best Place to Run Microservices
Cloud Foundry: The Best Place to Run MicroservicesCloud Foundry: The Best Place to Run Microservices
Cloud Foundry: The Best Place to Run Microservices
 
To Microservices and Beyond
To Microservices and BeyondTo Microservices and Beyond
To Microservices and Beyond
 
Cloud Foundry Diego: Modular and Extensible Substructure for Microservices
Cloud Foundry Diego: Modular and Extensible Substructure for MicroservicesCloud Foundry Diego: Modular and Extensible Substructure for Microservices
Cloud Foundry Diego: Modular and Extensible Substructure for Microservices
 
Building Distributed Systems with Netflix OSS and Spring Cloud
Building Distributed Systems with Netflix OSS and Spring CloudBuilding Distributed Systems with Netflix OSS and Spring Cloud
Building Distributed Systems with Netflix OSS and Spring Cloud
 
Pivotal Cloud Platform Roadshow: Sign Up for Pivotal Web Services
Pivotal Cloud Platform Roadshow: Sign Up for Pivotal Web ServicesPivotal Cloud Platform Roadshow: Sign Up for Pivotal Web Services
Pivotal Cloud Platform Roadshow: Sign Up for Pivotal Web Services
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
 
Agile Development with OSGi
Agile Development with OSGiAgile Development with OSGi
Agile Development with OSGi
 
Cloud Foundry and Microservices: A Mutualistic Symbiotic Relationship
Cloud Foundry and Microservices: A Mutualistic Symbiotic RelationshipCloud Foundry and Microservices: A Mutualistic Symbiotic Relationship
Cloud Foundry and Microservices: A Mutualistic Symbiotic Relationship
 
The Seven Wastes of Software Development
The Seven Wastes of Software DevelopmentThe Seven Wastes of Software Development
The Seven Wastes of Software Development
 
Information Sciences Solutions to Core Facility Problems at St. Jude Children...
Information Sciences Solutions to Core Facility Problems at St. Jude Children...Information Sciences Solutions to Core Facility Problems at St. Jude Children...
Information Sciences Solutions to Core Facility Problems at St. Jude Children...
 
Achieve Your Goals
Achieve Your GoalsAchieve Your Goals
Achieve Your Goals
 
Deploying Grails to Morph App Space
Deploying Grails to Morph App SpaceDeploying Grails to Morph App Space
Deploying Grails to Morph App Space
 
JUG Leadership Lessons Learned
JUG Leadership Lessons LearnedJUG Leadership Lessons Learned
JUG Leadership Lessons Learned
 
Introduction to JMS and Message-Driven POJOs
Introduction to JMS and Message-Driven POJOsIntroduction to JMS and Message-Driven POJOs
Introduction to JMS and Message-Driven POJOs
 
Case Study: SRM 2.0 - A next generation shared resource management system bui...
Case Study: SRM 2.0 - A next generation shared resource management system bui...Case Study: SRM 2.0 - A next generation shared resource management system bui...
Case Study: SRM 2.0 - A next generation shared resource management system bui...
 
Polyglot OSGi
Polyglot OSGiPolyglot OSGi
Polyglot OSGi
 

Kürzlich hochgeladen

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
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
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
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
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
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
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Kürzlich hochgeladen (20)

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
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
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
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
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
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
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Feelin' Groovy: An Afternoon of Reflexive Metaprogramming

Hinweis der Redaktion

  1. Of course, no introduction of myself would be complete without introducing my wife (CLICK!) And my four children (CLICK!)
  2. Consider the following Groovy class….it’s a Duck, and as any good Duck should, it walks like a duck and quacks like a duck. (CLICK!) Now, consider this Groovy class….it’s a MentalPatient, and it just so happens to walk like a duck and quack like a duck. (CLICK!) Now, consider the Groovy class….it claims to walk with ducks. It defines one method, with an interesting type declaration in its signature (CLICK!) Here we have a dynamic type declaration….”def”….this allows us to pass in either a Duck or a MentalPatient…and to WalksWithDucks, as long as it walks like a duck…. (CLICK!) It’s a duck!!!
  3. At the end of the day, it’s all in what you respond to! (CLICK!) Here we see one of Groovy’s metaprogramming constructs, the “respondsTo” method, which allows us to see whether or not a given object responds to certain method calls, irrespective of any class or interface implementation
  4. In Groovy application, 3 kinds of objects: POJO’s (Plain Old Java Objects) -> regular Java objects created in Java or other JVM languages (JRuby, Jython, etc.) POGO’s (Plain Old Groovy Objects) -> written in Groovy, extend java.lang.Object, implement groovy.lang.GroovyObject Groovy interceptors -> written in Groovy and implement GroovyInterceptable invokeMethod(), getProperty(), setProperty() – make Groovy objects highly dynamic – can be used to work w/ methods and properties created on the fly getMetaClass()/setMetaClass() – make it very easy to create proxies to intercept and also inject methods on a POGO
  5. Marker interface that extends GroovyObject All method calls – both existing and nonexisting methods – on an object implementing this interface are intercepted by its invokeMethod()
  6. Groovy allows metaprogramming for POJO’s and POGO’s POJOS – Groovy maintains a MetaClassRegistry class of MetaClasses POGOS – direct reference to their MetaClass When you call a method: Groovy first checks whether the target is a POJO or POGO, and handles such calls differently If it is a POJO, Groovy fetches its MetaClass from the MetaClassRegistry and delegates method invocation to it. Any interceptors or methods you’ve defined on its MetaClass take precedence over the original method of the POJO For POGO’s, Groovy takes a few extra steps (CLICK!)
  7. If the class implements GroovyInterceptable, all calls get routed to its invokeMethod() If not, then Groovy looks for the method first in the POGO’s MetaClass, and then if not found, in the POGO itself, executing in that order of preference If the POGO does not have either, it then looks for a property with that method name. If found, and if its type is Closure, it invokes the Closure. If no closure property, it invokes methodMissing() if it exists If not, it invokes the POGO’s invokeMethod() If all else fails, Groovy throws a MissingMethodException indicating the failure of the call
  8. Suppose we have a Car class for which we want to call its check() method to perform filtering prior to any other method call CLICK! Here we implement invokeMethod()….CLICK! First, we check to see if the name of the method is not check()….if not, we get access to the check() MetaMethod and invoke it….CLICK! Next, we try to access the MetaMethod for the method that was called…CLICK! If we don’t get a null, we know we have a valid method, and we invoke it…CLICK! Otherwise, we delegate the call to the Car MetaClass’s invokeMethod()….the default implementation throwing a MissingMethodException….CLICK! Here’s some client code…we call the 3 valid methods and then one invalid method…CLICK! And here’s the output….notice that for start() and drive() we run the filter….but when check() is called directly, we do not….and again, notice the MissingMethodException on speed()
  9. We can do the same thing using MetaClass…there are a few subtle differences: (CLICK!) We actually implement invokeMethod on the Car MetaClass by implementing a closure and assigning it to that method name. (CLICK!) Instead of passing “this” to invoke, we pass “delegate.” In a closure, delegate refers to the object that owns the closure. (CLICK!) Lastly, we call invokeMissingMethod() on the metaClass since we are already executing invokeMethod() and would not want to call that method recursively. invokeMissingMethod() actually delegates to invokeMethod() in the case of existing methods, and to missingMethod() in the case of nonexisting methods
  10. We can also use MetaClass on a POJO…in this case the java.lang.Integer class (CLICK!) Again, we’re implementing a closure and assigning it to invokeMethod on the Integer class (CLICK!) The closure simply checks for a valid method call, invokes pre-filtering code, invokes the method, and invokes post-filtering code. Here is some client code….the first two calls exist on Integer, while the third does not… (CLICK!) And here is the output…..notice the execution of the filters for the valid method calls and then the MissingMethodException thrown on the call to empty()
  11. So here we’re going to implement a StringUtil class containing a single method, toSSN(), that we’d like to be vailable on both String and StringBuffer…it will format the contents of the string as a social security number. So to do category injection, there are a few requirements: (CLICK!) First, you need a static method…(CLICK!) That accepts at least one parameter (the object for which the method is to be injected) (CLICK!) You write a use block, with the Category class as the argument…in this case, any Object inside the use block will have access to the toSSN() method because we left toSSN() dynamically typed (CLICK!) Objects outside the scope of the use block will not have toSSN()….(CLICK!) And here is the output…
  12. I want to show you a second example of this to futher illustrate the flexibility….here we have a FindUtil class with an extractOnly() method….(CLICK!) Again, the method is static….(CLICK!) It takes the object (in this case a String) on which to inject the method as the first parameter….(CLICK!) And it also takes a second argument, in this case a closure that we expect to return a boolean value…(CLICK!) Inside the method, we iterate over each character in the String and append to the result only characters for which the closure returns true. You’ll see “it” here, which happens to be the default argument in closures if none are specified…(CLICK!) We setup our use block and execute the code (CLICK!) In this case, we pass in a closre that returns true only if the scanned character is a ‘4’ or a ‘5’….given the String of characters we start with, we get 54 as the output…
  13. Here we’d like to add a method….daysFromNow()….to the Integer class…it will return an instance of java.util.Date equal to the Integer number of days from today….(CLICK!) Now you can tell I only made this slide a couple of days ago …. :-)
  14. We can also add a property in a similar way by implementing the “getter” method for a property called daysFromNow….this allows us to drop the parenthesis, creating a more “fluent” or human readable interface, something you like to shoot for when building domain specific languages…CLICK! Here’s the output….
  15. We can also add a static method by implementing methods on the static property of the metaClass…here’s we’ll add a method indicating whether or not its argument is an even number….CLICK! Again, here’s the output….
  16. The last method type we can add in is a constructor…we do this by appending a closure to the existing set of constructors on Integer….in this case, we want to construct an Integer equal to the current day of the year…CLICK! And the output….
  17. Let’s define a Person class that plays several sports…CLICK! First we’ll implement methodMissing()…CLICK! We’ll search for the suffix of the method named called….in this case we’re expecting method calls like “playFootball” or “playPolo”….CLICK! Having found it, we’ll return a String that says we’re “playing” the sport….here we’re using Groovy’s ability to execute arbitrary Groovy code embedded in a String inside the ${} construct…. CLICK! If we don’t find a legal method name, we throw a MissingMethodException….here’ some client code with several legal calls and one illegal call….CLICK! And here’s the output….notice that methodMissing() is not called for the work() method, but is for all of the sports-related methods….and we got a MissingMethodException for politics, which is usually not a sport, depending on who you’re talking to….
  18. Now let’s implement the Intercept, Cache, Invoke pattern on our Person class…CLICK! First we intercept the method call, just as we did before. Having found it….CLICK! We implement a closure and add it to the Person’s MetaClass…again we’re using Groovy’s String evaluation capabilities to dynamically construct the method name….CLICK! We then return the result of the closure we just implemented….CLICK! Quickly notice the static initializer block….here I’m simply “touching” the metaClass for Person. The reason for this is an eccentricity in Groovy in that ExpandoMetaClass is not the default MetaClass for Groovy, however once you access it the first time it is replaced with an instance of EMC. This may be changed in future versions….CLICK! Here’s some client code…CLICK!….and here’s the output. Notice that methodMissing() is only called once
  19. So here’s the beginning of our DSL….the first thing we do is enable the ExpandoMetaClass globally….this causes methods we add to a parent class, in this case Number, to be available to its children….CLICK! Next we reimplement Number’s get Property method….we assign it a closure that uses Jscience’s API to instantiate an Amount equal to the value of the Number instance and units specified by the propery name…. I’ve added a few examples of this and….CLICK!….here’s the output
  20. The next step is to define our operator overloading….since Jscience doesn’t use the same operation names as Groovy, we need to implement a few closures to massage out the differences…..I’ve put here examples of Multiplication Division Addition Subtraction Powers Opposites And comparisons…and CLICK! Here’s the output…..notice on the power example we mixed metric and english units, and Jscience guessed that we’d want the output in metric units (indicated by the question mark)…
  21. Our third step is to allow us to specify inverse units in a clean way, just like a physicist would. In a Groovy script like this one, all variables are local variables….however you can also pass in variables through a Binding, allowing for easy integration with existing Java code, etc. Here we’re going to implement a binding that will ignore references to the out property, which represents System.out….otherwise, it will return an amount equal to 1 unit of the symbol representing the property we tried to access…. Now, you can see these examples of inverse units, such as kilometers per hour, milligrams per Liter, etc…CLICK! And here’s the output of this portion….
  22. Finally, we’d like to easily do conversions between different units, so we define a to() method on Amount’s metaclass….here’s some examples of that and CLICK! The output