grails 3 inside and out

Post on 15-Apr-2017

1.122 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

SPRINGONE2GXWASHINGTON, DC

Grails 3 Inside & OutBy Graeme Rocher

@graemerocher

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Who we are?

Jeff Scott Brown Object Computing Inc. @jeffscottbrown brownj@ociweb.com

2

Graeme Rocher Object Computing Inc. @graemerocher rocherg@ociweb.com

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Grails + OCI• OCI focused on Grails• Full service support

– Consulting– Training– Support

• Commitment to engineering • Grails team at OCI growing

– Come speak to us!

3

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 4

More at ociweb.com/grails

Visit the OCI’s Table #2 to meet our Grails Team!

Graeme Rocher Jeff Brown

Dave Klein Colin Harrington

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Agenda• Plugins & Traits• Plugins & Events• Configuration API• Code Generation API• Gradle & The Shell

5

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

The Example• Build a Mail Sender Plugin

• Trait• Events• Configuration• Code Generation

6

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

SPRINGONE2GXWASHINGTON, DC

Plugins & Traits

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Adding Behaviour with Traits• Use Enhances to add behaviour

8

importgrails.artefact.*

@Enhances('Controller')traitMyTrait{voidmyNewMethod(){…}}

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Core Grails Traits• Controller - implemented by all controllers• DomainClass - implemented by all domain classes

• GormEntity - implemented by all GORM entities• Service - implemented by all services• TagLibrary - implemented by all tag libraries• Interceptor - all Grails interceptors• Events - Any object that wants to send events

9

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

SPRINGONE2GXWASHINGTON, DC

Events

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Events• Any class that implements the Events trait can send and receive events• Controllers and services implement the trait by default• You can effectively decouple systems using an event driven approach• Fits nicely with reactive programming• Events are built on the Reactor framework

• http://projectreactor.io

11

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Events• Use on to listen and notify to send or combine with sendAndReceive

12

notify('mail:sent',eventFor(message))

on('mail:sent'){Event<TYPE>event->//dostuff}

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Events• The Consumer and Selector annotations from Spring Reactor work too!

13

@ConsumerclassMyService{

@Selector('mail:sent')voidmailEventListener(MailMessagemsg){//dostuff}}

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

SPRINGONE2GXWASHINGTON, DC

Configuration API

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Configuration API

15

booleanisFooEnabled=config.getProperty('foo.bar',Boolean,true)

//or

@Value('foo.bar')booleanisFooEnabled

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Plugins & Configuration• Applications inherit plugin configuration• You should keep your plugin configuration minimal• Plugin configuration defines the default values• Applications can override any plugin provided value

16

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

SPRINGONE2GXWASHINGTON, DC

Code Generation & Grails

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Code Generation Scripts• Go in src/main/scripts in plugins or applications• All scripts subclass the GroovyScriptCommand class• Some handy properties

• gradle - for invoking Gradle• ant - for invoking Ant• methodMissing - for invoking other code gen commands

• Useful traits• TemplateRenderer - for rendering templates• FileSystemInteraction - for interacting with the file system

18

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Code Generation Scripts• The model method exposes a Model interface for introspecting conventions

19

interfaceModel{StringgetClassName()StringgetFullName()StringgetPackageName()…StringgetLowerCaseName()Stringconvention(StringconventionName)Map<String,Object>asMap()}

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

DSL for Code Generation Scripts

20

description("Createsaservicethatsendsamail"){usage"Thisdoescoolsstuff"}

defmodel=model(args[0])

rendertemplate:template('MailService.groovy'),destination:file("grails-app/services/${model.packagePath}/${model.convention('Service')}.groovy"),model:model

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

SPRINGONE2GXWASHINGTON, DC

Gradle & The Shell

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Gradle & The Shell• Create Gradle tasks that invoke your app

• Without knowing any Gradle! ;-)

22

classMailBatcherCommandimplementsApplicationCommand{booleanhandle(ExecutionContextcontext){//DOSTUFFreturntrue}}

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Gradle & The Shell• Just add to build.gradle build class path and run the command

23

classpath'org.grails.plugins:mailSender:0.1-SNAPSHOT'

gradlebatchSendMailgrailsbatch-send-mail

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Summary• Grails 3 provides powerful techniques to build plugins that empower your

application• The core philosophy of plugins and modular applications continues• Through traits and events Grails 3 is more powerful that ever before!• Grails’ internals are all based on the described techniques

24

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Q & A

25

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 26

More at ociweb.com/grails

The OCI Grails Team is growing — will You join us?

Unless otherwise indicated, these sl ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Stay Connected.

Web: grails.orgStackOverflow: http://stackoverflow.com/tags/grails Slack: http://slack-signup.grails.org Twitter: twitter.com/grailsframeworkLinkedIn: http://linkedin.com/groups/Grails-User-Group-39757

27

More at ociweb.com/grails

top related